Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite recursion when merge sourcemaps #14274

Merged
merged 3 commits into from Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/babel-core/src/transformation/file/merge-map.ts
Expand Up @@ -6,8 +6,14 @@ export default function mergeSourceMap(
map: SourceMap,
source: string,
): SourceMap {
// Prevent an infinite recursion if one of the input map's sources has the
// same resolved path as the input map. In the case, it would keep find the
// input map, then get it's sources which will include a path like the input
// map, on and on.
let found = false;
const result = remapping(rootless(map), (s, ctx) => {
if (s === source) {
if (s === source && !found) {
found = true;
// We empty the source location, which will prevent the sourcemap from
// becoming relative to the input's location. Eg, if we're transforming a
// file 'foo/bar.js', and it is a transformation of a `baz.js` file in the
Expand Down
@@ -0,0 +1,6 @@
var foo = function () {
return 4;
};

//# sourceMappingURL=input.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,3 @@
{
"inputSourceMap": true
}
@@ -0,0 +1,3 @@
var foo = function () {
return 4;
};
@@ -0,0 +1,7 @@
{
"mappings": "AAAA,UAAU,Y;SAAM;AAAC,CAAjB",
"names": [],
"sources": ["source-maps/input-source-map-same-location/input.js"],
"sourcesContent": ["var foo = () => 4;"],
"version": 3
}