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
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;
}