Skip to content

Commit 2a76af2

Browse files
author
Andy Hanson
committed
Remove duplicate check for misplaced parameter properties (taken care of by checkParameter)
1 parent 89a4b29 commit 2a76af2

6 files changed

+52
-14
lines changed

src/compiler/checker.ts

-3
Original file line numberDiff line numberDiff line change
@@ -18225,9 +18225,6 @@ namespace ts {
1822518225
if (parameter.dotDotDotToken) {
1822618226
return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.A_set_accessor_cannot_have_rest_parameter);
1822718227
}
18228-
else if (parameter.flags & NodeFlags.Modifier) {
18229-
return grammarErrorOnNode(accessor.name, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
18230-
}
1823118228
else if (parameter.questionToken) {
1823218229
return grammarErrorOnNode(parameter.questionToken, Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
1823318230
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
tests/cases/compiler/accessorParameterAccessibilityModifier.ts(3,9): error TS2369: A parameter property is only allowed in a constructor implementation.
21
tests/cases/compiler/accessorParameterAccessibilityModifier.ts(3,11): error TS2369: A parameter property is only allowed in a constructor implementation.
3-
tests/cases/compiler/accessorParameterAccessibilityModifier.ts(4,16): error TS2369: A parameter property is only allowed in a constructor implementation.
42
tests/cases/compiler/accessorParameterAccessibilityModifier.ts(4,18): error TS2369: A parameter property is only allowed in a constructor implementation.
53

64

7-
==== tests/cases/compiler/accessorParameterAccessibilityModifier.ts (4 errors) ====
5+
==== tests/cases/compiler/accessorParameterAccessibilityModifier.ts (2 errors) ====
86

97
class C {
108
set X(public v) { }
11-
~
12-
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
139
~~~~~~~~
1410
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
1511
static set X(public v2) { }
16-
~
17-
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
1812
~~~~~~~~~
1913
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
2014
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration15.ts(2,8): error TS2369: A parameter property is only allowed in a constructor implementation.
21
tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration15.ts(2,12): error TS2369: A parameter property is only allowed in a constructor implementation.
32

43

5-
==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration15.ts (2 errors) ====
4+
==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration15.ts (1 errors) ====
65
class C {
76
set Foo(public a: number) { }
8-
~~~
9-
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
107
~~~~~~~~~~~~~~~~
118
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
129
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
tests/cases/compiler/readonlyInNonPropertyParameters.ts(4,9): error TS2369: A parameter property is only allowed in a constructor implementation.
2+
tests/cases/compiler/readonlyInNonPropertyParameters.ts(5,8): error TS2369: A parameter property is only allowed in a constructor implementation.
3+
tests/cases/compiler/readonlyInNonPropertyParameters.ts(7,2): error TS2369: A parameter property is only allowed in a constructor implementation.
4+
5+
6+
==== tests/cases/compiler/readonlyInNonPropertyParameters.ts (3 errors) ====
7+
8+
// `readonly` won't work outside of property parameters
9+
class X {
10+
method(readonly x: number) {}
11+
~~~~~~~~~~~~~~~~~~
12+
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
13+
set x(readonly value: number) {}
14+
~~~~~~~~~~~~~~~~~~~~~~
15+
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
16+
}
17+
(readonly x) => 0;
18+
~~~~~~~~~~
19+
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [readonlyInNonPropertyParameters.ts]
2+
3+
// `readonly` won't work outside of property parameters
4+
class X {
5+
method(readonly x: number) {}
6+
set x(readonly value: number) {}
7+
}
8+
(readonly x) => 0;
9+
10+
//// [readonlyInNonPropertyParameters.js]
11+
// `readonly` won't work outside of property parameters
12+
var X = (function () {
13+
function X() {
14+
}
15+
X.prototype.method = function (x) { };
16+
Object.defineProperty(X.prototype, "x", {
17+
set: function (value) { },
18+
enumerable: true,
19+
configurable: true
20+
});
21+
return X;
22+
}());
23+
(function (x) { return 0; });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@target: ES5
2+
3+
// `readonly` won't work outside of property parameters
4+
class X {
5+
method(readonly x: number) {}
6+
set x(readonly value: number) {}
7+
}
8+
(readonly x) => 0;

0 commit comments

Comments
 (0)