Merge pull request #13599 from Microsoft/getFirstToken-returns-jsdoc

getFirstToken returns jsdoc as single comment
This commit is contained in:
Mohamed Hegazy
2017-01-20 17:01:02 -08:00
committed by GitHub
3 changed files with 21 additions and 4 deletions
+1 -1
View File
@@ -421,7 +421,7 @@
LastBinaryOperator = CaretEqualsToken,
FirstNode = QualifiedName,
FirstJSDocNode = JSDocTypeExpression,
LastJSDocNode = JSDocLiteralType,
LastJSDocNode = JSDocNeverKeyword,
FirstJSDocTagNode = JSDocComment,
LastJSDocTagNode = JSDocNeverKeyword
}
+14
View File
@@ -288,5 +288,19 @@ namespace ts {
*/`);
});
});
describe("getFirstToken", () => {
it("gets jsdoc", () => {
const first = ts.createSourceFile("foo.ts", "/** comment */var a = true;", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
assert.isDefined(first);
assert.equal(first.kind, 263);
});
});
describe("getLastToken", () => {
it("gets jsdoc", () => {
const last = ts.createSourceFile("foo.ts", "var a = true;/** comment */", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
assert.isDefined(last);
assert.equal(last.kind, 263);
});
});
});
}
+6 -3
View File
@@ -194,8 +194,9 @@ namespace ts {
}
const child = children[0];
return child.kind < SyntaxKind.FirstNode ? child : child.getFirstToken(sourceFile);
return child.kind < SyntaxKind.FirstNode || SyntaxKind.FirstJSDocNode <= child.kind && child.kind <= SyntaxKind.LastJSDocNode ?
child :
child.getFirstToken(sourceFile);
}
public getLastToken(sourceFile?: SourceFile): Node {
@@ -206,7 +207,9 @@ namespace ts {
return undefined;
}
return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile);
return child.kind < SyntaxKind.FirstNode || SyntaxKind.FirstJSDocNode <= child.kind && child.kind <= SyntaxKind.LastJSDocNode ?
child :
child.getLastToken(sourceFile);
}
}