8000 add explict serialization logic for source maps to avoid using JSON · johnangularjs/TypeScript@b15304f · GitHub
[go: up one dir, main page]

Skip to content

Commit b15304f

Browse files
committed
add explict serialization logic for source maps to avoid using JSON
1 parent d2f4cd7 commit b15304f

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/compiler/emitter.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,17 +588,33 @@ module ts {
588588
recordSourceMapSpan(comment.end);
589589
}
590590

591+
function serializeStringArray(list: string[]): string {
592+
if (list && list.length) {
593+
return "\"" + list.join("\",\"") + "\"";
594+
}
595+
return "";
596+
//var output = "";
597+
//for (var i = 0, n = list.length; i < n; i++) {
598+
// if (i) output += ",";
599+
// output += "\"" + list[i] + "\"";
600+
//}
601+
//return output;
602+
}
603+
604+
function serializeSourceMapContents(version: number, file: string, sourceRoot: string, sources: string[], names: string[], mappings: string) {
605+
return "{\"version\":" + version + ",\"file\":\"" + file + "\",\"sourceRoot\":\"" + sourceRoot + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + mappings + "\"}";
606+
}
607+
591608
function writeJavaScriptAndSourceMapFile(emitOutput: string, writeByteOrderMark: boolean) {
592609
// Write source map file
593610
encodeLastRecordedSourceMapSpan();
594-
writeFile(sourceMapData.sourceMapFilePath, JSON.stringify({
595-
version: 3,
596-
file: sourceMapData.sourceMapFile,
597-
sourceRoot: sourceMapData.sourceMapSourceRoot,
598-
sources: sourceMapData.sourceMapSources,
599-
names: sourceMapData.sourceMapNames,
600-
mappings: sourceMapData.sourceMapMappings
601-
}), /*writeByteOrderMark*/ false);
611+
writeFile(sourceMapData.sourceMapFilePath, serializeSourceMapContents(
612+
3,
613+
sourceMapData.sourceMapFile,
614+
sourceMapData.sourceMapSourceRoot,
615+
sourceMapData.sourceMapSources,
616+
sourceMapData.sourceMapNames,
617+
sourceMapData.sourceMapMappings), /*writeByteOrderMark*/ false);
602618
sourceMapDataList.push(sourceMapData);
603619

604620
// Write sourcemap url to the js file and write the js file

0 commit comments

Comments
 (0)
0