API: add getChildren and token getters to Node - #63893
Open
Matheus Mol (oMatheusmol) wants to merge 3 commits into
Open
API: add getChildren and token getters to Node#63893Matheus Mol (oMatheusmol) wants to merge 3 commits into
Matheus Mol (oMatheusmol) wants to merge 3 commits into
Conversation
Adds the remaining child/token getters to the API: getChildren, getChildCount, getChildAt, getFirstToken, getLastToken.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds child and token navigation getters to the native TypeScript Node API.
Changes:
- Implements child/token materialization and caching.
- Adds getters to local and remote nodes via generators.
- Adds comprehensive AST navigation tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tools/scripts/tsc/generate-ts-ast.ts |
Generates local node getters. |
tools/scripts/tsc/generate-encoder.ts |
Generates remote node getters. |
packages/typescript/test/sync/ast.test.ts |
Tests child/token navigation. |
packages/typescript/src/ast/factory.generated.ts |
Adds generated local getters. |
packages/typescript/src/ast/astnav.ts |
Implements navigation and caching. |
packages/typescript/src/ast/ast.ts |
Extends the public node interfaces. |
packages/typescript/src/api/node/node.generated.ts |
Adds generated remote getters. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #63892
Adds the remaining child/token getters to the native API's
Node:getChildren(),getChildCount(),getChildAt(),getFirstToken()andgetLastToken().Context
This is a re-submission of a contribution originally made to the typescript-go repo. I previously contributed the position/text getters in microsoft/typescript-go#4308, and this follow-up (completing microsoft/typescript-go#4216) was submitted as microsoft/typescript-go#4440. That PR was closed when development moved back to this repository, and the maintainers asked contributors to re-open their PRs here — so here it is.
Compared to the original PR, the only changes are path remappings to this repo's layout (
_packages/native-preview/→packages/typescript/,_scripts/→tools/scripts/tsc/) and a rebase onto currentmain. It also incorporates the review feedback from the original PR (reusingshouldSkipChildinstead of duplicating the JSDoc predicate).Validation
npm run generatereproduces the generated files (node.generated.ts,factory.generated.ts) with no extra diffnpm run buildinpackages/typescriptpassesnpm testinpackages/typescript: 612 tests pass, 0 fail (includes the newgetChildren/token getter tests intest/sync/ast.test.ts)