Preserve identifier location information when mapping this and arguments. (#7312)
This commit is contained in:
parent
96c0415c86
commit
278cd5e572
@ -208,9 +208,12 @@ function hoistFunctionEnvironment(
|
||||
},
|
||||
});
|
||||
const superBinding = getSuperBinding(thisEnvFn);
|
||||
allSuperCalls.forEach(superCall =>
|
||||
superCall.get("callee").replaceWith(t.identifier(superBinding)),
|
||||
);
|
||||
allSuperCalls.forEach(superCall => {
|
||||
const callee = t.identifier(superBinding);
|
||||
callee.loc = superCall.node.callee.loc;
|
||||
|
||||
superCall.get("callee").replaceWith(callee);
|
||||
});
|
||||
}
|
||||
|
||||
// Convert all "this" references in the arrow to point at the alias.
|
||||
@ -225,11 +228,12 @@ function hoistFunctionEnvironment(
|
||||
(inConstructor && hasSuperClass(thisEnvFn))
|
||||
) {
|
||||
thisPaths.forEach(thisChild => {
|
||||
thisChild.replaceWith(
|
||||
thisChild.isJSX()
|
||||
? t.jsxIdentifier(thisBinding)
|
||||
: t.identifier(thisBinding),
|
||||
);
|
||||
const thisRef = thisChild.isJSX()
|
||||
? t.jsxIdentifier(thisBinding)
|
||||
: t.identifier(thisBinding);
|
||||
|
||||
thisRef.loc = thisChild.node.loc;
|
||||
thisChild.replaceWith(thisRef);
|
||||
});
|
||||
|
||||
if (specCompliant) thisBinding = null;
|
||||
@ -243,7 +247,10 @@ function hoistFunctionEnvironment(
|
||||
);
|
||||
|
||||
argumentsPaths.forEach(argumentsChild => {
|
||||
argumentsChild.replaceWith(t.identifier(argumentsBinding));
|
||||
const argsRef = t.identifier(argumentsBinding);
|
||||
argsRef.loc = argumentsChild.node.loc;
|
||||
|
||||
argumentsChild.replaceWith(argsRef);
|
||||
});
|
||||
}
|
||||
|
||||
@ -253,8 +260,11 @@ function hoistFunctionEnvironment(
|
||||
t.metaProperty(t.identifier("new"), t.identifier("target")),
|
||||
);
|
||||
|
||||
newTargetPaths.forEach(argumentsChild => {
|
||||
argumentsChild.replaceWith(t.identifier(newTargetBinding));
|
||||
newTargetPaths.forEach(targetChild => {
|
||||
const targetRef = t.identifier(newTargetBinding);
|
||||
targetRef.loc = targetChild.node.loc;
|
||||
|
||||
targetChild.replaceWith(targetRef);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
5
packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/input.js
vendored
Normal file
5
packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/input.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
function fn() {
|
||||
var inner = () => {
|
||||
console.log(arguments);
|
||||
};
|
||||
}
|
||||
3
packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/options.json
vendored
Normal file
3
packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-arrow-functions"]
|
||||
}
|
||||
7
packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/output.js
vendored
Normal file
7
packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/output.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
function fn() {
|
||||
var _arguments = arguments;
|
||||
|
||||
var inner = function () {
|
||||
console.log(_arguments);
|
||||
};
|
||||
}
|
||||
8
packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/source-mappings.json
vendored
Normal file
8
packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/source-mappings.json
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
[{
|
||||
"generated": {
|
||||
"line": 5, "column": 16
|
||||
},
|
||||
"original": {
|
||||
"line": 3, "column": 16
|
||||
}
|
||||
}]
|
||||
5
packages/babel-traverse/test/fixtures/conversion/this-source-maps/input.js
vendored
Normal file
5
packages/babel-traverse/test/fixtures/conversion/this-source-maps/input.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
function fn() {
|
||||
var inner = () => {
|
||||
console.log(this);
|
||||
};
|
||||
}
|
||||
3
packages/babel-traverse/test/fixtures/conversion/this-source-maps/options.json
vendored
Normal file
3
packages/babel-traverse/test/fixtures/conversion/this-source-maps/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-arrow-functions"]
|
||||
}
|
||||
7
packages/babel-traverse/test/fixtures/conversion/this-source-maps/output.js
vendored
Normal file
7
packages/babel-traverse/test/fixtures/conversion/this-source-maps/output.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
function fn() {
|
||||
var _this = this;
|
||||
|
||||
var inner = function () {
|
||||
console.log(_this);
|
||||
};
|
||||
}
|
||||
8
packages/babel-traverse/test/fixtures/conversion/this-source-maps/source-mappings.json
vendored
Normal file
8
packages/babel-traverse/test/fixtures/conversion/this-source-maps/source-mappings.json
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
[{
|
||||
"generated": {
|
||||
"line": 5, "column": 16
|
||||
},
|
||||
"original": {
|
||||
"line": 3, "column": 16
|
||||
}
|
||||
}]
|
||||
Loading…
x
Reference in New Issue
Block a user