@@ -156,7 +156,6 @@ namespace ts {
156156 sourceMapNames : [ ] ,
157157 sourceMapMappings : "" ,
158158 sourceMapSourcesContent : compilerOptions . inlineSources ? [ ] : undefined ,
159- sourceMapDecodedMappings : [ ]
160159 } ;
161160
162161 // Normalize source root and make sure it has trailing "/" so that it can be used to combine paths with the
@@ -299,7 +298,6 @@ namespace ts {
299298 }
300299
301300 lastEncodedSourceMapSpan = lastRecordedSourceMapSpan ;
302- sourceMapData . sourceMapDecodedMappings . push ( lastEncodedSourceMapSpan ) ;
303301 }
304302
305303 /**
@@ -393,24 +391,29 @@ namespace ts {
393391
394392 const sourcesDirectoryPath = compilerOptions . sourceRoot ? host . getCommonSourceDirectory ( ) : sourceMapDir ;
395393 const resolvedPathCache = createMap < string > ( ) ;
396- sourcemaps . calculateDecodedMappings ( originalMap , ( raw ) : void => {
394+ const absolutePathCache = createMap < string > ( ) ;
395+ const sourcemapIterator = sourcemaps . decodeMappings ( originalMap ) ;
396+ for ( let { value : raw , done } = sourcemapIterator . next ( ) ; ! done ; { value : raw , done } = sourcemapIterator . next ( ) ) {
397+ const pathCacheKey = "" + raw . sourceIndex ;
397398 // Apply offsets to each position and fixup source entries
398- const rawPath = originalMap . sources [ raw . sourceIndex ] ;
399- const relativePath = originalMap . sourceRoot ? combinePaths ( originalMap . sourceRoot , rawPath ) : rawPath ;
400- const combinedPath = combinePaths ( getDirectoryPath ( node . sourceMapPath ! ) , relativePath ) ;
401- if ( ! resolvedPathCache . has ( combinedPath ) ) {
402- resolvedPathCache . set ( combinedPath , getRelativePathToDirectoryOrUrl (
399+ if ( ! resolvedPathCache . has ( pathCacheKey ) ) {
400+ const rawPath = originalMap . sources [ raw . sourceIndex ] ;
401+ const relativePath = originalMap . sourceRoot ? combinePaths ( originalMap . sourceRoot , rawPath ) : rawPath ;
402+ const combinedPath = combinePaths ( getDirectoryPath ( node . sourceMapPath ! ) , relativePath ) ;
403+ const resolvedPath = getRelativePathToDirectoryOrUrl (
403404 sourcesDirectoryPath ,
404405 combinedPath ,
405406 host . getCurrentDirectory ( ) ,
406407 host . getCanonicalFileName ,
407408 /*isAbsolutePathAnUrl*/ true
408- ) ) ;
409+ ) ;
410+ resolvedPathCache . set ( pathCacheKey , resolvedPath ) ;
411+ absolutePathCache . set ( pathCacheKey , getNormalizedAbsolutePath ( resolvedPath , sourcesDirectoryPath ) ) ;
409412 }
410- const resolvedPath = resolvedPathCache . get ( combinedPath ) ! ;
411- const absolutePath = getNormalizedAbsolutePath ( resolvedPath , sourcesDirectoryPath ) ;
413+ const resolvedPath = resolvedPathCache . get ( pathCacheKey ) ! ;
414+ const absolutePath = absolutePathCache . get ( pathCacheKey ) ! ;
412415 // tslint:disable-next-line:no-null-keyword
413- setupSourceEntry ( absolutePath , originalMap . sourcesContent ? originalMap . sourcesContent [ raw . sourceIndex ] : null ) ; // TODO: Lookup content for inlining?
416+ setupSourceEntry ( absolutePath , originalMap . sourcesContent ? originalMap . sourcesContent [ raw . sourceIndex ] : null , resolvedPath ) ; // TODO: Lookup content for inlining?
414417 const newIndex = sourceMapData . sourceMapSources . indexOf ( resolvedPath ) ;
415418 // Then reencode all the updated spans into the overall map
416419 encodeLastRecordedSourceMapSpan ( ) ;
@@ -420,7 +423,7 @@ namespace ts {
420423 emittedColumn : raw . emittedLine === 0 ? ( raw . emittedColumn + firstLineColumnOffset ) : raw . emittedColumn ,
421424 sourceIndex : newIndex ,
422425 } ;
423- } ) ;
426+ }
424427 // And actually emit the text these sourcemaps are for
425428 return emitCallback ( hint , node ) ;
426429 }
@@ -519,17 +522,19 @@ namespace ts {
519522 setupSourceEntry ( sourceFile . fileName , sourceFile . text ) ;
520523 }
521524
522- function setupSourceEntry ( fileName : string , content : string | null ) {
523- // Add the file to tsFilePaths
524- // If sourceroot option: Use the relative path corresponding to the common directory path
525- // otherwise source locations relative to map file location
526- const sourcesDirectoryPath = compilerOptions . sourceRoot ? host . getCommonSourceDirectory ( ) : sourceMapDir ;
527-
528- const source = getRelativePathToDirectoryOrUrl ( sourcesDirectoryPath ,
529- fileName ,
530- host . getCurrentDirectory ( ) ,
531- host . getCanonicalFileName ,
532- /*isAbsolutePathAnUrl*/ true ) ;
525+ function setupSourceEntry ( fileName : string , content : string | null , source ?: string ) {
526+ if ( ! source ) {
527+ // Add the file to tsFilePaths
528+ // If sourceroot option: Use the relative path corresponding to the common directory path
529+ // otherwise source locations relative to map file location
530+ const sourcesDirectoryPath = compilerOptions . sourceRoot ? host . getCommonSourceDirectory ( ) : sourceMapDir ;
531+
532+ source = getRelativePathToDirectoryOrUrl ( sourcesDirectoryPath ,
533+ fileName ,
534+ host . getCurrentDirectory ( ) ,
535+ host . getCanonicalFileName ,
536+ /*isAbsolutePathAnUrl*/ true ) ;
537+ }
533538
534539 sourceMapSourceIndex = sourceMapData . sourceMapSources . indexOf ( source ) ;
535540 if ( sourceMapSourceIndex === - 1 ) {
0 commit comments