diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e516a6319ec..acab10a9ac3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18225,9 +18225,6 @@ namespace ts { if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.A_set_accessor_cannot_have_rest_parameter); } - else if (parameter.flags & NodeFlags.Modifier) { - return grammarErrorOnNode(accessor.name, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); - } else if (parameter.questionToken) { return grammarErrorOnNode(parameter.questionToken, Diagnostics.A_set_accessor_cannot_have_an_optional_parameter); } diff --git a/tests/baselines/reference/accessorParameterAccessibilityModifier.errors.txt b/tests/baselines/reference/accessorParameterAccessibilityModifier.errors.txt index fad1d8ff10a..3036e734105 100644 --- a/tests/baselines/reference/accessorParameterAccessibilityModifier.errors.txt +++ b/tests/baselines/reference/accessorParameterAccessibilityModifier.errors.txt @@ -1,20 +1,14 @@ -tests/cases/compiler/accessorParameterAccessibilityModifier.ts(3,9): error TS2369: A parameter property is only allowed in a constructor implementation. tests/cases/compiler/accessorParameterAccessibilityModifier.ts(3,11): error TS2369: A parameter property is only allowed in a constructor implementation. -tests/cases/compiler/accessorParameterAccessibilityModifier.ts(4,16): error TS2369: A parameter property is only allowed in a constructor implementation. tests/cases/compiler/accessorParameterAccessibilityModifier.ts(4,18): error TS2369: A parameter property is only allowed in a constructor implementation. -==== tests/cases/compiler/accessorParameterAccessibilityModifier.ts (4 errors) ==== +==== tests/cases/compiler/accessorParameterAccessibilityModifier.ts (2 errors) ==== class C { set X(public v) { } - ~ -!!! error TS2369: A parameter property is only allowed in a constructor implementation. ~~~~~~~~ !!! error TS2369: A parameter property is only allowed in a constructor implementation. static set X(public v2) { } - ~ -!!! error TS2369: A parameter property is only allowed in a constructor implementation. ~~~~~~~~~ !!! error TS2369: A parameter property is only allowed in a constructor implementation. } \ No newline at end of file diff --git a/tests/baselines/reference/parserMemberAccessorDeclaration15.errors.txt b/tests/baselines/reference/parserMemberAccessorDeclaration15.errors.txt index f76264f6090..cba1e1fee92 100644 --- a/tests/baselines/reference/parserMemberAccessorDeclaration15.errors.txt +++ b/tests/baselines/reference/parserMemberAccessorDeclaration15.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration15.ts(2,8): error TS2369: A parameter property is only allowed in a constructor implementation. tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration15.ts(2,12): error TS2369: A parameter property is only allowed in a constructor implementation. -==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration15.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration15.ts (1 errors) ==== class C { set Foo(public a: number) { } - ~~~ -!!! error TS2369: A parameter property is only allowed in a constructor implementation. ~~~~~~~~~~~~~~~~ !!! error TS2369: A parameter property is only allowed in a constructor implementation. } \ No newline at end of file diff --git a/tests/baselines/reference/readonlyInNonPropertyParameters.errors.txt b/tests/baselines/reference/readonlyInNonPropertyParameters.errors.txt new file mode 100644 index 00000000000..696404c6d98 --- /dev/null +++ b/tests/baselines/reference/readonlyInNonPropertyParameters.errors.txt @@ -0,0 +1,19 @@ +tests/cases/compiler/readonlyInNonPropertyParameters.ts(4,9): error TS2369: A parameter property is only allowed in a constructor implementation. +tests/cases/compiler/readonlyInNonPropertyParameters.ts(5,8): error TS2369: A parameter property is only allowed in a constructor implementation. +tests/cases/compiler/readonlyInNonPropertyParameters.ts(7,2): error TS2369: A parameter property is only allowed in a constructor implementation. + + +==== tests/cases/compiler/readonlyInNonPropertyParameters.ts (3 errors) ==== + + // `readonly` won't work outside of property parameters + class X { + method(readonly x: number) {} + ~~~~~~~~~~~~~~~~~~ +!!! error TS2369: A parameter property is only allowed in a constructor implementation. + set x(readonly value: number) {} + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2369: A parameter property is only allowed in a constructor implementation. + } + (readonly x) => 0; + ~~~~~~~~~~ +!!! error TS2369: A parameter property is only allowed in a constructor implementation. \ No newline at end of file diff --git a/tests/baselines/reference/readonlyInNonPropertyParameters.js b/tests/baselines/reference/readonlyInNonPropertyParameters.js new file mode 100644 index 00000000000..484a726dc4d --- /dev/null +++ b/tests/baselines/reference/readonlyInNonPropertyParameters.js @@ -0,0 +1,23 @@ +//// [readonlyInNonPropertyParameters.ts] + +// `readonly` won't work outside of property parameters +class X { + method(readonly x: number) {} + set x(readonly value: number) {} +} +(readonly x) => 0; + +//// [readonlyInNonPropertyParameters.js] +// `readonly` won't work outside of property parameters +var X = (function () { + function X() { + } + X.prototype.method = function (x) { }; + Object.defineProperty(X.prototype, "x", { + set: function (value) { }, + enumerable: true, + configurable: true + }); + return X; +}()); +(function (x) { return 0; }); diff --git a/tests/cases/compiler/readonlyInNonPropertyParameters.ts b/tests/cases/compiler/readonlyInNonPropertyParameters.ts new file mode 100644 index 00000000000..7373d046e38 --- /dev/null +++ b/tests/cases/compiler/readonlyInNonPropertyParameters.ts @@ -0,0 +1,8 @@ +//@target: ES5 + +// `readonly` won't work outside of property parameters +class X { + method(readonly x: number) {} + set x(readonly value: number) {} +} +(readonly x) => 0; \ No newline at end of file