fix(36247): disallow 'constructor' as a parameter property name (#37285)
This commit is contained in:
parent
878f447798
commit
66aa9e77bf
|
@ -28912,6 +28912,9 @@ namespace ts {
|
|||
if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) {
|
||||
error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
|
||||
}
|
||||
if (func.kind === SyntaxKind.Constructor && isIdentifier(node.name) && node.name.escapedText === "constructor") {
|
||||
error(node.name, Diagnostics.constructor_cannot_be_used_as_a_parameter_property_name);
|
||||
}
|
||||
}
|
||||
if (node.questionToken && isBindingPattern(node.name) && (func as FunctionLikeDeclaration).body) {
|
||||
error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
|
||||
|
|
|
@ -1569,6 +1569,10 @@
|
|||
"category": "Error",
|
||||
"code": 2397
|
||||
},
|
||||
"'constructor' cannot be used as a parameter property name.": {
|
||||
"category": "Error",
|
||||
"code": 2398
|
||||
},
|
||||
"Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference.": {
|
||||
"category": "Error",
|
||||
"code": 2399
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
tests/cases/compiler/parameterPropertyInConstructor3.ts(2,22): error TS2398: 'constructor' cannot be used as a parameter property name.
|
||||
|
||||
|
||||
==== tests/cases/compiler/parameterPropertyInConstructor3.ts (1 errors) ====
|
||||
class Foo {
|
||||
constructor(public constructor: string) {}
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2398: 'constructor' cannot be used as a parameter property name.
|
||||
}
|
||||
|
13
tests/baselines/reference/parameterPropertyInConstructor3.js
Normal file
13
tests/baselines/reference/parameterPropertyInConstructor3.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
//// [parameterPropertyInConstructor3.ts]
|
||||
class Foo {
|
||||
constructor(public constructor: string) {}
|
||||
}
|
||||
|
||||
|
||||
//// [parameterPropertyInConstructor3.js]
|
||||
var Foo = /** @class */ (function () {
|
||||
function Foo(constructor) {
|
||||
this.constructor = constructor;
|
||||
}
|
||||
return Foo;
|
||||
}());
|
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/parameterPropertyInConstructor3.ts ===
|
||||
class Foo {
|
||||
>Foo : Symbol(Foo, Decl(parameterPropertyInConstructor3.ts, 0, 0))
|
||||
|
||||
constructor(public constructor: string) {}
|
||||
>constructor : Symbol(Foo.constructor, Decl(parameterPropertyInConstructor3.ts, 1, 14))
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/parameterPropertyInConstructor3.ts ===
|
||||
class Foo {
|
||||
>Foo : Foo
|
||||
|
||||
constructor(public constructor: string) {}
|
||||
>constructor : string
|
||||
}
|
||||
|
3
tests/cases/compiler/parameterPropertyInConstructor3.ts
Normal file
3
tests/cases/compiler/parameterPropertyInConstructor3.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Foo {
|
||||
constructor(public constructor: string) {}
|
||||
}
|
Loading…
Reference in a new issue