Skip to content

Commit 42c765b

Browse files
authored
Fix infinite recursion when merging sourcemaps (#14274)
* Fix infinite recursion when merge sourcemaps * Add test case * Externalize the sourcemap
1 parent dc28575 commit 42c765b

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

packages/babel-core/src/transformation/file/merge-map.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ export default function mergeSourceMap(
66
map: SourceMap,
77
source: string,
88
): SourceMap {
9+
// Prevent an infinite recursion if one of the input map's sources has the
10+
// same resolved path as the input map. In the case, it would keep find the
11+
// input map, then get it's sources which will include a path like the input
12+
// map, on and on.
13+
let found = false;
914
const result = remapping(rootless(map), (s, ctx) => {
10-
if (s === source) {
15+
if (s === source && !found) {
16+
found = true;
1117
// We empty the source location, which will prevent the sourcemap from
1218
// becoming relative to the input's location. Eg, if we're transforming a
1319
// file 'foo/bar.js', and it is a transformation of a `baz.js` file in the
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var foo = function () {
2+
return 4;
3+
};
4+
5+
//# sourceMappingURL=input.js.map
6+

packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-same-location/input.js.map

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"inputSourceMap": true
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var foo = function () {
2+
return 4;
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"mappings": "AAAA,UAAU,Y;SAAM;AAAC,CAAjB",
3+
"names": [],
4+
"sources": ["source-maps/input-source-map-same-location/input.js"],
5+
"sourcesContent": ["var foo = () => 4;"],
6+
"version": 3
7+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy