@@ -862,6 +862,8 @@ namespace ts {
862
862
let sourceMapGenerator : SourceMapGenerator | undefined ;
863
863
let sourceMapSource : SourceMapSource ;
864
864
let sourceMapSourceIndex = - 1 ;
865
+ let mostRecentlyAddedSourceMapSource : SourceMapSource ;
866
+ let mostRecentlyAddedSourceMapSourceIndex = - 1 ;
865
867
866
868
// Comments
867
869
let containerPos = - 1 ;
@@ -5337,9 +5339,10 @@ namespace ts {
5337
5339
function emitSourcePos ( source : SourceMapSource , pos : number ) {
5338
5340
if ( source !== sourceMapSource ) {
5339
5341
const savedSourceMapSource = sourceMapSource ;
5342
+ const savedSourceMapSourceIndex = sourceMapSourceIndex ;
5340
5343
setSourceMapSource ( source ) ;
5341
5344
emitPos ( pos ) ;
5342
- setSourceMapSource ( savedSourceMapSource ) ;
5345
+ resetSourceMapSource ( savedSourceMapSource , savedSourceMapSourceIndex ) ;
5343
5346
}
5344
5347
else {
5345
5348
emitPos ( pos ) ;
@@ -5386,6 +5389,13 @@ namespace ts {
5386
5389
5387
5390
sourceMapSource = source ;
5388
5391
5392
+ if ( source === mostRecentlyAddedSourceMapSource ) {
5393
+ // Fast path for when the new source map is the most recently added, in which case
5394
+ // we use its captured index without going through the source map generator.
5395
+ sourceMapSourceIndex = mostRecentlyAddedSourceMapSourceIndex ;
5396
+ return ;
5397
+ }
5398
+
5389
5399
if ( isJsonSourceMapSource ( source ) ) {
5390
5400
return ;
5391
5401
}
@@ -5394,6 +5404,14 @@ namespace ts {
5394
5404
if ( printerOptions . inlineSources ) {
5395
5405
sourceMapGenerator ! . setSourceContent ( sourceMapSourceIndex , source . text ) ;
5396
5406
}
5407
+
5408
+ mostRecentlyAddedSourceMapSource = source ;
5409
+ mostRecentlyAddedSourceMapSourceIndex = sourceMapSourceIndex ;
5410
+ }
5411
+
5412
+ function resetSourceMapSource ( source : SourceMapSource , sourceIndex : number ) {
5413
+ sourceMapSource = source ;
5414
+ sourceMapSourceIndex = sourceIndex ;
5397
5415
}
5398
5416
5399
5417
function isJsonSourceMapSource ( sourceFile : SourceMapSource ) {
0 commit comments