fix destructuring transformer AssignmentExpression to properly handle completion records

This commit is contained in:
Sebastian McKenzie 2015-05-30 22:33:09 -04:00
parent 7fd403998c
commit 4043e8e8b9

View File

@ -110,12 +110,7 @@ export function CatchClause(node, parent, scope, file) {
export function AssignmentExpression(node, parent, scope, file) { export function AssignmentExpression(node, parent, scope, file) {
if (!t.isPattern(node.left)) return; if (!t.isPattern(node.left)) return;
var ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref");
var nodes = []; var nodes = [];
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(ref, node.right)
]));
var destructuring = new DestructuringTransformer({ var destructuring = new DestructuringTransformer({
operator: node.operator, operator: node.operator,
@ -124,13 +119,24 @@ export function AssignmentExpression(node, parent, scope, file) {
nodes: nodes nodes: nodes
}); });
if (t.isArrayExpression(node.right)) { var ref;
destructuring.arrays[ref.name] = true; if (this.isCompletionRecord() || !this.parentPath.isExpressionStatement()) {
ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref");;
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(ref, node.right)
]));
if (t.isArrayExpression(node.right)) {
destructuring.arrays[ref.name] = true;
}
} }
destructuring.init(node.left, ref); destructuring.init(node.left, ref || node.right);
nodes.push(t.expressionStatement(ref)); if (ref) {
nodes.push(t.expressionStatement(ref));
}
return nodes; return nodes;
} }