Skip to content

Fix getChildCount/At methods in EndOfFileTokens #44991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2021
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
6 changes: 3 additions & 3 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ namespace ts {
}

public getChildCount(): number {
return 0;
return this.getChildren().length;
}

public getChildAt(): Node {
return undefined!; // TODO: GH#18217
public getChildAt(index: number): Node {
Copy link

Choose a reason for hiding this comment

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

Should return Node | undefined?
TypeScript's codebase chould use the stricter tsconfig flags...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Theoretically, yes, but that's somewhat tangential to this PR

return this.getChildren()[index];
}

public getChildren(): Node[] {
Expand Down
11 changes: 11 additions & 0 deletions src/testRunner/unittests/publicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,14 @@ var x
});
assert.equal(5, kids.length);
});

describe("unittests:: Public APIs:: getChild* methods on EndOfFileToken with JSDoc", () => {
const content = `
/** jsdoc comment attached to EndOfFileToken */
`;
const sourceFile = ts.createSourceFile("/file.ts", content, ts.ScriptTarget.ESNext, /*setParentNodes*/ true);
const endOfFileToken = sourceFile.getChildren()[1];
assert.equal(endOfFileToken.getChildren().length, 1);
assert.equal(endOfFileToken.getChildCount(), 1);
assert.notEqual(endOfFileToken.getChildAt(0), /*expected*/ undefined);
});