Skip to content

Commit 131f759

Browse files
committed
Merge pull request #8930 from zhengbli/i8676
Run fixupParentReferences when parsing isolated jsDocComment
2 parents 24f15a4 + e2a1a78 commit 131f759

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/compiler/parser.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,14 @@ namespace ts {
440440

441441
/* @internal */
442442
export function parseIsolatedJSDocComment(content: string, start?: number, length?: number) {
443-
return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length);
443+
const result = Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length);
444+
if (result && result.jsDocComment) {
445+
// because the jsDocComment was parsed out of the source file, it might
446+
// not be covered by the fixupParentReferences.
447+
Parser.fixupParentReferences(result.jsDocComment);
448+
}
449+
450+
return result;
444451
}
445452

446453
/* @internal */
@@ -652,14 +659,14 @@ namespace ts {
652659
return node;
653660
}
654661

655-
export function fixupParentReferences(sourceFile: Node) {
662+
export function fixupParentReferences(rootNode: Node) {
656663
// normally parent references are set during binding. However, for clients that only need
657664
// a syntax tree, and no semantic features, then the binding process is an unnecessary
658665
// overhead. This functions allows us to set all the parents, without all the expense of
659666
// binding.
660667

661-
let parent: Node = sourceFile;
662-
forEachChild(sourceFile, visitNode);
668+
let parent: Node = rootNode;
669+
forEachChild(rootNode, visitNode);
663670
return;
664671

665672
function visitNode(n: Node): void {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
/////** @template T */
4+
////function ident<T>: T {
5+
////}
6+
7+
var c = classification;
8+
verify.syntacticClassificationsAre(
9+
c.comment("/** "),
10+
c.punctuation("@"),
11+
c.docCommentTagName("template"),
12+
c.typeParameterName("T"),
13+
c.comment(" */"),
14+
c.keyword("function"),
15+
c.identifier("ident"),
16+
c.punctuation("<"),
17+
c.typeParameterName("T"),
18+
c.punctuation(">"),
19+
c.punctuation(":"),
20+
c.identifier("T"),
21+
c.punctuation("{"),
22+
c.punctuation("}"));

0 commit comments

Comments
 (0)