Merge pull request #7970 from Microsoft/fix-transforms-empty-destructuring-assignment

[Transforms] Correct destructuring assignment to empty object
This commit is contained in:
Nathan Shively-Sanders 2016-04-12 14:59:31 -07:00
commit ab49eb9fef
2 changed files with 11 additions and 5 deletions

View File

@ -17,10 +17,16 @@ namespace ts {
node: BinaryExpression,
needsValue: boolean,
recordTempVariable: (node: Identifier) => void,
visitor?: (node: Node) => VisitResult<Node>) {
visitor?: (node: Node) => VisitResult<Node>): Expression {
if (isEmptyObjectLiteralOrArrayLiteral(node.left)) {
return node.right;
const right = node.right;
if (isDestructuringAssignment(right)) {
return flattenDestructuringAssignment(context, right, needsValue, recordTempVariable, visitor);
}
else {
return node.right;
}
}
let location: TextRange = node;
@ -401,4 +407,4 @@ namespace ts {
return emitTempVariableAssignment(value, location);
}
}
}
}

View File

@ -9,8 +9,8 @@ let x, y, z, a1, a2, a3;
//// [emptyAssignmentPatterns02_ES5.js]
var a;
var x, y, z, a1, a2, a3;
((x = a.x, y = a.y, z = a.z, a));
((a1 = a[0], a2 = a[1], a3 = a[2], a));
(x = a.x, y = a.y, z = a.z, a);
(a1 = a[0], a2 = a[1], a3 = a[2], a);
//// [emptyAssignmentPatterns02_ES5.d.ts]