feat(napi/parser): add AST walker#13930
Merged
graphite-app[bot] merged 1 commit intomainfrom Sep 22, 2025
Merged
Conversation
Member
Author
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
d07fa71 to
1c50c58
Compare
a44ba52 to
f68cffb
Compare
1c50c58 to
098ac21
Compare
f68cffb to
f7f9e3a
Compare
098ac21 to
c2b060a
Compare
c2b060a to
4eb80fe
Compare
4eb80fe to
c8131c1
Compare
f7f9e3a to
b0abdfd
Compare
This was referenced Sep 20, 2025
c8131c1 to
da2c6f6
Compare
b0abdfd to
7091e82
Compare
da2c6f6 to
488d5b2
Compare
fe80787 to
2395e3a
Compare
0800b58 to
bfd6ca6
Compare
2395e3a to
2bd7aa7
Compare
Member
Author
Merge activity
|
Add an AST visitor to `oxc-parser`.
```js
import { parseSync, Visitor } from 'oxc-parser';
const { program } = parseSync('test.js', 'let x = { y: z };');
const idents = [];
const visitor = new Visitor({
Identifier(node) {
idents.push(node.name);
}
});
visitor.visit(program);
// Logs [ 'x', 'y', 'z' ]
console.log(idents);
```
Primarily we need a visitor for Oxlint plugins, but it's easier to develop and test in `oxc-parser`, so I thought I'd add it there first. Oxlint build process will copy the generated files for tree-walking from `napi/parser` dir, as it does with other files.
Notes:
* The `walk.mjs` file is large, so it's lazy-loaded only when user first constructs a `Visitor`. Adding `Visitor` to the package will not affect start-up time where user only uses `parseSync` etc.
* TS type definition for `Visitor` and the visitor object it takes are provided.
* Visitor supports enter and exit visitors e.g. `Program` and `Program:exit`.
* `src-js/visit/visitor.mjs` is copied from `apps/oxlint` with only minor modifications, and conversion from TS to JS. It'd be better if we only had this impl in one place, but that would require converting `oxc-parser` to TS and building with TSDown, like `oxlint` is. Leaving that for later - #13935.
2bd7aa7 to
4ee94a3
Compare
bfd6ca6 to
56a385f
Compare
Base automatically changed from
09-17-feat_napi_parser_export_visitor_keys
to
main
September 22, 2025 11:14
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.

Add an AST visitor to
oxc-parser.Primarily we need a visitor for Oxlint plugins, but it's easier to develop and test in
oxc-parser, so I thought I'd add it there first. Oxlint build process will copy the generated files for tree-walking fromnapi/parserdir, as it does with other files.Notes:
walk.mjsfile is large, so it's lazy-loaded only when user first constructs aVisitor. AddingVisitorto the package will not affect start-up time where user only usesparseSyncetc.Visitorand the visitor object it takes are provided.ProgramandProgram:exit.src-js/visit/visitor.mjsis copied fromapps/oxlintwith only minor modifications, and conversion from TS to JS. It'd be better if we only had this impl in one place, but that would require convertingoxc-parserto TS and building with TSDown, likeoxlintis. Leaving that for later - Convertoxc-parserto TypeScript #13935.