Optimize external source maps without full cache (#40130)
This commit is contained in:
parent
55ca5e91b9
commit
2f2b679436
|
@ -862,6 +862,8 @@ namespace ts {
|
|||
let sourceMapGenerator: SourceMapGenerator | undefined;
|
||||
let sourceMapSource: SourceMapSource;
|
||||
let sourceMapSourceIndex = -1;
|
||||
let mostRecentlyAddedSourceMapSource: SourceMapSource;
|
||||
let mostRecentlyAddedSourceMapSourceIndex = -1;
|
||||
|
||||
// Comments
|
||||
let containerPos = -1;
|
||||
|
@ -5337,9 +5339,10 @@ namespace ts {
|
|||
function emitSourcePos(source: SourceMapSource, pos: number) {
|
||||
if (source !== sourceMapSource) {
|
||||
const savedSourceMapSource = sourceMapSource;
|
||||
const savedSourceMapSourceIndex = sourceMapSourceIndex;
|
||||
setSourceMapSource(source);
|
||||
emitPos(pos);
|
||||
setSourceMapSource(savedSourceMapSource);
|
||||
resetSourceMapSource(savedSourceMapSource, savedSourceMapSourceIndex);
|
||||
}
|
||||
else {
|
||||
emitPos(pos);
|
||||
|
@ -5386,6 +5389,13 @@ namespace ts {
|
|||
|
||||
sourceMapSource = source;
|
||||
|
||||
if (source === mostRecentlyAddedSourceMapSource) {
|
||||
// Fast path for when the new source map is the most recently added, in which case
|
||||
// we use its captured index without going through the source map generator.
|
||||
sourceMapSourceIndex = mostRecentlyAddedSourceMapSourceIndex;
|
||||
return;
|
||||
}
|
||||
|
||||
if (isJsonSourceMapSource(source)) {
|
||||
return;
|
||||
}
|
||||
|
@ -5394,6 +5404,14 @@ namespace ts {
|
|||
if (printerOptions.inlineSources) {
|
||||
sourceMapGenerator!.setSourceContent(sourceMapSourceIndex, source.text);
|
||||
}
|
||||
|
||||
mostRecentlyAddedSourceMapSource = source;
|
||||
mostRecentlyAddedSourceMapSourceIndex = sourceMapSourceIndex;
|
||||
}
|
||||
|
||||
function resetSourceMapSource(source: SourceMapSource, sourceIndex: number) {
|
||||
sourceMapSource = source;
|
||||
sourceMapSourceIndex = sourceIndex;
|
||||
}
|
||||
|
||||
function isJsonSourceMapSource(sourceFile: SourceMapSource) {
|
||||
|
|
Loading…
Reference in a new issue