diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6f042627c6ba4..b24dd85f2f0dd 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -440,7 +440,14 @@ namespace ts { /* @internal */ export function parseIsolatedJSDocComment(content: string, start?: number, length?: number) { - return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length); + const result = Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length); + if (result && result.jsDocComment) { + // because the jsDocComment was parsed out of the source file, it might + // not be covered by the fixupParentReferences. + Parser.fixupParentReferences(result.jsDocComment); + } + + return result; } /* @internal */ @@ -652,14 +659,14 @@ namespace ts { return node; } - export function fixupParentReferences(sourceFile: Node) { + export function fixupParentReferences(rootNode: Node) { // normally parent references are set during binding. However, for clients that only need // a syntax tree, and no semantic features, then the binding process is an unnecessary // overhead. This functions allows us to set all the parents, without all the expense of // binding. - let parent: Node = sourceFile; - forEachChild(sourceFile, visitNode); + let parent: Node = rootNode; + forEachChild(rootNode, visitNode); return; function visitNode(n: Node): void { diff --git a/tests/cases/fourslash/syntacticClassificationForJSDocTemplateTag.ts b/tests/cases/fourslash/syntacticClassificationForJSDocTemplateTag.ts new file mode 100644 index 0000000000000..c3368207d2cc2 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationForJSDocTemplateTag.ts @@ -0,0 +1,22 @@ +/// + +/////** @template T */ +////function ident: T { +////} + +var c = classification; +verify.syntacticClassificationsAre( + c.comment("/** "), + c.punctuation("@"), + c.docCommentTagName("template"), + c.typeParameterName("T"), + c.comment(" */"), + c.keyword("function"), + c.identifier("ident"), + c.punctuation("<"), + c.typeParameterName("T"), + c.punctuation(">"), + c.punctuation(":"), + c.identifier("T"), + c.punctuation("{"), + c.punctuation("}"));