Merge pull request #10407 from zhengbli/fixJsDocSyntacticClassification

Return non-JsDocComment children for syntactic classification
This commit is contained in:
Mohamed Hegazy
2016-08-22 16:06:48 -07:00
committed by GitHub
3 changed files with 36 additions and 0 deletions

View File

@@ -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);

View File

@@ -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;
}

View 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("}"));