mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Merge pull request #48954 from a-tarasyuk/fix/48948
fix(48948): constructor can't be the name of class accessors and generators
This commit is contained in:
commit
0414deeaaf
@ -35389,6 +35389,10 @@ namespace ts {
|
||||
// Grammar checking
|
||||
if (!checkGrammarMethod(node)) checkGrammarComputedPropertyName(node.name);
|
||||
|
||||
if (isMethodDeclaration(node) && node.asteriskToken && isIdentifier(node.name) && idText(node.name) === "constructor") {
|
||||
error(node.name, Diagnostics.Class_constructor_may_not_be_a_generator);
|
||||
}
|
||||
|
||||
// Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration
|
||||
checkFunctionOrMethodDeclaration(node);
|
||||
|
||||
@ -35541,6 +35545,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkAccessorDeclaration(node: AccessorDeclaration) {
|
||||
if (isIdentifier(node.name) && idText(node.name) === "constructor") {
|
||||
error(node.name, Diagnostics.Class_constructor_may_not_be_an_accessor);
|
||||
}
|
||||
addLazyDiagnostic(checkAccessorDeclarationDiagnostics);
|
||||
checkSourceElement(node.body);
|
||||
setNodeLinksForPrivateIdentifierScope(node);
|
||||
|
||||
@ -1020,6 +1020,10 @@
|
||||
"category": "Error",
|
||||
"code": 1340
|
||||
},
|
||||
"Class constructor may not be an accessor.": {
|
||||
"category": "Error",
|
||||
"code": 1341
|
||||
},
|
||||
"Type arguments cannot be used here.": {
|
||||
"category": "Error",
|
||||
"code": 1342
|
||||
@ -1092,6 +1096,10 @@
|
||||
"category": "Error",
|
||||
"code": 1359
|
||||
},
|
||||
"Class constructor may not be a generator.": {
|
||||
"category": "Error",
|
||||
"code": 1360
|
||||
},
|
||||
"'{0}' cannot be used as a value because it was imported using 'import type'.": {
|
||||
"category": "Error",
|
||||
"code": 1361
|
||||
|
||||
@ -966,6 +966,8 @@ namespace ts {
|
||||
Diagnostics.extends_clause_already_seen.code,
|
||||
Diagnostics.let_declarations_can_only_be_declared_inside_a_block.code,
|
||||
Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations.code,
|
||||
Diagnostics.Class_constructor_may_not_be_a_generator.code,
|
||||
Diagnostics.Class_constructor_may_not_be_an_accessor.code,
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
tests/cases/conformance/salsa/constructorNameInAccessor.ts(2,9): error TS1341: Class constructor may not be an accessor.
|
||||
tests/cases/conformance/salsa/constructorNameInAccessor.ts(3,9): error TS1341: Class constructor may not be an accessor.
|
||||
|
||||
|
||||
==== tests/cases/conformance/salsa/constructorNameInAccessor.ts (2 errors) ====
|
||||
class C1 {
|
||||
get constructor() { return }
|
||||
~~~~~~~~~~~
|
||||
!!! error TS1341: Class constructor may not be an accessor.
|
||||
set constructor(value) {}
|
||||
~~~~~~~~~~~
|
||||
!!! error TS1341: Class constructor may not be an accessor.
|
||||
}
|
||||
|
||||
12
tests/baselines/reference/constructorNameInAccessor.js
Normal file
12
tests/baselines/reference/constructorNameInAccessor.js
Normal file
@ -0,0 +1,12 @@
|
||||
//// [constructorNameInAccessor.ts]
|
||||
class C1 {
|
||||
get constructor() { return }
|
||||
set constructor(value) {}
|
||||
}
|
||||
|
||||
|
||||
//// [constructorNameInAccessor.js]
|
||||
class C1 {
|
||||
get constructor() { return; }
|
||||
set constructor(value) { }
|
||||
}
|
||||
12
tests/baselines/reference/constructorNameInAccessor.symbols
Normal file
12
tests/baselines/reference/constructorNameInAccessor.symbols
Normal file
@ -0,0 +1,12 @@
|
||||
=== tests/cases/conformance/salsa/constructorNameInAccessor.ts ===
|
||||
class C1 {
|
||||
>C1 : Symbol(C1, Decl(constructorNameInAccessor.ts, 0, 0))
|
||||
|
||||
get constructor() { return }
|
||||
>constructor : Symbol(C1.constructor, Decl(constructorNameInAccessor.ts, 0, 10), Decl(constructorNameInAccessor.ts, 1, 32))
|
||||
|
||||
set constructor(value) {}
|
||||
>constructor : Symbol(C1.constructor, Decl(constructorNameInAccessor.ts, 0, 10), Decl(constructorNameInAccessor.ts, 1, 32))
|
||||
>value : Symbol(value, Decl(constructorNameInAccessor.ts, 2, 20))
|
||||
}
|
||||
|
||||
12
tests/baselines/reference/constructorNameInAccessor.types
Normal file
12
tests/baselines/reference/constructorNameInAccessor.types
Normal file
@ -0,0 +1,12 @@
|
||||
=== tests/cases/conformance/salsa/constructorNameInAccessor.ts ===
|
||||
class C1 {
|
||||
>C1 : C1
|
||||
|
||||
get constructor() { return }
|
||||
>constructor : void
|
||||
|
||||
set constructor(value) {}
|
||||
>constructor : void
|
||||
>value : void
|
||||
}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
tests/cases/conformance/salsa/constructorNameInGenerator.ts(2,6): error TS1360: Class constructor may not be a generator.
|
||||
|
||||
|
||||
==== tests/cases/conformance/salsa/constructorNameInGenerator.ts (1 errors) ====
|
||||
class C2 {
|
||||
*constructor() {}
|
||||
~~~~~~~~~~~
|
||||
!!! error TS1360: Class constructor may not be a generator.
|
||||
}
|
||||
|
||||
10
tests/baselines/reference/constructorNameInGenerator.js
Normal file
10
tests/baselines/reference/constructorNameInGenerator.js
Normal file
@ -0,0 +1,10 @@
|
||||
//// [constructorNameInGenerator.ts]
|
||||
class C2 {
|
||||
*constructor() {}
|
||||
}
|
||||
|
||||
|
||||
//// [constructorNameInGenerator.js]
|
||||
class C2 {
|
||||
*constructor() { }
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
=== tests/cases/conformance/salsa/constructorNameInGenerator.ts ===
|
||||
class C2 {
|
||||
>C2 : Symbol(C2, Decl(constructorNameInGenerator.ts, 0, 0))
|
||||
|
||||
*constructor() {}
|
||||
>constructor : Symbol(C2.constructor, Decl(constructorNameInGenerator.ts, 0, 10))
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
=== tests/cases/conformance/salsa/constructorNameInGenerator.ts ===
|
||||
class C2 {
|
||||
>C2 : C2
|
||||
|
||||
*constructor() {}
|
||||
>constructor : () => Generator<never, void, unknown>
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
// @target: esnext
|
||||
class C1 {
|
||||
get constructor() { return }
|
||||
set constructor(value) {}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
// @target: esnext
|
||||
class C2 {
|
||||
*constructor() {}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user