Skip to content

Commit

Permalink
insert inner source only when used
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Aug 2, 2021
1 parent cfebf95 commit e7be2e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
25 changes: 18 additions & 7 deletions lib/helpers/streamChunksOfCombinedSourceMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/SourceMapSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit e7be2e4

Please # to comment.