fix(destructuring): preserve loc of original declaration in output (#13173)
This commit is contained in:
parent
ab06ccad49
commit
691c46846f
@ -615,6 +615,7 @@ export default declare((api, options) => {
|
|||||||
if (!variableDeclarationHasPattern(node)) return;
|
if (!variableDeclarationHasPattern(node)) return;
|
||||||
|
|
||||||
const nodeKind = node.kind;
|
const nodeKind = node.kind;
|
||||||
|
const nodeLoc = node.loc;
|
||||||
const nodes = [];
|
const nodes = [];
|
||||||
let declar;
|
let declar;
|
||||||
|
|
||||||
@ -664,6 +665,10 @@ export default declare((api, options) => {
|
|||||||
} else {
|
} else {
|
||||||
// Make sure the original node kind is used for each compound declaration
|
// Make sure the original node kind is used for each compound declaration
|
||||||
node.kind = nodeKind;
|
node.kind = nodeKind;
|
||||||
|
// Propagate the original declaration node's location
|
||||||
|
if (!node.loc) {
|
||||||
|
node.loc = nodeLoc;
|
||||||
|
}
|
||||||
nodesOut.push(node);
|
nodesOut.push(node);
|
||||||
tail = t.isVariableDeclaration(node) ? node : null;
|
tail = t.isVariableDeclaration(node) ? node : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
const fn = (arg) => {
|
||||||
|
var [x, y] = arg;
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-destructuring"]
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
const fn = arg => {
|
||||||
|
var _arg = babelHelpers.slicedToArray(arg, 2),
|
||||||
|
x = _arg[0],
|
||||||
|
y = _arg[1];
|
||||||
|
};
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
[{
|
||||||
|
"original": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 2
|
||||||
|
},
|
||||||
|
"generated": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 2
|
||||||
|
}
|
||||||
|
}]
|
||||||
Loading…
x
Reference in New Issue
Block a user