fix regression with completion records for assignment expressions - fixes #1204
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user