Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
LastBinaryOperator = CaretEqualsToken,
FirstNode = QualifiedName,
FirstJSDocNode = JSDocTypeExpression,
LastJSDocNode = JSDocLiteralType,
LastJSDocNode = JSDocNeverKeyword,
FirstJSDocTagNode = JSDocComment,
LastJSDocTagNode = JSDocNeverKeyword
}
Expand Down
14 changes: 14 additions & 0 deletions src/harness/unittests/jsDocParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this not use ts.SyntaxKind?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. I grabbed 263 straight from the debugger. Nice catch. It looks like this issue needs some more attention (to fix getNextToken as well) so I'll correct this in the followup PR.

});
});
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);
});
});
});
}
9 changes: 6 additions & 3 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}

Expand Down