@@ -17,7 +17,8 @@ namespace ts {
1717
1818 const names : string [ ] = [ ] ;
1919 let nameToNameIndexMap : ESMap < string , number > | undefined ;
20- let mappings : string [ ] = [ ] ;
20+ let mappings = "" ;
21+ let mappingSegmentsBuffer : string [ ] = [ ] ;
2122
2223 // Last recorded and encoded mappings
2324 let lastGeneratedLine = 0 ;
@@ -221,7 +222,7 @@ namespace ts {
221222 if ( lastGeneratedLine < pendingGeneratedLine ) {
222223 // Emit line delimiters
223224 do {
224- mappings . push ( ";" ) ;
225+ mappingSegmentsBuffer . push ( ";" ) ;
225226 lastGeneratedLine ++ ;
226227 lastGeneratedCharacter = 0 ;
227228 }
@@ -231,34 +232,37 @@ namespace ts {
231232 Debug . assertEqual ( lastGeneratedLine , pendingGeneratedLine , "generatedLine cannot backtrack" ) ;
232233 // Emit comma to separate the entry
233234 if ( hasLast ) {
234- mappings . push ( "," ) ;
235+ mappingSegmentsBuffer . push ( "," ) ;
235236 }
236237 }
237238
238239 // 1. Relative generated character
239- mappings . push ( base64VLQFormatEncode ( pendingGeneratedCharacter - lastGeneratedCharacter ) ) ;
240+ mappingSegmentsBuffer . push ( base64VLQFormatEncode ( pendingGeneratedCharacter - lastGeneratedCharacter ) ) ;
240241 lastGeneratedCharacter = pendingGeneratedCharacter ;
241242
242243 if ( hasPendingSource ) {
243244 // 2. Relative sourceIndex
244- mappings . push ( base64VLQFormatEncode ( pendingSourceIndex - lastSourceIndex ) ) ;
245+ mappingSegmentsBuffer . push ( base64VLQFormatEncode ( pendingSourceIndex - lastSourceIndex ) ) ;
245246 lastSourceIndex = pendingSourceIndex ;
246247
247248 // 3. Relative source line
248- mappings . push ( base64VLQFormatEncode ( pendingSourceLine - lastSourceLine ) ) ;
249+ mappingSegmentsBuffer . push ( base64VLQFormatEncode ( pendingSourceLine - lastSourceLine ) ) ;
249250 lastSourceLine = pendingSourceLine ;
250251
251252 // 4. Relative source character
252- mappings . push ( base64VLQFormatEncode ( pendingSourceCharacter - lastSourceCharacter ) ) ;
253+ mappingSegmentsBuffer . push ( base64VLQFormatEncode ( pendingSourceCharacter - lastSourceCharacter ) ) ;
253254 lastSourceCharacter = pendingSourceCharacter ;
254255
255256 if ( hasPendingName ) {
256257 // 5. Relative nameIndex
257- mappings . push ( base64VLQFormatEncode ( pendingNameIndex - lastNameIndex ) ) ;
258+ mappingSegmentsBuffer . push ( base64VLQFormatEncode ( pendingNameIndex - lastNameIndex ) ) ;
258259 lastNameIndex = pendingNameIndex ;
259260 }
260261 }
261262
263+ mappings = mappingSegmentsBuffer . join ( "" ) ;
264+ mappingSegmentsBuffer . length = 1 ;
265+ mappingSegmentsBuffer [ 0 ] = mappings ;
262266 hasLast = true ;
263267 exit ( ) ;
264268 }
@@ -271,7 +275,7 @@ namespace ts {
271275 sourceRoot,
272276 sources,
273277 names,
274- mappings : mappings . join ( "" ) ,
278+ mappings,
275279 sourcesContent,
276280 } ;
277281 }
0 commit comments