Catch illegal jsdoc tags on constructors (#20045)

This commit is contained in:
Andy 2017-11-21 21:36:08 -05:00 committed by GitHub
parent 739097a9ad
commit 013ce8e36d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 4 deletions

View file

@ -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);
}
}

View 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() {}
}

View 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() {}
}

View file

@ -0,0 +1,14 @@
=== /a.js ===
class C {
>C : C
/** @template T */
constructor() { }
}
class D {
>D : D
/** @return {number} */
constructor() {}
}

View file

@ -0,0 +1,13 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: /a.js
class C {
/** @template T */
constructor() { }
}
class D {
/** @return {number} */
constructor() {}
}