mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Disallow initializers in assignment rest elements
This commit is contained in:
@@ -7657,11 +7657,17 @@ module ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (i === elements.length - 1) {
|
||||
checkDestructuringAssignment((<SpreadElementExpression>e).expression, createArrayType(elementType), contextualMapper);
|
||||
if (i < elements.length - 1) {
|
||||
error(e, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
|
||||
}
|
||||
else {
|
||||
error(e, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
|
||||
let restExpression = (<SpreadElementExpression>e).expression;
|
||||
if (restExpression.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>restExpression).operatorToken.kind === SyntaxKind.EqualsToken) {
|
||||
error((<BinaryExpression>restExpression).operatorToken, Diagnostics.A_rest_element_cannot_have_an_initializer);
|
||||
}
|
||||
else {
|
||||
checkDestructuringAssignment(restExpression, createArrayType(elementType), contextualMapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
tests/cases/conformance/es6/destructuring/restElementWithInitializer2.ts(3,5): error TS2364: Invalid left-hand side of assignment expression.
|
||||
tests/cases/conformance/es6/destructuring/restElementWithInitializer2.ts(3,7): error TS1186: A rest element cannot have an initializer.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/restElementWithInitializer2.ts (1 errors) ====
|
||||
var a: number[];
|
||||
var x: number[];
|
||||
[...x = a] = a; // Error, rest element cannot have initializer
|
||||
~~~~~
|
||||
!!! error TS2364: Invalid left-hand side of assignment expression.
|
||||
~
|
||||
!!! error TS1186: A rest element cannot have an initializer.
|
||||
|
||||
Reference in New Issue
Block a user