mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-26 21:23:53 -06:00
Merge pull request #12177 from Microsoft/error-on-non-identifier-rest-in-destructuring-assignment
Error on non identifier rest in destructuring assignment
This commit is contained in:
commit
1bc4ab0850
@ -13941,7 +13941,12 @@ namespace ts {
|
||||
error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(objectLiteralType), declarationNameToString(name));
|
||||
}
|
||||
}
|
||||
else if (property.kind !== SyntaxKind.SpreadAssignment) {
|
||||
else if (property.kind === SyntaxKind.SpreadAssignment) {
|
||||
if (property.expression.kind !== SyntaxKind.Identifier) {
|
||||
error(property.expression, Diagnostics.An_object_rest_element_must_be_an_identifier);
|
||||
}
|
||||
}
|
||||
else {
|
||||
error(property, Diagnostics.Property_assignment_expected);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1991,6 +1991,10 @@
|
||||
"category": "Error",
|
||||
"code": 2700
|
||||
},
|
||||
"An object rest element must be an identifier.": {
|
||||
"category": "Error",
|
||||
"code": 2701
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
@ -328,8 +328,9 @@ namespace ts {
|
||||
bindingElements.push(p);
|
||||
}
|
||||
}
|
||||
else if (i === properties.length - 1 && p.kind === SyntaxKind.SpreadAssignment) {
|
||||
Debug.assert((p as SpreadAssignment).expression.kind === SyntaxKind.Identifier);
|
||||
else if (i === properties.length - 1 &&
|
||||
p.kind === SyntaxKind.SpreadAssignment &&
|
||||
p.expression.kind === SyntaxKind.Identifier) {
|
||||
if (bindingElements.length) {
|
||||
emitRestAssignment(bindingElements, value, location, target);
|
||||
bindingElements = [];
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
tests/cases/conformance/types/rest/objectRestNegative.ts(2,10): error TS2462: A rest element must be last in a destructuring pattern
|
||||
tests/cases/conformance/types/rest/objectRestNegative.ts(3,31): error TS2462: A rest element must be last in a destructuring pattern
|
||||
tests/cases/conformance/types/rest/objectRestNegative.ts(6,17): error TS2700: Rest types may only be created from object types.
|
||||
tests/cases/conformance/types/rest/objectRestNegative.ts(11,9): error TS2701: An object rest element must be an identifier.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/rest/objectRestNegative.ts (3 errors) ====
|
||||
==== tests/cases/conformance/types/rest/objectRestNegative.ts (4 errors) ====
|
||||
let o = { a: 1, b: 'no' };
|
||||
var { ...mustBeLast, a } = o;
|
||||
~~~~~~~~~~
|
||||
@ -18,4 +19,9 @@ tests/cases/conformance/types/rest/objectRestNegative.ts(6,17): error TS2700: Re
|
||||
!!! error TS2700: Rest types may only be created from object types.
|
||||
return rest;
|
||||
}
|
||||
|
||||
let rest: { b: string }
|
||||
({a, ...rest.b + rest.b} = o);
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2701: An object rest element must be an identifier.
|
||||
|
||||
@ -7,6 +7,9 @@ function generic<T extends { x, y }>(t: T) {
|
||||
let { x, ...rest } = t;
|
||||
return rest;
|
||||
}
|
||||
|
||||
let rest: { b: string }
|
||||
({a, ...rest.b + rest.b} = o);
|
||||
|
||||
|
||||
//// [objectRestNegative.js]
|
||||
@ -25,3 +28,5 @@ function generic(t) {
|
||||
var x = t.x, rest = __rest(t, ["x"]);
|
||||
return rest;
|
||||
}
|
||||
var rest;
|
||||
(a = o.a, o, o);
|
||||
|
||||
@ -6,3 +6,6 @@ function generic<T extends { x, y }>(t: T) {
|
||||
let { x, ...rest } = t;
|
||||
return rest;
|
||||
}
|
||||
|
||||
let rest: { b: string }
|
||||
({a, ...rest.b + rest.b} = o);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user