refactor(parser): switch parser to new AstBuilder#23730
Conversation
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. |
Merging this PR will not alter performance
Comparing Footnotes
|
de11062 to
e769418
Compare
27489b3 to
e512626
Compare
e512626 to
c5d5217
Compare
e769418 to
16f04a9
Compare
c5d5217 to
6b2bb22
Compare
16f04a9 to
53147e2
Compare
53147e2 to
6afe9e0
Compare
6b2bb22 to
431ba1e
Compare
431ba1e to
dd42174
Compare
6afe9e0 to
36eb2c7
Compare
36eb2c7 to
e8278a2
Compare
dd42174 to
5ef81a0
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates oxc_parser to the new AST builder API (builder methods on AST types + GetAstBuilder), aligning the parser with the ongoing AstBuilder redesign in #23043 and reducing reliance on the legacy self.ast.* constructor surface.
Changes:
- Switch parser AST construction from
self.ast.*methods to*_::new(...)/*_::boxed(...)builder methods across JS/TS/JSX parsing paths. - Update allocation patterns to use
ArenaVec::{new_in, with_capacity_in, from_value_in}andArenaBox::new_in(...)viaGetAllocator. - Wire
ParserImplinto the new builder system by implementingGetAstBuilder, and enableoxc_ast’sbuilder_newfeature.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_parser/src/ts/types.rs | Convert TS type node construction to TSType::*/TS*::new/boxed builder methods and arena vec helpers. |
| crates/oxc_parser/src/ts/statement.rs | Convert TS statement/declaration parsing to new builder methods and arena vec allocation helpers. |
| crates/oxc_parser/src/lib.rs | Import new builder traits/types, construct Program via Program::new, update alloc, and implement GetAstBuilder for ParserImpl. |
| crates/oxc_parser/src/jsx/mod.rs | Convert JSX node creation to JSX*::new/boxed methods and arena vec helpers. |
| crates/oxc_parser/src/js/statement.rs | Convert statement node creation (and directive/hashbang) to new builder methods and arena vec helpers. |
| crates/oxc_parser/src/js/object.rs | Convert object expression/property construction to new builder methods; update shorthand/init tracking construction sites. |
| crates/oxc_parser/src/js/module.rs | Convert import/export/module AST construction to new builder methods and arena vec helpers. |
| crates/oxc_parser/src/js/grammar.rs | Update cover grammar conversions to new builder methods; replace p.ast.vec() with ArenaVec::new_in(p). |
| crates/oxc_parser/src/js/function.rs | Convert function body/params/function nodes and yield expression construction to new builder methods. |
| crates/oxc_parser/src/js/expression.rs | Convert expression node creation to new builder methods; update arena vec helpers and Str::from_in usage. |
| crates/oxc_parser/src/js/declaration.rs | Convert variable declaration/declarator construction and list allocations to new builder methods. |
| crates/oxc_parser/src/js/class.rs | Convert class/class-body/heritage/method/property element construction to new builder methods and arena vec helpers. |
| crates/oxc_parser/src/js/binding.rs | Convert binding patterns/rest elements/properties/assignment patterns to new builder methods. |
| crates/oxc_parser/src/js/arrow.rs | Convert arrow function construction (params/body/expression) to new builder methods and arena vec helpers. |
| crates/oxc_parser/src/cursor.rs | Replace builder vec creation with ArenaVec::new_in(self) in list parsing helpers. |
| crates/oxc_parser/Cargo.toml | Enable oxc_ast feature builder_new for the parser crate. |
e8278a2 to
858a6ba
Compare
5ef81a0 to
1e4a339
Compare
858a6ba to
17a0f9e
Compare
|
@camc314 @Dunqing I think this is ready to go now. Please could you take a look and see if you think it's OK? The thing I'm not entirely happy with is that it makes code more verbose (especially I did try a macro, which is shorter syntax, but I felt it was a bit "mysterious":
If we all think we should move forwards with this, I think we can merge, and I'll transition all the other crates over in separate PRs. |
camc314
left a comment
There was a problem hiding this comment.
nice work! looks good to me!
I'm happy to work on this for the linter - would be helpful to get used to the new API. but if me working on that will slow you down, please go ahead! |
Thanks! That would be a great help. By all means try the codemod and see how far it gets. We might need to convert some other Then again, the linter doesn't use I noticed a pattern in linter where it creates an But all that said, let's wait for Dunqing to have a look and see if he's happy with this before we go any further. |
Merge activity
|
Part of #23043. Switch over `oxc_parser` to use the new `AstBuilder` and builder methods on AST types themselves. Vast majority performed by an ast-grep codemod generated by Claude (2nd commit - [codemod here](https://github.com/oxc-project/oxc/tree/overlookmotel/ast-builder-codemod)). The last 2 commits are a few small fixes, and some manual changes to shorten code.
1e4a339 to
785461b
Compare
17a0f9e to
981a952
Compare
Part of #23043. Switch over `oxc_parser` to use the new `AstBuilder` and builder methods on AST types themselves. Vast majority performed by an ast-grep codemod generated by Claude (2nd commit - [codemod here](https://github.com/oxc-project/oxc/tree/overlookmotel/ast-builder-codemod)). The last 2 commits are a few small fixes, and some manual changes to shorten code.

Part of #23043.
Switch over
oxc_parserto use the newAstBuilderand builder methods on AST types themselves.Vast majority performed by an ast-grep codemod generated by Claude (2nd commit - codemod here).
The last 2 commits are a few small fixes, and some manual changes to shorten code.