fix regression with completion records for assignment expressions - fixes #1204

This commit is contained in:
Sebastian McKenzie
2015-04-11 18:13:47 -07:00
parent e362512af3
commit 1a30f1aafc
5 changed files with 33 additions and 5 deletions

View File

@@ -126,10 +126,11 @@ export function AssignmentExpression(node, parent, scope, file) {
if (!t.isPattern(node.left)) return;
var ref = scope.generateUidIdentifier("temp");
scope.push({ id: ref });
var nodes = [];
nodes.push(t.expressionStatement(t.assignmentExpression("=", ref, node.right)));
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(ref, node.right)
]));
var destructuring = new DestructuringTransformer({
operator: node.operator,
@@ -137,6 +138,11 @@ export function AssignmentExpression(node, parent, scope, file) {
scope: scope,
nodes: nodes
});
if (t.isArrayExpression(node.right)) {
destructuring.arrays[ref.name] = true;
}
destructuring.init(node.left, ref);
nodes.push(t.expressionStatement(ref));

View File

@@ -132,11 +132,24 @@ export default class TraversalPath {
_maybePopFromStatements(nodes) {
var last = nodes[nodes.length - 1];
if (t.isExpressionStatement(last) && t.isIdentifier(last.expression)) {
if (t.isExpressionStatement(last) && t.isIdentifier(last.expression) && !this.isCompletionRecord()) {
nodes.pop();
}
}
isCompletionRecord() {
var path = this;
do {
var container = path.container;
if (Array.isArray(container) && path.key !== container.length - 1) {
return false;
}
} while (path = path.parentPath && !path.isProgram());
return true;
}
isStatementOrBlock() {
if (t.isLabeledStatement(this.parent) || t.isBlockStatement(this.container)) {
return false;