Use an array for building up mappings in the sourcemap generator.

This commit is contained in:
Daniel Rosenwasser
2021-04-23 01:07:28 +00:00
committed by GitHub
parent c552a4bf82
commit 4c86404b41

View File

@@ -17,7 +17,7 @@ namespace ts {
const names: string[] = [];
let nameToNameIndexMap: ESMap<string, number> | undefined;
let mappings = "";
let mappings: string[] = [];
// Last recorded and encoded mappings
let lastGeneratedLine = 0;
@@ -221,7 +221,7 @@ namespace ts {
if (lastGeneratedLine < pendingGeneratedLine) {
// Emit line delimiters
do {
mappings += ";";
mappings.push(";");
lastGeneratedLine++;
lastGeneratedCharacter = 0;
}
@@ -231,30 +231,30 @@ namespace ts {
Debug.assertEqual(lastGeneratedLine, pendingGeneratedLine, "generatedLine cannot backtrack");
// Emit comma to separate the entry
if (hasLast) {
mappings += ",";
mappings.push(",");
}
}
// 1. Relative generated character
mappings += base64VLQFormatEncode(pendingGeneratedCharacter - lastGeneratedCharacter);
mappings.push(base64VLQFormatEncode(pendingGeneratedCharacter - lastGeneratedCharacter));
lastGeneratedCharacter = pendingGeneratedCharacter;
if (hasPendingSource) {
// 2. Relative sourceIndex
mappings += base64VLQFormatEncode(pendingSourceIndex - lastSourceIndex);
mappings.push(base64VLQFormatEncode(pendingSourceIndex - lastSourceIndex));
lastSourceIndex = pendingSourceIndex;
// 3. Relative source line
mappings += base64VLQFormatEncode(pendingSourceLine - lastSourceLine);
mappings.push(base64VLQFormatEncode(pendingSourceLine - lastSourceLine));
lastSourceLine = pendingSourceLine;
// 4. Relative source character
mappings += base64VLQFormatEncode(pendingSourceCharacter - lastSourceCharacter);
mappings.push(base64VLQFormatEncode(pendingSourceCharacter - lastSourceCharacter));
lastSourceCharacter = pendingSourceCharacter;
if (hasPendingName) {
// 5. Relative nameIndex
mappings += base64VLQFormatEncode(pendingNameIndex - lastNameIndex);
mappings.push(base64VLQFormatEncode(pendingNameIndex - lastNameIndex));
lastNameIndex = pendingNameIndex;
}
}
@@ -271,7 +271,7 @@ namespace ts {
sourceRoot,
sources,
names,
mappings,
mappings: mappings.join(),
sourcesContent,
};
}