Skip to content

Commit

Permalink
Merge pull request #13645 from Microsoft/getFirstToken-skips-jsdoc
Browse files Browse the repository at this point in the history
getFirstToken skips JSDoc
  • Loading branch information
sandersn authored Jan 24, 2017
2 parents 4888e4f + 053b3cd commit c1181ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/harness/unittests/jsDocParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,21 @@ namespace ts {
});
describe("getFirstToken", () => {
it("gets jsdoc", () => {
const first = ts.createSourceFile("foo.ts", "/** comment */var a = true;", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
const root = ts.createSourceFile("foo.ts", "/** comment */var a = true;", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
assert.isDefined(root);
assert.equal(root.kind, ts.SyntaxKind.SourceFile);
const first = root.getFirstToken();
assert.isDefined(first);
assert.equal(first.kind, 263);
assert.equal(first.kind, ts.SyntaxKind.VarKeyword);
});
});
describe("getLastToken", () => {
it("gets jsdoc", () => {
const last = ts.createSourceFile("foo.ts", "var a = true;/** comment */", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
const root = ts.createSourceFile("foo.ts", "var a = true;/** comment */", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
assert.isDefined(root);
const last = root.getLastToken();
assert.isDefined(last);
assert.equal(last.kind, 263);
assert.equal(last.kind, ts.SyntaxKind.EndOfFileToken);
});
});
});
Expand Down
8 changes: 3 additions & 5 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ namespace ts {
return undefined;
}

const child = children[0];
return child.kind < SyntaxKind.FirstNode || SyntaxKind.FirstJSDocNode <= child.kind && child.kind <= SyntaxKind.LastJSDocNode ?
const child = ts.find(children, kid => kid.kind < SyntaxKind.FirstJSDocNode || kid.kind > SyntaxKind.LastJSDocNode);
return child.kind < SyntaxKind.FirstNode ?
child :
child.getFirstToken(sourceFile);
}
Expand All @@ -207,9 +207,7 @@ namespace ts {
return undefined;
}

return child.kind < SyntaxKind.FirstNode || SyntaxKind.FirstJSDocNode <= child.kind && child.kind <= SyntaxKind.LastJSDocNode ?
child :
child.getLastToken(sourceFile);
return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile);
}
}

Expand Down

0 comments on commit c1181ae

Please sign in to comment.