Skip to content

Commit 9d957c6

Browse files
authored
Fix getChildCount/At methods in EndOfFileTokens (microsoft#44991)
* Fix getChildCount/At methods in EndOfFileTokens Before, they were hardcoded to return `0` and `undefined!`, respectively, but that is inaccurate for `EndOfFileToken`s with attached jsdoc. * Add tests for getChild* methods on EndOfFileTokens
1 parent 42915c3 commit 9d957c6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/services/services.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,11 @@ namespace ts {
259259
}
260260

261261
public getChildCount(): number {
262-
return 0;
262+
return this.getChildren().length;
263263
}
264264

265-
public getChildAt(): Node {
266-
return undefined!; // TODO: GH#18217
265+
public getChildAt(index: number): Node {
266+
return this.getChildren()[index];
267267
}
268268

269269
public getChildren(): Node[] {

src/testRunner/unittests/publicApi.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,14 @@ var x
171171
});
172172
assert.equal(5, kids.length);
173173
});
174+
175+
describe("unittests:: Public APIs:: getChild* methods on EndOfFileToken with JSDoc", () => {
176+
const content = `
177+
/** jsdoc comment attached to EndOfFileToken */
178+
`;
179+
const sourceFile = ts.createSourceFile("/file.ts", content, ts.ScriptTarget.ESNext, /*setParentNodes*/ true);
180+
const endOfFileToken = sourceFile.getChildren()[1];
181+
assert.equal(endOfFileToken.getChildren().length, 1);
182+
assert.equal(endOfFileToken.getChildCount(), 1);
183+
assert.notEqual(endOfFileToken.getChildAt(0), /*expected*/ undefined);
184+
});

0 commit comments

Comments
 (0)