Skip to content

Commit d133b0e

Browse files
authored
Merge pull request microsoft#10407 from zhengbli/fixJsDocSyntacticClassification
Return non-JsDocComment children for syntactic classification
2 parents 6f722b0 + 6d2323b commit d133b0e

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ namespace ts {
301301
return node.kind >= SyntaxKind.FirstJSDocNode && node.kind <= SyntaxKind.LastJSDocNode;
302302
}
303303

304+
export function isJSDocTag(node: Node) {
305+
return node.kind >= SyntaxKind.FirstJSDocTagNode && node.kind <= SyntaxKind.LastJSDocTagNode;
306+
}
307+
304308
export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFile): number {
305309
if (nodeIsMissing(node) || !node.decorators) {
306310
return getTokenPosOfNode(node, sourceFile);

src/services/services.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ namespace ts {
299299
processNode(jsDocComment);
300300
}
301301
}
302+
// For syntactic classifications, all trivia are classcified together, including jsdoc comments.
303+
// For that to work, the jsdoc comments should still be the leading trivia of the first child.
304+
// Restoring the scanner position ensures that.
305+
pos = this.pos;
302306
forEachChild(this, processNode, processNodes);
303307
if (pos < this.end) {
304308
this.addSyntheticNodes(children, pos, this.end);
@@ -7596,6 +7600,10 @@ namespace ts {
75967600
* False will mean that node is not classified and traverse routine should recurse into node contents.
75977601
*/
75987602
function tryClassifyNode(node: Node): boolean {
7603+
if (isJSDocTag(node)) {
7604+
return true;
7605+
}
7606+
75997607
if (nodeIsMissing(node)) {
76007608
return true;
76017609
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// /** @param {number} p1 */
4+
//// function foo(p1) {}
5+
6+
var c = classification;
7+
verify.syntacticClassificationsAre(
8+
c.comment("/** "),
9+
c.punctuation("@"),
10+
c.docCommentTagName("param"),
11+
c.comment(" "),
12+
c.punctuation("{"),
13+
c.keyword("number"),
14+
c.punctuation("}"),
15+
c.comment(" "),
16+
c.parameterName("p1"),
17+
c.comment(" */"),
18+
c.keyword("function"),
19+
c.identifier("foo"),
20+
c.punctuation("("),
21+
c.parameterName("p1"),
22+
c.punctuation(")"),
23+
c.punctuation("{"),
24+
c.punctuation("}"));

0 commit comments

Comments
 (0)