From e7be2e408d1e6c968ef7cb791b5cee1af1aec72e Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 2 Aug 2021 08:54:13 +0200 Subject: [PATCH] insert inner source only when used --- .../streamChunksOfCombinedSourceMap.js | 25 +++++++++++++------ test/SourceMapSource.js | 8 +++--- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/helpers/streamChunksOfCombinedSourceMap.js b/lib/helpers/streamChunksOfCombinedSourceMap.js index 973057f..468e970 100644 --- a/lib/helpers/streamChunksOfCombinedSourceMap.js +++ b/lib/helpers/streamChunksOfCombinedSourceMap.js @@ -214,6 +214,15 @@ const streamChunksOfCombinedSourceMap = ( if (removeInnerSource) { onChunk(chunk, generatedLine, generatedColumn, -1, -1, -1, -1); return; + } else { + if (sourceIndexMapping[sourceIndex] === -2) { + let globalIndex = sourceMapping.get(innerSourceName); + if (globalIndex === undefined) { + sourceMapping.set(source, (globalIndex = sourceMapping.size)); + onSource(globalIndex, innerSourceName, innerSource); + } + sourceIndexMapping[sourceIndex] = globalIndex; + } } } @@ -255,6 +264,8 @@ const streamChunksOfCombinedSourceMap = ( if (source === innerSourceName) { innerSourceIndex = i; if (innerSource !== undefined) sourceContent = innerSource; + else innerSource = sourceContent; + sourceIndexMapping[i] = -2; streamChunksOfSourceMap( sourceContent, innerSourceMap, @@ -296,14 +307,14 @@ const streamChunksOfCombinedSourceMap = ( false, columns ); - if (removeInnerSource) return; - } - let globalIndex = sourceMapping.get(source); - if (globalIndex === undefined) { - sourceMapping.set(source, (globalIndex = sourceMapping.size)); - onSource(globalIndex, source, sourceContent); + } else { + let globalIndex = sourceMapping.get(source); + if (globalIndex === undefined) { + sourceMapping.set(source, (globalIndex = sourceMapping.size)); + onSource(globalIndex, source, sourceContent); + } + sourceIndexMapping[i] = globalIndex; } - sourceIndexMapping[i] = globalIndex; }, (i, name) => { nameIndexMapping[i] = -2; diff --git a/test/SourceMapSource.js b/test/SourceMapSource.js index 60ad013..3e4b7a5 100644 --- a/test/SourceMapSource.js +++ b/test/SourceMapSource.js @@ -68,22 +68,22 @@ describe("SourceMapSource", () => { 2:0 -> [hello-world.txt] 2:0, :7, :13 -> [hello-world.txt] 2:10 3:0 -> [text] 3:11, :7, :8 -> [text] 3:17", "file": "x", - "mappings": "YCAAA,K,CAAMC;AACN,O,MAAU;ADCC,O,CAAM", + "mappings": "YAAAA,K,CAAMC;AACN,O,MAAU;ACCC,O,CAAM", "names": Array [ "Hello", "World", ], "sources": Array [ - "text", "hello-world.txt", + "text", ], "sourcesContent": Array [ "Hello World is a test string - Translate: Other text", + ", "Hello World is a test string - ", + Translate: Other text", ], "version": 3, }