fix(destructuring): preserve loc of original declaration in output (#13173)

This commit is contained in:
Moti Zilberman 2021-04-20 15:36:06 +01:00 committed by GitHub
parent ab06ccad49
commit 691c46846f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 0 deletions

View File

@ -615,6 +615,7 @@ export default declare((api, options) => {
if (!variableDeclarationHasPattern(node)) return;
const nodeKind = node.kind;
const nodeLoc = node.loc;
const nodes = [];
let declar;
@ -664,6 +665,10 @@ export default declare((api, options) => {
} else {
// Make sure the original node kind is used for each compound declaration
node.kind = nodeKind;
// Propagate the original declaration node's location
if (!node.loc) {
node.loc = nodeLoc;
}
nodesOut.push(node);
tail = t.isVariableDeclaration(node) ? node : null;
}

View File

@ -0,0 +1,3 @@
const fn = (arg) => {
var [x, y] = arg;
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["transform-destructuring"]
}

View File

@ -0,0 +1,5 @@
const fn = arg => {
var _arg = babelHelpers.slicedToArray(arg, 2),
x = _arg[0],
y = _arg[1];
};

View File

@ -0,0 +1,10 @@
[{
"original": {
"line": 2,
"column": 2
},
"generated": {
"line": 2,
"column": 2
}
}]