From 4c86404b414974c5a462e823bbffc5fddb8edc75 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 23 Apr 2021 01:07:28 +0000 Subject: [PATCH] Use an array for building up mappings in the sourcemap generator. --- src/compiler/sourcemap.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index 0db89a5830f..3e8e9a1f46c 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -17,7 +17,7 @@ namespace ts { const names: string[] = []; let nameToNameIndexMap: ESMap | 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, }; }