Catch illegal jsdoc tags on constructors (#20045)
This commit is contained in:
parent
739097a9ad
commit
013ce8e36d
|
@ -26248,14 +26248,17 @@ namespace ts {
|
|||
}
|
||||
|
||||
function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
|
||||
if (node.typeParameters) {
|
||||
return grammarErrorAtPos(node, node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
|
||||
const typeParameters = getEffectiveTypeParameterDeclarations(node);
|
||||
if (typeParameters) {
|
||||
const { pos, end } = isNodeArray(typeParameters) ? typeParameters : first(typeParameters);
|
||||
return grammarErrorAtPos(node, pos, end - pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarConstructorTypeAnnotation(node: ConstructorDeclaration) {
|
||||
if (node.type) {
|
||||
return grammarErrorOnNode(node.type, Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
|
||||
const type = getEffectiveReturnTypeNode(node);
|
||||
if (type) {
|
||||
return grammarErrorOnNode(type, Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
tests/baselines/reference/jsdocIllegalTags.errors.txt
Normal file
18
tests/baselines/reference/jsdocIllegalTags.errors.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
/a.js(2,19): error TS1092: Type parameters cannot appear on a constructor declaration.
|
||||
/a.js(6,18): error TS1093: Type annotation cannot appear on a constructor declaration.
|
||||
|
||||
|
||||
==== /a.js (2 errors) ====
|
||||
class C {
|
||||
/** @template T */
|
||||
~
|
||||
!!! error TS1092: Type parameters cannot appear on a constructor declaration.
|
||||
constructor() { }
|
||||
}
|
||||
class D {
|
||||
/** @return {number} */
|
||||
~~~~~~
|
||||
!!! error TS1093: Type annotation cannot appear on a constructor declaration.
|
||||
constructor() {}
|
||||
}
|
||||
|
14
tests/baselines/reference/jsdocIllegalTags.symbols
Normal file
14
tests/baselines/reference/jsdocIllegalTags.symbols
Normal file
|
@ -0,0 +1,14 @@
|
|||
=== /a.js ===
|
||||
class C {
|
||||
>C : Symbol(C, Decl(a.js, 0, 0))
|
||||
|
||||
/** @template T */
|
||||
constructor() { }
|
||||
}
|
||||
class D {
|
||||
>D : Symbol(D, Decl(a.js, 3, 1))
|
||||
|
||||
/** @return {number} */
|
||||
constructor() {}
|
||||
}
|
||||
|
14
tests/baselines/reference/jsdocIllegalTags.types
Normal file
14
tests/baselines/reference/jsdocIllegalTags.types
Normal file
|
@ -0,0 +1,14 @@
|
|||
=== /a.js ===
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
/** @template T */
|
||||
constructor() { }
|
||||
}
|
||||
class D {
|
||||
>D : D
|
||||
|
||||
/** @return {number} */
|
||||
constructor() {}
|
||||
}
|
||||
|
13
tests/cases/compiler/jsdocIllegalTags.ts
Normal file
13
tests/cases/compiler/jsdocIllegalTags.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @Filename: /a.js
|
||||
|
||||
class C {
|
||||
/** @template T */
|
||||
constructor() { }
|
||||
}
|
||||
class D {
|
||||
/** @return {number} */
|
||||
constructor() {}
|
||||
}
|
Loading…
Reference in a new issue