From 4c86404b414974c5a462e823bbffc5fddb8edc75 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 23 Apr 2021 01:07:28 +0000 Subject: [PATCH 1/3] 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 0db89a5830fd2..3e8e9a1f46c47 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, }; } From 312ce16e0f7fdef9d80e6db2fb008d017c55f6d4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 23 Apr 2021 01:39:55 +0000 Subject: [PATCH 2/3] Ugh. --- src/compiler/sourcemap.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index 3e8e9a1f46c47..f77d7c1a2eddc 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -271,7 +271,7 @@ namespace ts { sourceRoot, sources, names, - mappings: mappings.join(), + mappings: mappings.join(""), sourcesContent, }; } From 799bbbeca6403a9191267469059f3a15cbe830df Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 23 Apr 2021 02:54:06 +0000 Subject: [PATCH 3/3] Just calculate the result at the end of commitPendingMapping. --- src/compiler/sourcemap.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index f77d7c1a2eddc..7a52ed5200c28 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -17,7 +17,8 @@ namespace ts { const names: string[] = []; let nameToNameIndexMap: ESMap | undefined; - let mappings: string[] = []; + let mappings = ""; + let mappingSegmentsBuffer: string[] = []; // Last recorded and encoded mappings let lastGeneratedLine = 0; @@ -221,7 +222,7 @@ namespace ts { if (lastGeneratedLine < pendingGeneratedLine) { // Emit line delimiters do { - mappings.push(";"); + mappingSegmentsBuffer.push(";"); lastGeneratedLine++; lastGeneratedCharacter = 0; } @@ -231,34 +232,37 @@ namespace ts { Debug.assertEqual(lastGeneratedLine, pendingGeneratedLine, "generatedLine cannot backtrack"); // Emit comma to separate the entry if (hasLast) { - mappings.push(","); + mappingSegmentsBuffer.push(","); } } // 1. Relative generated character - mappings.push(base64VLQFormatEncode(pendingGeneratedCharacter - lastGeneratedCharacter)); + mappingSegmentsBuffer.push(base64VLQFormatEncode(pendingGeneratedCharacter - lastGeneratedCharacter)); lastGeneratedCharacter = pendingGeneratedCharacter; if (hasPendingSource) { // 2. Relative sourceIndex - mappings.push(base64VLQFormatEncode(pendingSourceIndex - lastSourceIndex)); + mappingSegmentsBuffer.push(base64VLQFormatEncode(pendingSourceIndex - lastSourceIndex)); lastSourceIndex = pendingSourceIndex; // 3. Relative source line - mappings.push(base64VLQFormatEncode(pendingSourceLine - lastSourceLine)); + mappingSegmentsBuffer.push(base64VLQFormatEncode(pendingSourceLine - lastSourceLine)); lastSourceLine = pendingSourceLine; // 4. Relative source character - mappings.push(base64VLQFormatEncode(pendingSourceCharacter - lastSourceCharacter)); + mappingSegmentsBuffer.push(base64VLQFormatEncode(pendingSourceCharacter - lastSourceCharacter)); lastSourceCharacter = pendingSourceCharacter; if (hasPendingName) { // 5. Relative nameIndex - mappings.push(base64VLQFormatEncode(pendingNameIndex - lastNameIndex)); + mappingSegmentsBuffer.push(base64VLQFormatEncode(pendingNameIndex - lastNameIndex)); lastNameIndex = pendingNameIndex; } } + mappings = mappingSegmentsBuffer.join(""); + mappingSegmentsBuffer.length = 1; + mappingSegmentsBuffer[0] = mappings; hasLast = true; exit(); } @@ -271,7 +275,7 @@ namespace ts { sourceRoot, sources, names, - mappings: mappings.join(""), + mappings, sourcesContent, }; }