Check for missing type parameter names in JSDoc template tags (#42017)

* Check for missing type parameter names in JSDoc template tags

Fixes #36692

* Update baselines
This commit is contained in:
Ryan Cavanaugh
2021-02-17 16:54:56 -08:00
committed by GitHub
parent 412ecbc291
commit f5618562ab
3 changed files with 12 additions and 2 deletions

View File

@@ -8043,6 +8043,9 @@ namespace ts {
function parseTemplateTagTypeParameter() {
const typeParameterPos = getNodePos();
const name = parseJSDocIdentifierName(Diagnostics.Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces);
if (nodeIsMissing(name)) {
return undefined;
}
return finishNode(factory.createTypeParameterDeclaration(name, /*constraint*/ undefined, /*defaultType*/ undefined), typeParameterPos);
}
@@ -8051,7 +8054,10 @@ namespace ts {
const typeParameters = [];
do {
skipWhitespace();
typeParameters.push(parseTemplateTagTypeParameter());
const node = parseTemplateTagTypeParameter();
if (node !== undefined) {
typeParameters.push(node);
}
skipWhitespaceOrAsterisk();
} while (parseOptionalJsdoc(SyntaxKind.CommaToken));
return createNodeArray(typeParameters, pos);

View File

@@ -382,5 +382,9 @@ namespace ts {
const root = createSourceFile("foo.ts", "/** */var a = true;", ScriptTarget.ES5, /*setParentNodes*/ false);
root.statements[0].getStart(root, /*includeJsdocComment*/ true);
});
describe("missing type parameter in jsDoc doesn't create a 1-element array", () => {
const doc = parseIsolatedJSDocComment("/**\n @template\n*/");
assert.equal((doc?.jsDoc.tags?.[0] as JSDocTemplateTag).typeParameters.length, 0);
});
});
}

View File

@@ -89,7 +89,7 @@ f({ a: 12 }, undefined, undefined, 101, 'nope');
* @param {T} x
*/
function g(x) { }
>g : <(Missing) extends any, T>(x: T) => void
>g : <T>(x: T) => void
>x : T