@@ -4,9 +4,7 @@ namespace ts {
44 extendedDiagnostics ?: boolean ;
55 }
66
7- let mappingsBuffer : Uint8Array ;
8-
9- export function createSourceMapGenerator ( host : EmitHost , file : string , guessedInputLength : number , sourceRoot : string , sourcesDirectoryPath : string , generatorOptions : SourceMapGeneratorOptions ) : SourceMapGenerator {
7+ export function createSourceMapGenerator ( host : EmitHost , file : string , sourceRoot : string , sourcesDirectoryPath : string , generatorOptions : SourceMapGeneratorOptions ) : SourceMapGenerator {
108 const { enter, exit } = generatorOptions . extendedDiagnostics
119 ? performance . createTimer ( "Source Map" , "beforeSourcemap" , "afterSourcemap" )
1210 : performance . nullTimer ;
@@ -19,18 +17,15 @@ namespace ts {
1917
2018 const names : string [ ] = [ ] ;
2119 let nameToNameIndexMap : ESMap < string , number > | undefined ;
22- mappingsBuffer ||= new Uint8Array ( guessedInputLength + 1 >> 1 ) ;
23- let lastMappings : string | undefined ;
24- let mappingsPos = 0 ;
20+ let mappings = "" ;
21+ let mappingsBuffer = new Uint8Array ( 1024 ) ;
22+ let mappingsBufferPos = 0 ;
2523 function setMapping ( charCode : number ) {
26- // resize to 1.5 * length
27- if ( mappingsPos >= mappingsBuffer . length ) {
28- const oldLength = mappingsBuffer . length + 1 ;
29- const replacementBuffer = new Uint8Array ( oldLength + ( ( oldLength + 1 ) >> 1 ) ) ;
30- replacementBuffer . set ( mappingsBuffer ) ;
31- mappingsBuffer = replacementBuffer ;
24+ if ( mappingsBufferPos >= mappingsBuffer . length ) {
25+ mappings += String . fromCharCode . apply ( undefined , mappingsBuffer ) ;
26+ mappingsBufferPos = 0 ;
3227 }
33- mappingsBuffer [ mappingsPos ++ ] = charCode ;
28+ mappingsBuffer [ mappingsBufferPos ++ ] = charCode ;
3429 }
3530
3631 function base64VLQFormatEncode ( inValue : number ) {
@@ -302,17 +297,16 @@ namespace ts {
302297 exit ( ) ;
303298 }
304299
305- function serializeMappings ( len : number ) : string {
306- let mappings = "" ;
307- for ( let i = 0 ; i < len ; i += 1024 ) {
308- mappings += String . fromCharCode . apply ( undefined , mappingsBuffer . subarray ( i , Math . min ( len , i + 1024 ) ) ) ;
300+ function flushMappings ( ) : void {
301+ if ( mappingsBufferPos > 0 ) {
302+ mappings += String . fromCharCode . apply ( undefined , mappingsBuffer . subarray ( 0 , mappingsBufferPos ) ) ;
303+ mappingsBufferPos = 0 ;
309304 }
310- return mappings ;
311305 }
312306
313307 function toJSON ( ) : RawSourceMap {
314308 commitPendingMapping ( ) ;
315- const mappings = ( lastMappings ??= serializeMappings ( mappingsPos ) ) ;
309+ flushMappings ( ) ;
316310 return {
317311 version : 3 ,
318312 file,
0 commit comments