Skip to content

Commit 053b3cd

Browse files
committed
getFirstToken skips JSDoc
Fixes #13519. This is a better fix than #13599. Also fixes broken tests associated with #13599.
1 parent 3cf326a commit 053b3cd

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/harness/unittests/jsDocParsing.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,21 @@ namespace ts {
290290
});
291291
describe("getFirstToken", () => {
292292
it("gets jsdoc", () => {
293-
const first = ts.createSourceFile("foo.ts", "/** comment */var a = true;", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
293+
const root = ts.createSourceFile("foo.ts", "/** comment */var a = true;", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
294+
assert.isDefined(root);
295+
assert.equal(root.kind, ts.SyntaxKind.SourceFile);
296+
const first = root.getFirstToken();
294297
assert.isDefined(first);
295-
assert.equal(first.kind, 263);
298+
assert.equal(first.kind, ts.SyntaxKind.VarKeyword);
296299
});
297300
});
298301
describe("getLastToken", () => {
299302
it("gets jsdoc", () => {
300-
const last = ts.createSourceFile("foo.ts", "var a = true;/** comment */", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
303+
const root = ts.createSourceFile("foo.ts", "var a = true;/** comment */", ts.ScriptTarget.ES5, /*setParentNodes*/ true);
304+
assert.isDefined(root);
305+
const last = root.getLastToken();
301306
assert.isDefined(last);
302-
assert.equal(last.kind, 263);
307+
assert.equal(last.kind, ts.SyntaxKind.EndOfFileToken);
303308
});
304309
});
305310
});

src/services/services.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ namespace ts {
193193
return undefined;
194194
}
195195

196-
const child = children[0];
197-
return child.kind < SyntaxKind.FirstNode || SyntaxKind.FirstJSDocNode <= child.kind && child.kind <= SyntaxKind.LastJSDocNode ?
196+
const child = ts.find(children, kid => kid.kind < SyntaxKind.FirstJSDocNode || kid.kind > SyntaxKind.LastJSDocNode);
197+
return child.kind < SyntaxKind.FirstNode ?
198198
child :
199199
child.getFirstToken(sourceFile);
200200
}
@@ -207,9 +207,7 @@ namespace ts {
207207
return undefined;
208208
}
209209

210-
return child.kind < SyntaxKind.FirstNode || SyntaxKind.FirstJSDocNode <= child.kind && child.kind <= SyntaxKind.LastJSDocNode ?
211-
child :
212-
child.getLastToken(sourceFile);
210+
return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile);
213211
}
214212
}
215213

0 commit comments

Comments
 (0)