forked from babel/babel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge multi-source output sourcemaps
Surprisingly, Babel allows a transformer to mark the source file of a node to allow it to be sourced from any file. When this happens, the output sourcemap will contain multiple `sources`. I didn't realize this when I created babel#14209, and this `remapping` will throw an error if the output map has multiple sources. This can be fixed by using `remapping`'s graph building API (don't pass an array). This allows us to return an input map for _any_ source file, and we just need some special handling to figure out which source is our transformed file. Fixes ampproject/remapping#159.
- Loading branch information
1 parent
89e26a0
commit f29f5fa
Showing
8 changed files
with
128 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...est/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/input.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
...fixtures/transformation/source-maps/input-source-map-multiple-output-sources/input.js.map
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
...fixtures/transformation/source-maps/input-source-map-multiple-output-sources/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"inputSourceMap": true, | ||
"plugins": ["./plugin.js"] | ||
} |
5 changes: 5 additions & 0 deletions
5
...st/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
foo(1); | ||
|
||
function foo(bar) { | ||
throw new Error('Intentional.'); | ||
} |
14 changes: 14 additions & 0 deletions
14
...st/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = function (babel) { | ||
const { types: t } = babel; | ||
|
||
return { | ||
visitor: { | ||
CallExpression(path) { | ||
const { sourceFileName } = this.file.opts.generatorOpts; | ||
// This filename will cause a second source file to be generated in the | ||
// output sourcemap. | ||
path.node.loc.filename = "test.js"; | ||
}, | ||
}, | ||
}; | ||
}; |
17 changes: 17 additions & 0 deletions
17
...tures/transformation/source-maps/input-source-map-multiple-output-sources/source-map.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"mappings": "AAAAA,IAAI,CCAJ;;ADCA,SAASA,GAAT,CAAaC,GAAb,EAAwB;AACpB,QAAM,IAAIC,KAAJ,CAAU,cAAV,CAAN;AACH", | ||
"names": [ | ||
"foo", | ||
"bar", | ||
"Error" | ||
], | ||
"sources": [ | ||
"input.tsx", | ||
"test.js" | ||
], | ||
"sourcesContent": [ | ||
"foo(1);\nfunction foo(bar: number): never {\n throw new Error('Intentional.');\n}", | ||
null | ||
], | ||
"version": 3 | ||
} |