Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit ef2687b

Browse files
authored
Fix: Handle assignment within property destructuring (fixes #332) (#336)
1 parent 8d5bc7b commit ef2687b

File tree

3 files changed

+417
-10
lines changed

3 files changed

+417
-10
lines changed

lib/convert.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -666,17 +666,36 @@ module.exports = function convert(config) {
666666
});
667667
break;
668668

669-
case SyntaxKind.ShorthandPropertyAssignment:
670-
Object.assign(result, {
671-
type: AST_NODE_TYPES.Property,
672-
key: convertChild(node.name),
673-
value: convertChild(node.name),
674-
computed: false,
675-
method: false,
676-
shorthand: true,
677-
kind: "init"
678-
});
669+
case SyntaxKind.ShorthandPropertyAssignment: {
670+
if (node.objectAssignmentInitializer) {
671+
Object.assign(result, {
672+
type: AST_NODE_TYPES.Property,
673+
key: convertChild(node.name),
674+
value: {
675+
type: AST_NODE_TYPES.AssignmentPattern,
676+
left: convertChild(node.name),
677+
right: convertChild(node.objectAssignmentInitializer),
678+
loc: result.loc,
679+
range: result.range
680+
},
681+
computed: false,
682+
method: false,
683+
shorthand: true,
684+
kind: "init"
685+
});
686+
} else {
687+
Object.assign(result, {
688+
type: AST_NODE_TYPES.Property,
689+
key: convertChild(node.name),
690+
value: convertChild(node.initializer || node.name),
691+
computed: false,
692+
method: false,
693+
shorthand: true,
694+
kind: "init"
695+
});
696+
}
679697
break;
698+
}
680699

681700
case SyntaxKind.ComputedPropertyName:
682701

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
({ foo = [] } = bar);

0 commit comments

Comments
 (0)