Skip to content

Commit 9b0caea

Browse files
committed
Optimize external source maps without full cache
1 parent a0d457e commit 9b0caea

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/compiler/emitter.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ namespace ts {
861861
let sourceMapsDisabled = true;
862862
let sourceMapGenerator: SourceMapGenerator | undefined;
863863
let sourceMapSource: SourceMapSource;
864+
let mostRecentlyAddedSourceMapSource: SourceMapSource;
864865
let sourceMapSourceIndex = -1;
865866

866867
// Comments
@@ -5339,7 +5340,7 @@ namespace ts {
53395340
const savedSourceMapSource = sourceMapSource;
53405341
setSourceMapSource(source);
53415342
emitPos(pos);
5342-
setSourceMapSource(savedSourceMapSource);
5343+
setSourceMapSource(savedSourceMapSource, /*addSource*/ false);
53435344
}
53445345
else {
53455346
emitPos(pos);
@@ -5379,13 +5380,17 @@ namespace ts {
53795380
return tokenPos;
53805381
}
53815382

5382-
function setSourceMapSource(source: SourceMapSource) {
5383+
function setSourceMapSource(source: SourceMapSource, addSource?: boolean) {
53835384
if (sourceMapsDisabled) {
53845385
return;
53855386
}
53865387

53875388
sourceMapSource = source;
53885389

5390+
if (addSource === false || source === mostRecentlyAddedSourceMapSource) {
5391+
return;
5392+
}
5393+
53895394
if (isJsonSourceMapSource(source)) {
53905395
return;
53915396
}
@@ -5394,6 +5399,8 @@ namespace ts {
53945399
if (printerOptions.inlineSources) {
53955400
sourceMapGenerator!.setSourceContent(sourceMapSourceIndex, source.text);
53965401
}
5402+
5403+
mostRecentlyAddedSourceMapSource = source;
53975404
}
53985405

53995406
function isJsonSourceMapSource(sourceFile: SourceMapSource) {

src/compiler/sourcemap.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace ts {
1313
const rawSources: string[] = [];
1414
const sources: string[] = [];
1515
const sourceToSourceIndexMap = new Map<string, number>();
16-
const fileNameToSourceIndexMap = new Map<string, number>();
1716
let sourcesContent: (string | null)[] | undefined;
1817

1918
const names: string[] = [];
@@ -52,10 +51,6 @@ namespace ts {
5251

5352
function addSource(fileName: string) {
5453
enter();
55-
const sourceIndexByFileName = fileNameToSourceIndexMap.get(fileName);
56-
if (sourceIndexByFileName !== undefined) {
57-
return sourceIndexByFileName;
58-
}
5954
const source = getRelativePathToDirectoryOrUrl(sourcesDirectoryPath,
6055
fileName,
6156
host.getCurrentDirectory(),
@@ -69,7 +64,6 @@ namespace ts {
6964
rawSources.push(fileName);
7065
sourceToSourceIndexMap.set(source, sourceIndex);
7166
}
72-
fileNameToSourceIndexMap.set(fileName, sourceIndex);
7367
exit();
7468
return sourceIndex;
7569
}

0 commit comments

Comments
 (0)