Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18204,7 +18204,10 @@ namespace ts {
return grammarErrorOnNode(lastDeclare, Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare");
}
else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.ParameterPropertyModifier) && isBindingPattern((<ParameterDeclaration>node).name)) {
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_a_binding_pattern);
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_declared_using_a_binding_pattern);
}
else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.ParameterPropertyModifier) && (<ParameterDeclaration>node).dotDotDotToken) {
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_cannot_be_declared_using_a_rest_parameter);
}
if (flags & NodeFlags.Async) {
return checkGrammarAsyncModifier(node, lastAsync);
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@
"category": "Error",
"code": 1186
},
"A parameter property may not be a binding pattern.": {
"A parameter property may not be declared using a binding pattern.": {
"category": "Error",
"code": 1187
},
Expand Down Expand Up @@ -851,6 +851,10 @@
"category": "Error",
"code": 1316
},
"A parameter property cannot be declared using a rest parameter.": {
"category": "Error",
"code": 1317
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
Expand Down
1 change: 1 addition & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ namespace ts {
return token === SyntaxKind.OpenBracketToken
|| token === SyntaxKind.OpenBraceToken
|| token === SyntaxKind.AsteriskToken
|| token === SyntaxKind.DotDotDotToken
|| isLiteralPropertyName();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be a binding pattern.
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be a binding pattern.
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be a binding pattern.
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be declared using a binding pattern.
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be declared using a binding pattern.
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be declared using a binding pattern.


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

type TupleType1 =[string, number, boolean];
class C2 {
constructor(public [x, y, z]: TupleType1) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
!!! error TS1187: A parameter property may not be declared using a binding pattern.
}
}

type ObjType1 = { x: number; y: string; z: boolean }
class C3 {
constructor(public { x, y, z }: ObjType1) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
!!! error TS1187: A parameter property may not be declared using a binding pattern.
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(11,13): error TS2370: A rest parameter must be of an array type.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(13,13): error TS2370: A rest parameter must be of an array type.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(14,17): error TS1047: A rest parameter cannot be optional.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,16): error TS1048: A rest parameter cannot have an initializer.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number | string'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(21,7): error TS2304: Cannot find name 'array2'.
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]]]'.
Expand All @@ -10,12 +12,12 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(24,4): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'.
Type 'number | string' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,24): error TS1005: ',' expected.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,17): error TS1317: A parameter property cannot be declared using a rest parameter.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,22): error TS2304: Cannot find name 'E1'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,28): error TS2304: Cannot find name 'E'.


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

Expand All @@ -34,7 +36,11 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
~~~~~~~~~~~~~~~
!!! error TS2370: A rest parameter must be of an array type.
function a3(...b?) { } // Error, can't be optional
~

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wasn't this an error before? weird.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the git history and they never had an error when they were added. Seems it has something to do with the other bogus baselines. They have always outputted the correct error in the compiler.

!!! error TS1047: A rest parameter cannot be optional.
function a4(...b = [1,2,3]) { } // Error, can't have initializer
~
!!! error TS1048: A rest parameter cannot have an initializer.
function a5([a, b, [[c]]]) { }
function a6([a, b, c, ...x]: number[]) { }

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

var temp = [1, 2, 3];
class C {
constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier
~~~
!!! error TS1005: ',' expected.
constructor(public ...temp) { } // Error, rest parameter can't have properties
~~~~~~~~~~~~~~
!!! error TS1317: A parameter property cannot be declared using a rest parameter.
}

// Rest parameter with generic
Expand Down
11 changes: 6 additions & 5 deletions tests/baselines/reference/destructuringParameterDeclaration4.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ a6([1, 2, "string"]); // Error, parameter type is number[]

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

// Rest parameter with generic
Expand Down Expand Up @@ -83,12 +83,13 @@ a5([1, 2]); // Error, parameter type is [any, any, [[any]]]
a6([1, 2, "string"]); // Error, parameter type is number[]
var temp = [1, 2, 3];
var C = (function () {
function C(public) {
function C() {
var temp = [];
for (var _i = 1; _i < arguments.length; _i++) {
temp[_i - 1] = arguments[_i];
for (var _i = 0; _i < arguments.length; _i++) {
temp[_i - 0] = arguments[_i];
}
} // Error, rest parameter can't have accessibilityModifier
this.temp = temp;
} // Error, rest parameter can't have properties
return C;
}());
// Rest parameter with generic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2,17): error TS1187: A parameter property may not be a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(9,17): error TS1187: A parameter property may not be a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(16,17): error TS1187: A parameter property may not be a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2,17): error TS1187: A parameter property may not be declared using a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(9,17): error TS1187: A parameter property may not be declared using a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(16,17): error TS1187: A parameter property may not be declared using a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,26): error TS2339: Property 'x' does not exist on type 'C1'.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'.
Expand All @@ -17,7 +17,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2
class C1 {
constructor(public [x, y, z]: string[]) {
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
!!! error TS1187: A parameter property may not be declared using a binding pattern.
}
}

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2,36): error TS1187: A parameter property may not be a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2,36): error TS1187: A parameter property may not be declared using a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'.
Expand All @@ -14,7 +14,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2
class C1 {
constructor(private k: number, private [a, b, c]: [number, string, boolean]) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
!!! error TS1187: A parameter property may not be declared using a binding pattern.
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
~
!!! error TS2339: Property 'b' does not exist on type 'C1'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(2,31): error TS1187: A parameter property may not be a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(2,31): error TS1187: A parameter property may not be declared using a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
Expand All @@ -11,7 +11,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(1
class C1<T, U, V> {
constructor(private k: T, private [a, b, c]: [T,U,V]) {
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
!!! error TS1187: A parameter property may not be declared using a binding pattern.
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
~
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(3,31): error TS1187: A parameter property may not be a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(3,31): error TS1187: A parameter property may not be declared using a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(4,59): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(4,83): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(5,18): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
Expand All @@ -15,7 +15,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(2
class C1<T, U, V> {
constructor(private k: T, protected [a, b, c]: [T,U,V]) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
!!! error TS1187: A parameter property may not be declared using a binding pattern.
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
~
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,17): error TS1187: A parameter property may not be a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,17): error TS1187: A parameter property may not be declared using a binding pattern.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,27): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,31): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature.
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,35): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature.
Expand All @@ -20,7 +20,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(1
class C1 {
constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
!!! error TS1187: A parameter property may not be declared using a binding pattern.
~~
!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature.
~~
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/parser509668.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts(3,23): error TS1005: ',' expected.
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts(3,16): error TS1317: A parameter property cannot be declared using a rest parameter.


==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts (1 errors) ====
class Foo3 {
// Doesn't work, but should
constructor (public ...args: string[]) { }
~~~
!!! error TS1005: ',' expected.
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1317: A parameter property cannot be declared using a rest parameter.
}
7 changes: 4 additions & 3 deletions tests/baselines/reference/parser509668.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ class Foo3 {
//// [parser509668.js]
var Foo3 = (function () {
// Doesn't work, but should
function Foo3(public) {
function Foo3() {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
this.args = args;
}
return Foo3;
}());
6 changes: 3 additions & 3 deletions tests/baselines/reference/restParamModifier2.errors.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/compiler/restParamModifier2.ts(2,24): error TS1005: ',' expected.
tests/cases/compiler/restParamModifier2.ts(2,17): error TS1317: A parameter property cannot be declared using a rest parameter.


==== tests/cases/compiler/restParamModifier2.ts (1 errors) ====
class C {
constructor(public ...rest: string[]) {}
~~~
!!! error TS1005: ',' expected.
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1317: A parameter property cannot be declared using a rest parameter.
}
7 changes: 4 additions & 3 deletions tests/baselines/reference/restParamModifier2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ class C {

//// [restParamModifier2.js]
var C = (function () {
function C(public) {
function C() {
var rest = [];
for (var _i = 1; _i < arguments.length; _i++) {
rest[_i - 1] = arguments[_i];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i - 0] = arguments[_i];
}
this.rest = rest;
}
return C;
}());
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/varArgConstructorMemberParameter.ts(10,25): error TS1005: ',' expected.
tests/cases/compiler/varArgConstructorMemberParameter.ts(10,18): error TS1317: A parameter property cannot be declared using a rest parameter.


==== tests/cases/compiler/varArgConstructorMemberParameter.ts (1 errors) ====
Expand All @@ -12,7 +12,7 @@ tests/cases/compiler/varArgConstructorMemberParameter.ts(10,25): error TS1005: '

class Foo3 {
constructor (public ...args: string[]) { }
~~~
!!! error TS1005: ',' expected.
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1317: A parameter property cannot be declared using a rest parameter.
}

Loading