Skip to content

Commit 3f6010c

Browse files
authored
Merge pull request #9298 from OrangeShark/new-rest-param-error
New rest parameter properties error message
2 parents 9134ed3 + be662e1 commit 3f6010c

18 files changed

+69
-51
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18204,7 +18204,10 @@ namespace ts {
1820418204
return grammarErrorOnNode(lastDeclare, Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare");
1820518205
}
1820618206
else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.ParameterPropertyModifier) && isBindingPattern((<ParameterDeclaration>node).name)) {
18207-
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_a_binding_pattern);
18207+
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_declared_using_a_binding_pattern);
18208+
}
18209+
else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.ParameterPropertyModifier) && (<ParameterDeclaration>node).dotDotDotToken) {
18210+
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_cannot_be_declared_using_a_rest_parameter);
1820818211
}
1820918212
if (flags & NodeFlags.Async) {
1821018213
return checkGrammarAsyncModifier(node, lastAsync);

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@
571571
"category": "Error",
572572
"code": 1186
573573
},
574-
"A parameter property may not be a binding pattern.": {
574+
"A parameter property may not be declared using a binding pattern.": {
575575
"category": "Error",
576576
"code": 1187
577577
},
@@ -851,6 +851,10 @@
851851
"category": "Error",
852852
"code": 1316
853853
},
854+
"A parameter property cannot be declared using a rest parameter.": {
855+
"category": "Error",
856+
"code": 1317
857+
},
854858
"Duplicate identifier '{0}'.": {
855859
"category": "Error",
856860
"code": 2300

src/compiler/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ namespace ts {
11781178
return token === SyntaxKind.OpenBracketToken
11791179
|| token === SyntaxKind.OpenBraceToken
11801180
|| token === SyntaxKind.AsteriskToken
1181+
|| token === SyntaxKind.DotDotDotToken
11811182
|| isLiteralPropertyName();
11821183
}
11831184

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be a binding pattern.
2-
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be a binding pattern.
3-
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be a binding pattern.
1+
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be declared using a binding pattern.
2+
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be declared using a binding pattern.
3+
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be declared using a binding pattern.
44

55

66
==== tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts (3 errors) ====
77
class C1 {
88
constructor(public [x, y, z]: string[]) {
99
~~~~~~~~~~~~~~~~~~~~~~~~~~
10-
!!! error TS1187: A parameter property may not be a binding pattern.
10+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
1111
}
1212
}
1313

1414
type TupleType1 =[string, number, boolean];
1515
class C2 {
1616
constructor(public [x, y, z]: TupleType1) {
1717
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18-
!!! error TS1187: A parameter property may not be a binding pattern.
18+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
1919
}
2020
}
2121

2222
type ObjType1 = { x: number; y: string; z: boolean }
2323
class C3 {
2424
constructor(public { x, y, z }: ObjType1) {
2525
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26-
!!! error TS1187: A parameter property may not be a binding pattern.
26+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
2727
}
2828
}

tests/baselines/reference/destructuringParameterDeclaration4.errors.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(11,13): error TS2370: A rest parameter must be of an array type.
22
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(13,13): error TS2370: A rest parameter must be of an array type.
3+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(14,17): error TS1047: A rest parameter cannot be optional.
4+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,16): error TS1048: A rest parameter cannot have an initializer.
35
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number | string'.
46
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(21,7): error TS2304: Cannot find name 'array2'.
57
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(22,4): error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
@@ -10,12 +12,12 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
1012
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(24,4): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'.
1113
Type 'number | string' is not assignable to type 'number'.
1214
Type 'string' is not assignable to type 'number'.
13-
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,24): error TS1005: ',' expected.
15+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,17): error TS1317: A parameter property cannot be declared using a rest parameter.
1416
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,22): error TS2304: Cannot find name 'E1'.
1517
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,28): error TS2304: Cannot find name 'E'.
1618

1719

18-
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (10 errors) ====
20+
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (12 errors) ====
1921
// If the parameter is a rest parameter, the parameter type is any[]
2022
// A type annotation for a rest parameter must denote an array type.
2123

@@ -34,7 +36,11 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
3436
~~~~~~~~~~~~~~~
3537
!!! error TS2370: A rest parameter must be of an array type.
3638
function a3(...b?) { } // Error, can't be optional
39+
~
40+
!!! error TS1047: A rest parameter cannot be optional.
3741
function a4(...b = [1,2,3]) { } // Error, can't have initializer
42+
~
43+
!!! error TS1048: A rest parameter cannot have an initializer.
3844
function a5([a, b, [[c]]]) { }
3945
function a6([a, b, c, ...x]: number[]) { }
4046

@@ -63,9 +69,9 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
6369

6470
var temp = [1, 2, 3];
6571
class C {
66-
constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier
67-
~~~
68-
!!! error TS1005: ',' expected.
72+
constructor(public ...temp) { } // Error, rest parameter can't have properties
73+
~~~~~~~~~~~~~~
74+
!!! error TS1317: A parameter property cannot be declared using a rest parameter.
6975
}
7076

7177
// Rest parameter with generic

tests/baselines/reference/destructuringParameterDeclaration4.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ a6([1, 2, "string"]); // Error, parameter type is number[]
2727

2828
var temp = [1, 2, 3];
2929
class C {
30-
constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier
30+
constructor(public ...temp) { } // Error, rest parameter can't have properties
3131
}
3232

3333
// Rest parameter with generic
@@ -83,12 +83,13 @@ a5([1, 2]); // Error, parameter type is [any, any, [[any]]]
8383
a6([1, 2, "string"]); // Error, parameter type is number[]
8484
var temp = [1, 2, 3];
8585
var C = (function () {
86-
function C(public) {
86+
function C() {
8787
var temp = [];
88-
for (var _i = 1; _i < arguments.length; _i++) {
89-
temp[_i - 1] = arguments[_i];
88+
for (var _i = 0; _i < arguments.length; _i++) {
89+
temp[_i - 0] = arguments[_i];
9090
}
91-
} // Error, rest parameter can't have accessibilityModifier
91+
this.temp = temp;
92+
} // Error, rest parameter can't have properties
9293
return C;
9394
}());
9495
// Rest parameter with generic

tests/baselines/reference/destructuringParameterProperties1.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2,17): error TS1187: A parameter property may not be a binding pattern.
2-
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(9,17): error TS1187: A parameter property may not be a binding pattern.
3-
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(16,17): error TS1187: A parameter property may not be a binding pattern.
1+
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2,17): error TS1187: A parameter property may not be declared using a binding pattern.
2+
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(9,17): error TS1187: A parameter property may not be declared using a binding pattern.
3+
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(16,17): error TS1187: A parameter property may not be declared using a binding pattern.
44
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,26): error TS2339: Property 'x' does not exist on type 'C1'.
55
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'.
66
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'.
@@ -17,7 +17,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2
1717
class C1 {
1818
constructor(public [x, y, z]: string[]) {
1919
~~~~~~~~~~~~~~~~~~~~~~~~~~
20-
!!! error TS1187: A parameter property may not be a binding pattern.
20+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
2121
}
2222
}
2323

@@ -26,7 +26,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2
2626
class C2 {
2727
constructor(public [x, y, z]: TupleType1) {
2828
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29-
!!! error TS1187: A parameter property may not be a binding pattern.
29+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
3030
}
3131
}
3232

@@ -35,7 +35,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2
3535
class C3 {
3636
constructor(public { x, y, z }: ObjType1) {
3737
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38-
!!! error TS1187: A parameter property may not be a binding pattern.
38+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
3939
}
4040
}
4141

tests/baselines/reference/destructuringParameterProperties2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2,36): error TS1187: A parameter property may not be a binding pattern.
1+
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2,36): error TS1187: A parameter property may not be declared using a binding pattern.
22
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'.
33
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'.
44
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'.
@@ -14,7 +14,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2
1414
class C1 {
1515
constructor(private k: number, private [a, b, c]: [number, string, boolean]) {
1616
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17-
!!! error TS1187: A parameter property may not be a binding pattern.
17+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
1818
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
1919
~
2020
!!! error TS2339: Property 'b' does not exist on type 'C1'.

tests/baselines/reference/destructuringParameterProperties3.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(2,31): error TS1187: A parameter property may not be a binding pattern.
1+
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(2,31): error TS1187: A parameter property may not be declared using a binding pattern.
22
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
33
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
44
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
@@ -11,7 +11,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(1
1111
class C1<T, U, V> {
1212
constructor(private k: T, private [a, b, c]: [T,U,V]) {
1313
~~~~~~~~~~~~~~~~~~~~~~~~~~
14-
!!! error TS1187: A parameter property may not be a binding pattern.
14+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
1515
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
1616
~
1717
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.

tests/baselines/reference/destructuringParameterProperties4.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(3,31): error TS1187: A parameter property may not be a binding pattern.
1+
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(3,31): error TS1187: A parameter property may not be declared using a binding pattern.
22
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(4,59): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
33
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(4,83): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
44
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(5,18): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
@@ -15,7 +15,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(2
1515
class C1<T, U, V> {
1616
constructor(private k: T, protected [a, b, c]: [T,U,V]) {
1717
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18-
!!! error TS1187: A parameter property may not be a binding pattern.
18+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
1919
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
2020
~
2121
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.

0 commit comments

Comments
 (0)