Skip to content

Commit 1ca59ab

Browse files
lauraharkercopybara-github
authored andcommitted
Fix object pattern rest transpilation when assigning to a non-simple-name, like ({a, ...b.rest} = o});
PiperOrigin-RevId: 857198731
1 parent 43c374c commit 1ca59ab

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/com/google/javascript/jscomp/Es6RewriteDestructuring.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,10 @@ private void replaceObjectPattern(
565565

566566
Node restName = child.getOnlyChild(); // e.g. get `rest` from `const {...rest} = {};`
567567
if (restName.getString().startsWith(DESTRUCTURING_TEMP_VAR)) {
568+
checkState(restName.isName(), restName);
568569
newLHS = createTempVarNameNode(restName.getString(), type(restName));
569570
} else {
570-
newLHS = astFactory.createName(restName.getString(), type(restName));
571+
newLHS = restName.detach();
571572
}
572573
newRHS = objectPatternRestRHS(objectPattern, child, restTempVarName, propsToDeleteForRest);
573574
} else {

test/com/google/javascript/jscomp/Es6RewriteDestructuringTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,8 +1600,6 @@ public void testObjectPatternWithRestAssignStatement() {
16001600

16011601
@Test
16021602
public void testObjectPatternWithRestAssignStatement_assignedToProperty() {
1603-
// TODO: b/475285460 - fix the output of this test: it should assign to `obj.rest`, not just
1604-
// `rest`.
16051603
test(
16061604
"var a, obj = {}; ({a, ...obj.rest} = foo());",
16071605
"""
@@ -1610,7 +1608,7 @@ public void testObjectPatternWithRestAssignStatement_assignedToProperty() {
16101608
var $jscomp$destructuring$var0 = foo();
16111609
var $jscomp$destructuring$var1 = Object.assign({}, $jscomp$destructuring$var0);
16121610
a = $jscomp$destructuring$var0.a;
1613-
rest = (delete $jscomp$destructuring$var1.a, $jscomp$destructuring$var1);
1611+
obj.rest = (delete $jscomp$destructuring$var1.a, $jscomp$destructuring$var1);
16141612
""");
16151613
}
16161614

0 commit comments

Comments
 (0)