feat(estree)!: make whether to include TS fields a runtime option#23574
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
|
There was a problem hiding this comment.
Pull request overview
This PR changes ESTree JSON serialization to make “include TypeScript fields” a runtime option instead of a compile-time split between separate JS-only vs TS serializers, aiming to reduce oxc_parser binary size at the cost of a few extra runtime branches.
Changes:
- Replace separate JS/TS serializer configs and
Program::{to_*_estree_{js,ts}_json*}APIs with unified methods that takeinclude_ts_fields: bool. - Update coverage tools, benchmarks, NAPI parser binding, and examples to call the new unified serialization APIs.
- Refactor
oxc_estreeserializer configs to storeinclude_ts_fieldsandrangesas runtime config fields.
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tasks/coverage/src/tools.rs | Switch coverage ESTree dumps to to_pretty_estree_json(include_ts_fields, ranges) calls. |
| tasks/coverage/src/driver.rs | Update coverage driver to call to_estree_json_with_fixes(true, false). |
| tasks/benchmark/benches/parser.rs | Update benchmark to use to_estree_json_with_fixes(true, false). |
| napi/parser/src/lib.rs | Use unified to_estree_json_with_fixes(include_ts_fields, ranges) and keep JS-only hashbang behavior. |
| crates/oxc_parser/examples/parser.rs | Use unified pretty serialization API based on source_type. |
| crates/oxc_estree/src/serialize/structs.rs | Update tests to use unified serializers (but one pretty-path test currently uses the wrong serializer type). |
| crates/oxc_estree/src/serialize/strings.rs | Update tests to use CompactSerializer. |
| crates/oxc_estree/src/serialize/sequences.rs | Update tests to use CompactSerializer / PrettySerializer. |
| crates/oxc_estree/src/serialize/primitives.rs | Update tests to use CompactSerializer. |
| crates/oxc_estree/src/serialize/mod.rs | Collapse JS/TS serializer type aliases into unified serializers; add include_ts_fields to constructor API. |
| crates/oxc_estree/src/serialize/config.rs | Replace separate JS/TS configs with runtime include_ts_fields + ranges fields for fixes/no-fixes configs. |
| crates/oxc_estree/src/serialize/blanket.rs | Update tests to use CompactSerializer. |
| crates/oxc_ast/src/serialize/mod.rs | Replace 8 JS/TS serialization entry points with 4 unified entry points that accept include_ts_fields. |
| crates/oxc_allocator/src/vec.rs | Update serialize tests to use CompactSerializer. |
| crates/oxc_allocator/src/boxed.rs | Update serialize tests to use CompactSerializer. |
88b88e0 to
4749b17
Compare
27f9d37 to
9b6bddc
Compare
9b6bddc to
7ee8a1a
Compare
4749b17 to
3373a77
Compare
7ee8a1a to
b4e4d75
Compare
3373a77 to
5f62541
Compare
Merge activity
|
…3574) Previously, whether to serialize AST to ESTree JSON with/without TS fields was a compile-time option - via 2 different configs `CompactTSSerializer` and `CompactJSSerializer` (and their pretty-printing and with-fixes counterparts). Turn this into a runtime option instead - This make serialization a little slower (more branches in either mode, and dead code in JS-only mode) but reduces the size of `oxc-parser` binary as only one `ESTreeSerializer` is generated, instead of 2 (JS-only, and with-TS).
Previously `Config` passed to ESTree serializers inclused `INCLUDE_TS_FIELDS` and `FIXES` consts. Allow these options to be set either as compile time or at runtime by instead implementing them as methods. This PR defines all these methods on all configs as returning static values, so it does not change behavior. Next PR (#23574) uses this to alter configs to make whether TS fields are included in output a runtime option instead of a compile time one.
5f62541 to
e7b6b68
Compare
b4e4d75 to
7a76cd3
Compare
### 💥 BREAKING CHANGES - 7a76cd3 estree: [**BREAKING**] Make whether to include TS fields a runtime option (#23574) (overlookmotel) - e7b6b68 estree: [**BREAKING**] `ESTree` config use methods not consts (#23573) (overlookmotel) ### 🚀 Features - 556cc6d data_structures: Add `CodeBuffer::as_str` method (#23571) (overlookmotel) - 38c4b06 parser: Add friendly error for adjacent JSX elements (#23378) (sapphi-red) - 53509a8 minifier: Treeshake pure typed arrays and Set/Map array literals (#23469) (Dunqing) - 09762d9 minifier: Inline const value for read-only vars (#22593) (Dunqing) ### 🐛 Bug Fixes - 20375f9 react_compiler: Keep imports referenced only by a computed key (#23586) (Boshen) - 31bfd9b minifier: Keep Object introspection calls on a possible Proxy (#23483) (Dunqing) - 837a395 parser: Treat a line comment after ':' as leading, not trailing (#23515) (Dunqing) - e409fe0 minifier: Keep `new Map`/`WeakSet`/`WeakMap` with a string argument (#23470) (Dunqing) - ae02b4e ci/parser: Use `minimal` for vitest reporter (#23457) (camc314) ### ⚡ Performance - cf24329 mangler: Compile slot sort once instead of per CAPACITY (#23577) (Boshen) - 4058a6a parser: Reduce code bloat from verify_modifiers monomorphization (#23576) (Boshen) - 053b0c1 estree: Remove pointless `mem::take` (#23572) (overlookmotel) - dfb52b6 transformer: Pre-size statement vecs in TS enum & namespace lowering (#23516) (Yunfei He) - 970e09a minifier: Compute template-literal inline checks in a single pass (#23467) (Yunfei He) - 3170c0e semantic,mangler,minifier: Fix `Semantic::stats` node count and reuse stats in mangler builds (#23352) (Boshen) - d1fa6e0 minifier: Evaluate ternary branches once in minimize_conditional_expression (#23479) (Yunfei He) - 3fa8051 transformer: Pre-size JSX props vec to attribute count (#23466) (Yunfei He) - 488b382 react_compiler: Borrow binding names in prefilter instead of allocating (#23471) (Yunfei He) - bcb3894 minifier: Incremental scoping refresh, delete LiveUsageCollector (#23197) (Dunqing) ### 📚 Documentation - f68641e data_structures: Improve docs on safety contract (#23575) (overlookmotel) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

Previously, whether to serialize AST to ESTree JSON with/without TS fields was a compile-time option - via 2 different configs
CompactTSSerializerandCompactJSSerializer(and their pretty-printing and with-fixes counterparts).Turn this into a runtime option instead.
This makes serialization a little slower (more branches in either mode, and dead code in JS-only mode) but reduces the size of
oxc-parserbinary as only oneESTreeSerializeris generated, instead of 2 (JS-only, and with-TS).