Skip to content

Commit 0bdc79f

Browse files
Only emit the RHS in an empty assignment pattern.
1 parent 0ec38b7 commit 0bdc79f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/compiler/emitter.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3249,7 +3249,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
32493249
function emitAssignmentExpression(root: BinaryExpression) {
32503250
let target = root.left;
32513251
let value = root.right;
3252-
if (isAssignmentExpressionStatement) {
3252+
3253+
if (isEmptyObjectLiteralOrArrayLiteral(target)) {
3254+
emit(value);
3255+
}
3256+
else if (isAssignmentExpressionStatement) {
32533257
emitDestructuringAssignment(target, value);
32543258
}
32553259
else {

src/compiler/utilities.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,17 @@ namespace ts {
19811981
(node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).name === node);
19821982
}
19831983

1984+
export function isEmptyObjectLiteralOrArrayLiteral(expression: Node): boolean {
1985+
let kind = expression.kind;
1986+
if (kind === SyntaxKind.ObjectLiteralExpression) {
1987+
return (<ObjectLiteralExpression>expression).properties.length === 0;
1988+
}
1989+
if (kind === SyntaxKind.ArrayLiteralExpression) {
1990+
return (<ArrayLiteralExpression>expression).elements.length === 0;
1991+
}
1992+
return false;
1993+
}
1994+
19841995
export function getLocalSymbolForExportDefault(symbol: Symbol) {
19851996
return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined;
19861997
}

0 commit comments

Comments
 (0)