refactor: pass arrays to AST builder methods#10419
Conversation
How to use the Graphite Merge QueueAdd the label graphite: merge-when-ready to this PR to add it to 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. |
There was a problem hiding this comment.
Pull request overview
This PR continues the AST-construction refactor (follow-on after #10018) by leveraging oxc’s updated per-type AST constructors that accept array literals where an arena Vec was previously required, reducing boilerplate and improving readability at many call sites.
Changes:
- Replaces
oxc::allocator::Vec::{new_in, from_value_in, from_array_in}usages at constructor call sites with[]/[...]array literals where supported. - Simplifies construction of common AST nodes (calls, function bodies/params, object expressions, programs) across finalizers, HMR codegen, and plugins.
- Keeps existing arena-allocated
Vecusage where mutation/capacity management is still needed.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rolldown/src/utils/tweak_ast_for_scanning.rs | Uses [] / [...] when constructing export decls and call arguments during preprocessing rewrites. |
| crates/rolldown/src/module_finalizers/mod.rs | Replaces many arena Vec constructions with array literals in scope-hoisting finalizer AST generation. |
| crates/rolldown/src/module_finalizers/impl_visit_mut.rs | Simplifies ImportMeta rewrite to an empty object literal via new_object_expression(SPAN, [], ...). |
| crates/rolldown/src/hmr/utils.rs | Uses array literals for object properties and call arguments in HMR runtime registration AST. |
| crates/rolldown/src/hmr/impl_traverse_for_hmr_ast_finalizer.rs | Simplifies try/finally wrapper block/function construction using [] / [...]. |
| crates/rolldown/src/hmr/hmr_ast_finalizer.rs | Converts multiple call/sequence/function-body argument lists to array literals in HMR finalization logic. |
| crates/rolldown_plugin_vite_web_worker_post/src/ast_visitor.rs | Uses array literal for the single-property importMeta object expression. |
| crates/rolldown_plugin_vite_build_import_analysis/src/ast_utils.rs | Uses array literals for pattern properties and small single-item declaration lists. |
| crates/rolldown_plugin_lazy_compilation/src/runtime_injector.rs | Uses array literals for .then(...) args, formal params, and var decls in injected helper/function bodies. |
| crates/rolldown_ecmascript/src/ecma_compiler.rs | Builds a program from a parsed expression using [] / [...] for directives/comments/body. |
| crates/rolldown_ecmascript_utils/src/ast_factory.rs | Updates factory helpers to pass [] / [...] for params/bodies/args and keeps mutable arena Vec where needed. |
| crates/rolldown_common/src/ecmascript/json_to_program.rs | Builds a minimal program from JSON using array literals for directives/comments/body. |
Merging this PR will not alter performance
Comparing Footnotes
|
de7535b to
d5762eb
Compare
4e5b677 to
8e20bae
Compare
Merge activity
|
Follow-on after #10018. The new AST builder methods allow passing arrays where a `Vec` is required. Use this facility to remove a lot of repetitious boilerplate. Before: ```rust FunctionBody::new( SPAN, oxc::allocator::Vec::new_in(&self.ast_builder), oxc::allocator::Vec::from_value_in(try_stmt, &self.ast_builder), &self.ast_builder, ) ``` After: ```rust FunctionBody::new(SPAN, [], [try_stmt], &self.ast_builder) ``` Note: Like #10418, diff is quite large, but these changes were almost entirely produced using the same [deterministic codemod](https://github.com/oxc-project/oxc/tree/overlookmotel/ast-builder-codemod) we used to migrate Oxc repo to new AST builder, with only some final tweaks by an LLM. I've reviewed it all and, even though I'm unfamiliar with Rolldown's codebase, I'm pretty confident it looks correct.
8e20bae to
9886244
Compare
d5762eb to
4240c14
Compare

Follow-on after #10018.
The new AST builder methods allow passing arrays where a
Vecis required. Use this facility to remove a lot of repetitious boilerplate.Before:
After:
Note: Like #10418, diff is quite large, but these changes were almost entirely produced using the same deterministic codemod we used to migrate Oxc repo to new AST builder, with only some final tweaks by an LLM. I've reviewed it all and, even though I'm unfamiliar with Rolldown's codebase, I'm pretty confident it looks correct.