Disallow binding patterns in binding rest elements (fixes #2519)
This commit is contained in:
parent
6637f49209
commit
2d3b22cbba
|
@ -12729,6 +12729,11 @@ module ts {
|
|||
if (node !== elements[elements.length - 1]) {
|
||||
return grammarErrorOnNode(node, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
|
||||
}
|
||||
|
||||
if (node.name.kind === SyntaxKind.ArrayBindingPattern || node.name.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
return grammarErrorOnNode(node.name, Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
|
||||
}
|
||||
|
||||
if (node.initializer) {
|
||||
// Error on equals token which immediate precedes the initializer
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - 1, 1, Diagnostics.A_rest_element_cannot_have_an_initializer);
|
||||
|
|
|
@ -363,6 +363,7 @@ module ts {
|
|||
External_module_0_uses_export_and_cannot_be_used_with_export_Asterisk: { code: 2498, category: DiagnosticCategory.Error, key: "External module '{0}' uses 'export =' and cannot be used with 'export *'." },
|
||||
An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2499, category: DiagnosticCategory.Error, key: "An interface can only extend an identifier/qualified-name with optional type arguments." },
|
||||
A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2500, category: DiagnosticCategory.Error, key: "A class can only implement an identifier/qualified-name with optional type arguments." },
|
||||
A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||
|
|
|
@ -1439,6 +1439,10 @@
|
|||
"category": "Error",
|
||||
"code": 2500
|
||||
},
|
||||
"A rest element cannot contain a binding pattern.": {
|
||||
"category": "Error",
|
||||
"code": 2501
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
tests/cases/conformance/es6/destructuring/restElementWithBindingPattern.ts(1,9): error TS2501: A rest element cannot contain a binding pattern.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/restElementWithBindingPattern.ts (1 errors) ====
|
||||
var [...[a, b]] = [0, 1];
|
||||
~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
|
@ -0,0 +1,5 @@
|
|||
//// [restElementWithBindingPattern.ts]
|
||||
var [...[a, b]] = [0, 1];
|
||||
|
||||
//// [restElementWithBindingPattern.js]
|
||||
var _a = [0, 1], [a, b] = _a.slice(0);
|
|
@ -0,0 +1,10 @@
|
|||
tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts(1,9): error TS2501: A rest element cannot contain a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts(1,16): error TS2459: Type 'number[]' has no property 'b' and no string index signature.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts (2 errors) ====
|
||||
var [...{0: a, b }] = [0, 1];
|
||||
~~~~~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
~
|
||||
!!! error TS2459: Type 'number[]' has no property 'b' and no string index signature.
|
|
@ -0,0 +1,5 @@
|
|||
//// [restElementWithBindingPattern2.ts]
|
||||
var [...{0: a, b }] = [0, 1];
|
||||
|
||||
//// [restElementWithBindingPattern2.js]
|
||||
var _a = [0, 1], { 0: a, b } = _a.slice(0);
|
|
@ -0,0 +1 @@
|
|||
var [...[a, b]] = [0, 1];
|
|
@ -0,0 +1 @@
|
|||
var [...{0: a, b }] = [0, 1];
|
Loading…
Reference in a new issue