From 4b4a156d5e31976e1241ff4fc61965f2f1965265 Mon Sep 17 00:00:00 2001 From: JoostK Date: Fri, 14 Aug 2020 21:34:29 +0200 Subject: [PATCH] Optimize source mapping into external source map sources --- src/compiler/sourcemap.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index 0db89a5830fd2..1c9ef5f55b645 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -13,6 +13,7 @@ namespace ts { const rawSources: string[] = []; const sources: string[] = []; const sourceToSourceIndexMap = new Map(); + const fileNameToSourceIndexMap = new Map(); let sourcesContent: (string | null)[] | undefined; const names: string[] = []; @@ -51,6 +52,10 @@ namespace ts { function addSource(fileName: string) { enter(); + const sourceIndexByFileName = fileNameToSourceIndexMap.get(fileName); + if (sourceIndexByFileName !== undefined) { + return sourceIndexByFileName; + } const source = getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, fileName, host.getCurrentDirectory(), @@ -64,6 +69,7 @@ namespace ts { rawSources.push(fileName); sourceToSourceIndexMap.set(source, sourceIndex); } + fileNameToSourceIndexMap.set(fileName, sourceIndex); exit(); return sourceIndex; }