mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 06:02:53 -05:00
Merge pull request #10407 from zhengbli/fixJsDocSyntacticClassification
Return non-JsDocComment children for syntactic classification
This commit is contained in:
@@ -301,6 +301,10 @@ namespace ts {
|
||||
return node.kind >= SyntaxKind.FirstJSDocNode && node.kind <= SyntaxKind.LastJSDocNode;
|
||||
}
|
||||
|
||||
export function isJSDocTag(node: Node) {
|
||||
return node.kind >= SyntaxKind.FirstJSDocTagNode && node.kind <= SyntaxKind.LastJSDocTagNode;
|
||||
}
|
||||
|
||||
export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFile): number {
|
||||
if (nodeIsMissing(node) || !node.decorators) {
|
||||
return getTokenPosOfNode(node, sourceFile);
|
||||
|
||||
@@ -299,6 +299,10 @@ namespace ts {
|
||||
processNode(jsDocComment);
|
||||
}
|
||||
}
|
||||
// For syntactic classifications, all trivia are classcified together, including jsdoc comments.
|
||||
// For that to work, the jsdoc comments should still be the leading trivia of the first child.
|
||||
// Restoring the scanner position ensures that.
|
||||
pos = this.pos;
|
||||
forEachChild(this, processNode, processNodes);
|
||||
if (pos < this.end) {
|
||||
this.addSyntheticNodes(children, pos, this.end);
|
||||
@@ -7596,6 +7600,10 @@ namespace ts {
|
||||
* False will mean that node is not classified and traverse routine should recurse into node contents.
|
||||
*/
|
||||
function tryClassifyNode(node: Node): boolean {
|
||||
if (isJSDocTag(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nodeIsMissing(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
24
tests/cases/fourslash/syntacticClassificationsDocComment4.ts
Normal file
24
tests/cases/fourslash/syntacticClassificationsDocComment4.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /** @param {number} p1 */
|
||||
//// function foo(p1) {}
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/** "),
|
||||
c.punctuation("@"),
|
||||
c.docCommentTagName("param"),
|
||||
c.comment(" "),
|
||||
c.punctuation("{"),
|
||||
c.keyword("number"),
|
||||
c.punctuation("}"),
|
||||
c.comment(" "),
|
||||
c.parameterName("p1"),
|
||||
c.comment(" */"),
|
||||
c.keyword("function"),
|
||||
c.identifier("foo"),
|
||||
c.punctuation("("),
|
||||
c.parameterName("p1"),
|
||||
c.punctuation(")"),
|
||||
c.punctuation("{"),
|
||||
c.punctuation("}"));
|
||||
Reference in New Issue
Block a user