diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8ddfb53d21f..06c4ca9190f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10172,6 +10172,9 @@ module ts { else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) { return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); } + else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.AccessibilityModifier) && isBindingPattern((node).name)) { + return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); + } } function checkGrammarForDisallowedTrailingComma(list: NodeArray): boolean { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 2a342fa17d2..80e1505569d 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -146,6 +146,7 @@ module ts { Modifiers_cannot_appear_here: { code: 1184, category: DiagnosticCategory.Error, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, + A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index efb2bfe7e94..704e3ada25f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -224,7 +224,7 @@ "A 'declare' modifier cannot be used with an import declaration.": { "category": "Error", "code": 1079, - "isEarly": true + "isEarly": true }, "Invalid 'reference' directive syntax.": { "category": "Error", @@ -659,7 +659,7 @@ "An implementation cannot be declared in ambient contexts.": { "category": "Error", "code": 1184, - "isEarly": true + "isEarly": true }, "Modifiers cannot appear here.": { "category": "Error", @@ -673,6 +673,10 @@ "category": "Error", "code": 1186 }, + "A parameter property may not be a binding pattern.": { + "category": "Error", + "code": 1187 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/tests/baselines/reference/destructuringParameterProperties1.errors.txt b/tests/baselines/reference/destructuringParameterProperties1.errors.txt index c3a9cfc2924..b8f3a22b4c5 100644 --- a/tests/baselines/reference/destructuringParameterProperties1.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties1.errors.txt @@ -1,3 +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(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'. @@ -10,9 +13,11 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(2 tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts(29,42): error TS2339: Property 'z' does not exist on type 'C3'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts (10 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties1.ts (13 errors) ==== class C1 { constructor(public [x, y, z]: string[]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. } } @@ -20,6 +25,8 @@ 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. } } @@ -27,6 +34,8 @@ 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. } } diff --git a/tests/baselines/reference/destructuringParameterProperties2.errors.txt b/tests/baselines/reference/destructuringParameterProperties2.errors.txt index 3b424f8ae97..61c0e61611a 100644 --- a/tests/baselines/reference/destructuringParameterProperties2.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties2.errors.txt @@ -1,3 +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(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'. @@ -7,9 +8,11 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(1 tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(21,27): error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts (7 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts (8 errors) ==== class C1 { constructor(private k: number, private [a, b, c]: [number, string, boolean]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { ~ !!! error TS2339: Property 'b' does not exist on type 'C1'. diff --git a/tests/baselines/reference/destructuringParameterProperties3.errors.txt b/tests/baselines/reference/destructuringParameterProperties3.errors.txt index 44c18d32cc1..73d7dab2a38 100644 --- a/tests/baselines/reference/destructuringParameterProperties3.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties3.errors.txt @@ -1,3 +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(3,59): error TS2339: Property 'b' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'. @@ -6,9 +7,11 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(1 tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts (6 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties3.ts (7 errors) ==== class C1 { constructor(private k: T, private [a, b, c]: [T,U,V]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { ~ !!! error TS2339: Property 'b' does not exist on type 'C1'. diff --git a/tests/baselines/reference/destructuringParameterProperties4.errors.txt b/tests/baselines/reference/destructuringParameterProperties4.errors.txt index 9d8fdb9d933..04f6f82b5df 100644 --- a/tests/baselines/reference/destructuringParameterProperties4.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties4.errors.txt @@ -1,3 +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(4,59): error TS2339: Property 'b' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(4,83): error TS2339: Property 'c' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(5,18): error TS2339: Property 'a' does not exist on type 'C1'. @@ -9,10 +10,12 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(2 tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts(24,44): error TS2339: Property 'c' does not exist on type 'C2'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts (9 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties4.ts (10 errors) ==== class C1 { constructor(private k: T, protected [a, b, c]: [T,U,V]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { ~ !!! error TS2339: Property 'b' does not exist on type 'C1'. diff --git a/tests/baselines/reference/destructuringParameterProperties5.errors.txt b/tests/baselines/reference/destructuringParameterProperties5.errors.txt index 00839fff662..dca02a9a84e 100644 --- a/tests/baselines/reference/destructuringParameterProperties5.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties5.errors.txt @@ -1,3 +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,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. @@ -12,12 +13,14 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(1 Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts (9 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts (10 errors) ==== type ObjType1 = { x: number; y: string; z: boolean } type TupleType1 = [ObjType1, number, string] class C1 { constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. ~~ !!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature. ~~