Skip to content

Commit 9b2b2ca

Browse files
committed
Error on non-identifier rest in destructuring assignment
1 parent ea309fe commit 9b2b2ca

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13941,7 +13941,12 @@ namespace ts {
1394113941
error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(objectLiteralType), declarationNameToString(name));
1394213942
}
1394313943
}
13944-
else if (property.kind !== SyntaxKind.SpreadAssignment) {
13944+
else if (property.kind === SyntaxKind.SpreadAssignment) {
13945+
if (property.expression.kind !== SyntaxKind.Identifier) {
13946+
error(property.expression, Diagnostics.An_object_rest_element_must_be_an_identifier);
13947+
}
13948+
}
13949+
else {
1394513950
error(property, Diagnostics.Property_assignment_expected);
1394613951
}
1394713952
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,10 @@
19911991
"category": "Error",
19921992
"code": 2700
19931993
},
1994+
"An object rest element must be an identifier.": {
1995+
"category": "Error",
1996+
"code": 2701
1997+
},
19941998

19951999
"Import declaration '{0}' is using private name '{1}'.": {
19962000
"category": "Error",

src/compiler/transformers/destructuring.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,9 @@ namespace ts {
328328
bindingElements.push(p);
329329
}
330330
}
331-
else if (i === properties.length - 1 && p.kind === SyntaxKind.SpreadAssignment) {
332-
Debug.assert((p as SpreadAssignment).expression.kind === SyntaxKind.Identifier);
331+
else if (i === properties.length - 1 &&
332+
p.kind === SyntaxKind.SpreadAssignment &&
333+
p.expression.kind === SyntaxKind.Identifier) {
333334
if (bindingElements.length) {
334335
emitRestAssignment(bindingElements, value, location, target);
335336
bindingElements = [];

0 commit comments

Comments
 (0)