Commit Graph

86 Commits

Author SHA1 Message Date
Boshen baf022d74d refactor(ast)!: remove old AstBuilder methods (#24563)
Closes the migration tracked in #23043.

The new builder API (methods on the AST types themselves) has been in place for a while, all Oxc crates are migrated, and every crate which uses `AstBuilder` already enables `disable_old_builder` in its tests. The module docs said "after a few weeks, we will remove `AstBuilder`'s own methods entirely" — this does that.

## What's removed

- `crates/oxc_ast/src/generated/ast_builder.rs` and `builder/methods.rs` — `AstBuilder`'s own node and primitive constructors.
- `AstBuilderGenerator`, which produced the former.
- The `disable_old_builder` Cargo feature, plus the dev-dependency hacks it required across 33 manifests. Eight crates depended on `oxc_ast` *purely* to turn the feature on; those deps and their `cargo-shear` ignore entries are gone too.

## One thing worth reviewing

`AstBuilderGenerator` owned the `#[builder(default)]` / `#[builder(skip)]` attr registration that `BuilderMethodsGenerator` only *reads* — its doc comment said as much. Deleting it naively would have silently dropped `skip`/`default` handling for the 12 AST types using those attrs, so `attrs()` and `parse_attr()` move to `BuilderMethodsGenerator`.

The evidence this was faithful: after regenerating, `builder_methods.rs` and every other generated file are **byte-identical**. The only generated change in the diff is the deletion.

## Breaking changes

- `AstBuilder`'s own methods are gone. Use the AST type methods: `Statement::new_expression_statement(span, expr, &builder)` instead of `builder.statement_expression(span, expr)`.
- `AstBuilder` is no longer `Copy`/`Clone`, and its `allocator` field is private — use the `allocator` method from `GetAllocator`.
- `AstBuilder` and `NONE` are no longer re-exported from the crate root; import them from `oxc_ast::builder`. (The `disable_old_builder` feature already gated these off, so nothing in-tree used the root path.)
- The `disable_old_builder` feature no longer exists — remove it from any manifest that sets it.

A migration note covering all of the above is in `crates/oxc_ast/src/builder/mod.rs`.

---

Implemented with AI assistance (Claude Code); design, review, and verification driven by the author per the repo AI-usage policy.
2026-07-21 15:22:46 +00:00
overlookmotel 85a6853e0b fix(tasks): enable disable_old_builder Cargo feature for oxc_ast crate for all tasks (#23885)
Part of #23043.

We don't enable `oxc_ast`'s `disable_old_builder` Cargo feature in any of our published crates, or crates that are depended on by published crates.

Tasks are private to the repo, so enable this feature on them, to ensure no usage of legacy `AstBuilder` methods sneak in during the transition period before we delete these methods.
2026-06-28 12:13:17 +00:00
Boshen 9e19b9b539 refactor(benchmark): drive pipeline benchmark through oxc Compiler interface (#23154)
Rework the pipeline benchmark to run the full compilation through the
`oxc` root crate's `Compiler`/`CompilerInterface` instead of hand-wiring
each `oxc_*` stage.

- A `PipelineCompiler` implements `CompilerInterface`, overriding the
option hooks with common options:
  - **transform**: `esnext` target
  - **define**: `process.env.NODE_ENV` → `'production'`
  - **inject**: `Buffer` from `node:buffer`
- **compress**: `CompressOptions::smallest()`, plus default mangle and
codegen
- The bench body just calls `compiler.compile(...)`, so parse → semantic
→ transform → define → inject → minify → mangle → codegen is driven by
the interface.
- `Cargo.toml`: added `oxc` (with `full` feature) to the `compiler`
feature and to `cargo-shear` ignored list.

The CI matrix maps the `pipeline` component to the `compiler` feature,
which now includes `oxc`, so no workflow changes are needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-06-09 22:11:25 +08:00
Boshen b846ab2d9a feat(react_compiler): integrate the Rust port of the React Compiler (#22942)
Closes https://github.com/oxc-project/oxc/issues/10048

Integrates the Rust port of the React Compiler ([facebook/react#36173](https://github.com/facebook/react/pull/36173)) into oxc.

## Notes (resolved)

- Published crates can't reference Git URLs, so using this from Rolldown needs the React Compiler crates on crates.io. ✅ Published as a fork at https://crates.io/crates/forked_react_compiler; this PR depends on those `forked_react_compiler*` crates so people can get earlier access.
- The React Compiler crates had no license field. ✅ The published fork carries `license = "MIT"` (per the React repo's MIT license), so Cargo Deny and Security Analysis pass.

## Benchmark

**Wall-clock overhead vs plain transform** (release `transformSync`, same `jsx: automatic`, toggling only `reactCompiler`):

| fixture | without | with | overhead |
| --- | --- | --- | --- |
| RadixUIAdoptionSection.jsx (2.5 KiB) | 0.03 ms | 1.81 ms | +1.8 ms |
| excalidraw `App.tsx` (406 KiB) | 4.09 ms | 14.49 ms | +10.4 ms (3.5×) |

So roughly a fixed ~1.8 ms floor per file plus a per-size cost — about **3.5× the transform time** on a large real-world component.

## Binary size

Linking the React Compiler pulls the whole compiler pipeline (HIR, lowering, inference, SSA, optimization, reactive scopes, validation) plus the oxc⇄Babel AST conversion into the binding. Release build of the napi transform addon (`transform.darwin-arm64.node`, `--release`, stripped), darwin-arm64:

| build | size |
| --- | --- |
| baseline (`main`) | 3.51 MiB |
| with React Compiler | 8.66 MiB |
| **delta** | **+5.14 MiB (+146%, 2.46×)** |
2026-06-08 13:32:56 +00:00
overlookmotel c9642b48c0 fix(tools): fix cargo-shear warning in benchmarks (#19864)
`cargo-shear` is giving warnings on `tasks/benchmark`. Fix that.
2026-03-01 08:20:52 +00:00
overlookmotel d6f8b9f999 ci(benchmarks): benchmark parser with tokens and ESTree tokens conversion (#19649)
Add benchmarks for:

1. Parsing with tokens.
2. Serializing tokens to ESTree-style JSON.

Neither of these benchmarks needs to be kept indefinitely, but they'll be useful while working on the tokens code. There's a lot of room for optimization.
2026-02-24 11:31:05 +00:00
Boshen dcc4be8259 feat(benchmark): add pipeline benchmark for full compilation flow (#18484) 2026-01-24 22:13:14 +08:00
Boshen e031056b2f feat(codegen): add sourcemap feature flag (#17305)
Oxlint uses `oxc_codegen` for fixes, but do not require sourcemap.
2025-12-23 10:28:49 +00:00
renovate 6cf7173c29 chore(deps): update dependency oxfmt to ^0.20.0 (#17263)
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Adoption](https://docs.renovatebot.com/merge-confidence/) | [Passing](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|---|---|
| [oxfmt](https://oxc.rs) ([source](https://redirect.github.com/oxc-project/oxc/tree/HEAD/npm/oxfmt)) | [`^0.19.0` -> `^0.20.0`](https://renovatebot.com/diffs/npm/oxfmt/0.19.0/0.20.0) | ![age](https://developer.mend.io/api/mc/badges/age/npm/oxfmt/0.20.0?slim=true) | ![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/oxfmt/0.20.0?slim=true) | ![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/oxfmt/0.19.0/0.20.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/oxfmt/0.19.0/0.20.0?slim=true) |

---

### Release Notes

<details>
<summary>oxc-project/oxc (oxfmt)</summary>

### [`v0.20.0`](https://redirect.github.com/oxc-project/oxc/blob/HEAD/npm/oxfmt/CHANGELOG.md#0200---2025-12-22)

[Compare Source](https://redirect.github.com/oxc-project/oxc/compare/oxfmt_v0.19.0...oxfmt_v0.20.0)

##### 🚀 Features

- [`97a02d1`](https://redirect.github.com/oxc-project/oxc/commit/97a02d1) oxfmt: Add `insertFinalNewline` option ([#&#8203;17251](https://redirect.github.com/oxc-project/oxc/issues/17251)) (leaysgur)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/oxc-project/oxc).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41OS4wIiwidXBkYXRlZEluVmVyIjoiNDIuNTkuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
2025-12-22 12:52:43 +00:00
Boshen 3f5d6b7529 chore(rust): cargo-shear v1.9.0 (#16800)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-12-14 00:46:46 +08:00
Liang Mi c8a5e64422 chore(deps): apply the fix from latest cargo-shear (#16166)
Since the update of
[cargo-shear](https://github.com/Boshen/cargo-shear/releases/tag/v1.6.6),
there are more unused dependencies be found in latest version of it, it
prevents the git commits and this PR applies the fix from latest cargo
shear to fix it
2025-11-26 22:26:21 +08:00
overlookmotel 40c00cd320 ci(benchmarks/lexer): reduce string cloning in source cleaner (#15528)
Improve the source text cleaner in lexer benchmark to do less string cloning and allocations. Does not affect the benchmark itself, only makes the setup more efficient.
2025-11-09 20:57:00 +00:00
Boshen 2c3d144b12 refactor(benchmark): consolidate features into compiler and linter (#14108)
closes https://github.com/oxc-project/oxc/issues/14007

- Replace 8 individual benchmark features with 2: compiler and linter
- Update matrix script to return objects with component and feature
fields
- Simplify workflow to use cargo codspeed build/run with feature mapping

🤖 Generated with [Claude Code](https://claude.ai/code)

This balances build speed and cache size, it was saving 7 separate
caches of 280MB each component + 400MB for the linter, it's now
200-300MB for the "compiler".

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-25 17:10:52 +08:00
Boshen 08c05df60c perf(semantic): make CFG construction a compile-time feature (#13678)
part of #13646

## Summary

This PR converts the Control Flow Graph (CFG) functionality in `oxc_semantic` from runtime checks to a compile-time cargo feature, eliminating runtime overhead when CFG is not needed.

## Changes

- Added `cfg` cargo feature to `oxc_semantic/Cargo.toml` with `oxc_cfg` as optional dependency
- Feature-gated all CFG-related code using `#[cfg(feature = "cfg")]`
- Updated `oxc_linter` to enable the `cfg` feature (since it requires CFG)
- Made the `control_flow!` macro work correctly with and without the feature

## Benefits

- **Performance**: Eliminates runtime `Option<CFG>` checks when feature is disabled
- **Binary size**: Smaller binaries for crates that don't need CFG
- **Cleaner API**: CFG methods only available when feature is enabled

## Test Plan

- [x] All existing tests pass with `cargo test -p oxc_semantic --features cfg`
- [x] `oxc_linter` builds and works correctly (it enables the feature)
- [x] Feature is backward compatible - existing code continues to work

🤖 Generated with [Claude Code](https://claude.ai/code)
2025-09-11 12:44:19 +00:00
Boshen 0a66cb0599 refactor(benchmark): change benchmark files to a minimal set (#11110)
The benchmark jobs take too long to run, change them to a minimal set.

This set of files are smaller but should provide basic coverage to real
world examples.
2025-05-18 15:16:23 +08:00
camc314 79819cc12b refactor(linter): move around some config store logic (#10861)
this PR moves all of the config resolution for a single file into the `ConfigStore` structure, rather than half existing in `oxc_linter` and half in `oxlint` crates
2025-05-08 11:21:19 +00:00
Boshen d82dff91c8 feat(formatter): new implementation based on biome formatter (#10108)
Part of #5068, suggested by @ematipico and @MichaReiser, where @leaysgur
and I explored using biome formatter as the base and made a success. All
credits to the old Rome and the new Biome team.

This PR is in a boilerplate state where some of the functions are marked
as `todo!()`.

I also made the following changes:

* changed the base to be less generic, removed the `Language` and
`Context` generics
* expanded the formatter lifetime to include an `'ast` lifetime
* added access to the source text and comments
* added a mechanism for tracking and accessing parent ast nodes (done by
our codegen)
* removed most of the unit tests because they no longer compile
* removed the `oxc_prettier` crate
2025-03-30 16:54:37 +08:00
Toshit a9a47a6e1a feat(parser): Add regex cargo feature to oxc_parser (#9879)
Fixes #9839.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2025-03-19 20:57:20 +08:00
Boshen a5cde10ecc feat(visit_ast)!: add oxc_visit_ast crate (#9428)
closes #9384
2025-02-28 08:03:54 +00:00
overlookmotel d3ce88fa1c ci(benchmarks): fix and improve benchmarking commands (#9067)
* Fix `cargo benchmark` - previous it failed with an error.
* Add `just benchmark-one` to run a single benchmark e.g. `just
benchmark-one parser`.
* Simplify `default` feature in `tasks/benchmark/Cargo.toml`.
2025-02-12 21:11:17 +08:00
Boshen b7f13e636e feat(ast): implement utf8 to utf16 span converter (#8687)
closes #8629
2025-01-24 16:57:44 +00:00
overlookmotel bfd0b0da17 ci(benchmark): make lexer benchmark more realistic (#8573)
The lexer benchmarks had a problem. The lexer alone cannot make sense of regexp literals, template literals, or JSX text elements - it needs the parser "driving" it.

So lexer was producing plenty of errors on some benchmarks. This is unrealistic - when driven by the parser, the lexer produces no errors. Generating diagnostics is relatively expensive, so this was skewing the benchmarks somewhat.

Solve this by cleaning up the input source text to replace these syntaxes with string literals prior to running the benchmarks.

Unfortunately lexer benchmarks don't exercise the code paths for these syntaxes, but there isn't much we can do about that. We can judge by the parser benchmarks, which are the more important ones anyway.
2025-01-18 01:47:07 +00:00
Boshen dba054f529 feat(tasks/benchmark): add mangler (#8470)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-14 10:08:13 +08:00
camc314 9b3a2beaa3 refactor(benchmark): transform code before codegen (#7934)
@overlookmotel suggested this [here](https://github.com/oxc-project/oxc/pull/7926#discussion_r1886023496).
2024-12-16 13:08:11 +00:00
Boshen 348d4f451a feat(sourcemap): move oxc_sourcemap to github.com/oxc-project/oxc-sourcemap (#7604)
It's mostly stable so we can v1.0.0 it.

And we will create cyclic dependency with StringWizard soon.
2024-12-03 11:59:43 +00:00
overlookmotel 911e4e58ab ci(minifier): minifier benchmark measure only the minifier itself (#6222)
Minifier benchmark currently includes the time to run parser and semantic as well as the minifier itself. Similar to transformer benchmark, only measure the minifier itself in the benchmark.

This will give us a clearer picture of performance changes, and should also reduce variance in the benchmarks.
2024-10-01 17:43:39 +00:00
Boshen 63a830e08c chore(dprint): format toml files (#5599)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-09-08 14:26:16 +08:00
Boshen 56cc4818b5 chore(website): remove textlint annotation
the website no longer uses textlint
2024-08-23 15:50:52 +08:00
Boshen 4b49cf8ce4 feat(transformer): always pass in symbols and scopes (#5087)
We no longer need to build semantic data inside the transformer.

The caller should be responsible for handling semantic data and its
errors.

The best way to achieve this in via `CompilerInterface`.

closes #3565
2024-08-22 16:06:31 +00:00
Boshen bf48c7f02a fix(minifier): fix keep_var keeping vars from arrow functions (#4680) 2024-08-06 07:04:25 +00:00
Boshen 0f5e982d19 perf(minifier): only visit arrow expression after dropping console.log (#4677) 2024-08-06 04:20:41 +00:00
Boshen e78cba6464 refactor(minifier): ast passes infrastructure (#4625)
After studying google closure compiler, I'm leaning towards a multi-ast-pass infrastructure for the minifier.

This is one of the few places where we are going to trade maintainability over performance, given the goal of the minifier is compression size not performance.

All of the terminologies and separation of concerns are aligned with google closure compiler.

Infrastructure of `terser` and `esbuild` are not suitable for us to study nor pursuit. Their code are so tightly coupled - I failed to comprehend any of them every time I try to walk through a piece of optmization. Google closure compiler despite being written in Java, it's actually the most readable minifier out there.

To improve performance between ast passes, I envision a change detection system over a portion of the code.

The benchmark will demonstrate the performance regression of running 5 ast passes instead of 2.

To complete this PR, I need to figure out "fix-point" and order of these ast passes.
2024-08-04 11:58:39 +00:00
Boshen 73d2558c14 fix(oxlint): fix oxlint failed to build due to missing feature
closes #4626
2024-08-04 19:33:04 +08:00
DonIsaac 6ff200d072 perf(linter): change react rules and utils to use Cow and CompactStr instead of String (#4603) 2024-08-03 21:26:08 +00:00
Boshen 91dc0f7866 chore(benchmark): add codegen benchmark (#4207) 2024-07-11 23:58:37 +08:00
Boshen 0ba375899c chore(tasks/benchmark): add isolated_declarations bench 2024-07-07 19:22:49 +08:00
Dunqing 54b3b6c0da chore(benchmark): add isolated declarations (#4078) 2024-07-07 17:14:48 +08:00
Boshen c2c425d4dc chore: bump criterion2 (#3444) 2024-05-28 15:49:51 +08:00
Boshen 1e84644220 chore: update toml format 2024-05-21 22:15:47 +08:00
Boshen f6daf0b7ae feat(sourcemap): add feature "sourcemap_concurrent" 2024-05-14 00:05:27 +08:00
overlookmotel f0cbbbe28c ci: build each benchmark only with deps it needs (#3221)
This PR builds on #3201 to further speed up the benchmarks and reduce CI
time.

* Build and run each benchmark as separate job (like before).
* But now each bench is only built with the dependencies it needs.
* For linter benchmarks, build benchmark in 1 job (like #3201 does).
* Run each linter fixture in a separate job as they're slow.

This reduces total time to complete benchmarks from between 6m-7m to
~4m40s.

All the individual jobs complete in under 1m30s, except for building
linter benchmark which takes 2m30s. So there won't be the problem of
blocking the CI queue that there was before.

NB: I did try this before, and didn't see a benefit. But I realized
today what I was doing wrong - it only works once the caches are
populated by a previous run on main branch.

So the CI times in this PR won't look good, but once it's merged to
main, it will take effect. Here it is running on main branch of my fork:

https://github.com/overlookmotel/oxc/actions/runs/9030511348

I also added a step to delete the temp artefacts which aren't needed
once the run has completed.
2024-05-10 22:01:24 +08:00
Boshen 7363e14335 feat(sourcemap): add "rayon" feature (#3198) 2024-05-07 23:47:36 +08:00
renovate[bot] 6fd6170154 chore(deps): lock file maintenance rust crates (#3125) 2024-04-29 06:00:15 +00:00
renovate[bot] df7b9ee8da chore(deps): lock file maintenance rust crates (#3059) 2024-04-22 09:58:21 +08:00
Boshen a0532adc65 chore: bump criterion2, which removes clap and 10s compile time 2024-04-02 16:48:40 +08:00
underfin b199cb89a2 feat: add oxc sourcemap crate (#2825)
The sourcemap implement port from
[rust-sourcemap](https://github.com/getsentry/rust-sourcemap), but has
some different with it.

- Encode sourcemap at parallel, including quote `sourceContent` and
encode token to `vlq` mappings.
- Avoid `Sourcemap` some methods overhead, like `SourceMap::tokens()`
caused extra overhead at common cases. Here using `SourceViewToken` to
instead of it.
2024-03-28 19:36:38 +08:00
Wang Wenzhe 3897cf4118 chore(eslint/tree-shaking): add NoEffect explicitly (#2823) 2024-03-26 21:32:29 +08:00
overlookmotel 29d8a64bc9 perf(tasks): speed up NAPI parser benchmark build (#2787)
The `parser_napi` pseudo-benchmark does not depend on any Oxc crates, so
remove all dependencies for this benchmark. This reduces build time of
this benchmark on CI by ~1 minute.

After #2780, NAPI parser benchmark sometimes took the longest of all the
benchmarks, so making it faster reduces time to complete the benchmarks
overall.
2024-03-22 12:09:32 +00:00
overlookmotel 508091314f feat(tasks): benchmark NodeJS parser (#2770)
Add NodeJS parser to benchmarks.

Previous attempt #2724 did not work due CodSpeed producing very
inaccurate results (https://github.com/CodSpeedHQ/action/issues/96).

This version runs the actual benchmarks without CodSpeed's
instrumentation. Then another faux-benchmark runs within Codspeed's
instrumented action and just performs meaningless calculations in a loop
for as long as is required to take same amount of time as the original
uninstrumented benchmarks took.

It's unfortunate that we therefore don't get flame graphs on CodSpeed,
but this seems to be the best we can do for now.
2024-03-20 05:06:09 +00:00
Boshen 178d205d53 chore: criterion2 (#2737) 2024-03-16 18:55:04 +08:00