Commit Graph

69 Commits

Author SHA1 Message Date
Boshen 030857b509 refactor(diagnostics): update oxc-miette to v4 (#25395)
Remove the miette `Report` wrapper and update oxc-miette to v4's narrowed diagnostic and source protocol.

AI-assisted by OpenAI Codex.
2026-08-10 07:48:02 +00:00
Boshen 777f02ae10 refactor(diagnostics)!: return a Diagnostics type instead of Vec<OxcDiagnostic> (#23217)
## Summary

Introduces `oxc_diagnostics::Diagnostics` — a `Vec<OxcDiagnostic>` newtype that knows the difference between errors and warnings — and makes it the standard diagnostics return value across oxc.

- **New type**: `Diagnostics` with `has_errors()`, `has_warnings()`, `errors()`, `warnings()`, plus `Vec`-like ergonomics (Deref, `IntoIterator`, `Extend`, `From`/`Into<Vec>`) so most call sites are unchanged.
- **Return types**: `ParserReturn`, `SemanticBuilderReturn`, `IsolatedDeclarationsReturn`, the React Compiler `TransformResult`/`LintResult`, and `TransformerReturn` now expose `diagnostics: Diagnostics` instead of `errors: Vec<OxcDiagnostic>` (the React Compiler's separate `errors`/`warnings` are merged into one severity-tagged list).
- **Behaviour**: a React Compiler **error** now stops the transform (no output), while **warnings** flow through and the transform continues. `compile()` aborts codegen only when `diagnostics.has_errors()` — warnings alone no longer abort (previously any diagnostic did).

## Breaking change

Consumers reading `*.errors` on these return values must read `*.diagnostics`. React Compiler consumers that read `.errors`/`.warnings` separately should use `diagnostics.has_errors()` / `diagnostics.errors()` / `diagnostics.warnings()`.

Parser/semantic/isolated-declarations fatality is otherwise unchanged. Builds on the React Compiler transform feature (#23201).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-06-10 14:46:52 +00:00
Dunqing 5e755d14f9 chore(transformer, playground): enable enum_eval in semantic for transformer (#21671)
close: https://github.com/oxc-project/oxc/issues/21667
2026-04-23 10:27:58 +00:00
Dunqing 5df2eb4182 chore(transformer): make copy output from terminal friendly (#21663)
Tab may be lost when copying from the terminal, which makes it hard for us to use https://source-map-viewer.void.app for inspection. So change it to space.
2026-04-23 03:00:38 +00:00
Dunqing 6c9949ff3b chore(transformer): support --inline-sourcemap in example (#21641)
Include an inline sourcemap for easy use of https://github.com/Dunqing/source-map-viewer for inspecting.
2026-04-22 13:42:25 +00:00
Copilot 514322c4c3 docs(rust): Add minimal documentation to example files in crates directory (#12731) 2025-08-02 22:02:20 +08:00
Boshen 315143ae42 refactor(codegen)!: remove useless CodeGenerator type alias (#10702) 2025-04-29 17:01:07 +00:00
camc314 f48f8955e3 fix(transfomer/using): remove use of child ids (#9961)
fixes #9744
2025-04-04 01:04:32 +00:00
camc314 a10ead8913 feat(transformer): transform explicit resource management (#9310)
~~wanted to have a shot at implementing this, this is rough draft.~~

~~Dunqing or overlookmotel feel free to take over or close out this PR. not sure how much time i'll have to finish it off~~

@Dunqing @overlookmotel this should be ready when you guys have time 🙏

closes #9168
2025-03-11 05:42:47 +00:00
Boshen 23738bf9db refactor(semantic)!: introduce Scoping (#9611)
part of #9607
2025-03-09 10:28:11 +00:00
overlookmotel a4a8e7deda style(all): replace #[allow] with #[expect] (#8930)
Replace `#[allow]` with `#[expect]` through the whole codebase.

This also surfaced many places where the `#[allow]` attributes were outdated/pointless and could be removed entirely.

Only places `#[allow]` remains are:

1. In generated code and macros, where lint errors may or may not be triggered depending on the generated code.
2. A few places where clippy malfunctions. These use e.g. `#[allow(unused, clippy::allow_attributes)]`.
2025-02-07 14:50:02 +00:00
Dunqing 4a524ed150 chore(transformer): support passing babel options path in example (#7790)
Sometimes we want to use Babel test's options to test some code, If the example can get the TransformerOptions from Babel options, then we can easily do it
2024-12-11 00:33:22 +00:00
Boshen 224775c056 feat(transformer): transform object rest spread (#7003)
https://babel.dev/docs/babel-plugin-transform-object-rest-spread
2024-11-21 11:33:26 +00:00
Boshen 846711cf41 feat(transformer)!: change API to take a &TransformOptions instead of TransformOptions (#7213)
closes #7185

`TransformOption`s has an initialization cost, it should be initialized once and shared across files.
2024-11-09 06:01:13 +00:00
Boshen a166a4abd7 feat(transformer): add esbuild comma separated target API --target=es2020,chrome58 (#7210) 2024-11-08 14:09:20 +00:00
Boshen 9f611a18cf chore(transformer): fix typos s/browerslist/browserslist/ 2024-11-03 21:54:54 +08:00
Boshen bfdbcf1c6a feat(transformer): add EnvOptions::from_browerslist_query API (#7098) 2024-11-03 12:43:25 +00:00
Boshen 21b8e4988f feat(transformer): add ESTarget (#7091)
closes #6982
2024-11-03 12:21:53 +00:00
Boshen fcaba4a92a feat(transformer): add TransformerOptions::env with EnvOptions (#7037) 2024-10-31 12:30:32 +00:00
Boshen e921df6199 refactor(transformer): rename EnvOptions to BabelEnvOptions (#7036) 2024-10-31 10:00:52 +00:00
Boshen 76947e2aec refactor(transform): refactor Babel Targets (#7026)
Found a trick from serde to get us from `BabelTargets` to `Targets`.
2024-10-30 14:08:19 +00:00
Boshen b8daab3663 refactor(transformer)!: API to TryFrom<&EnvOptions> for TransformOptions and TryFrom<&BabelOptions> TransformOptions (#7020)
…ions` and `TryFrom<&BabelOptions> TransformOptions`
2024-10-30 09:40:09 +00:00
Boshen 520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +00:00
Boshen 2b7be08af4 feat(ast)! add source_text to Program (#6444) 2024-10-11 04:13:41 +00:00
Boshen 020bb80b65 refactor(codegen)!: change to CodegenReturn::code and CodegenReturn::map (#6310) 2024-10-06 05:05:47 +00:00
overlookmotel 4f6bc79734 refactor(transformer)!: remove source_type param from Transformer::new (#6251)
Closes #6248.
2024-10-03 00:21:01 +00:00
overlookmotel b9c45646d1 refactor(transformer): transformer example output semantic + transformer errors (#5852) 2024-09-18 11:08:27 +00:00
overlookmotel 3230ae5842 feat(semantic): add SemanticBuilder::with_excess_capacity (#5762)
Add `SemanticBuilder::with_excess_capacity` method to request that `SemanticBuilder` over-allocate space in `Semantic`'s `Vec`s.

Use this method to reserve 200% extra capacity for transformer to create more scopes, symbols and references.

200% is an unscientific guess of how much extra capacity is required. Obviously it depends on what transforms are enabled and content of the source code.
2024-09-14 15:02:16 +00:00
Boshen b06052501a refactor(semantic)!: remove source_type argument from SemanticBuilder::new (#5553)
Realized we can get the source type from the AST.

The next PR will introduce `unambiguous` to `SourceType` and directly set `Program::source_type` to either `script` or `module`.
2024-09-06 16:40:10 +00:00
Boshen 32d4bbb519 feat(transformer): add TransformOptions::enable_all method (#5495)
Make it **really** explicit about which transformer options are being
turned on. I also need this in monitor-oxc.
2024-09-06 12:04:06 +08:00
Boshen 8d565d5b23 chore(transformer): update examples to use the targets API 2024-08-31 14:08:37 +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
overlookmotel ff1da27278 fix(transformer): correct comment in example (#3831)
Correct instructions for transformer example.
2024-06-22 19:08:01 +00:00
Boshen 5c38a0fd69 feat(codegen)!: new code gen API (#3740)
This PR introduces two type alias to avoid the confusing const generic `pub struct Codegen<'a, const MINIFY: bool>`

* CodeGenerator - Code generator without whitespace removal.
* WhitespaceRemover - Code generator with whitespace removal.

Usage is changed to a builder pattern:

```rust
CodeGenerator::new()
  .enable_comment(...)
  .enable_sourcemap(...)
  .build(&program);
```
2024-06-18 15:50:12 +00:00
Boshen 982e6f08df chore: make println and eprintln opt-in (#3712)
I noticed accidental `println` can be merged, which isn't really nice.
2024-06-17 10:40:34 +00:00
Boshen 750a534455 feat(coverage): transformer idempotency test (#3691) 2024-06-15 13:59:53 +00:00
Boshen b58d8eb88f fix!(codegen): remove the unecessary 4th argument from Codegen::new (#3640) 2024-06-12 07:58:54 +00:00
Boshen f6752b482f feat!(ast): make Trivias clonable by adding Arc (#3638)
This makes `Trivias` cloneable and stops us from using `Rc::new` and
`Rc::clone` everywhere.

`Trivias` is rarely cloned so an `Arc` should suffice.
2024-06-12 13:16:10 +08:00
Dunqing 5793ff1986 refactor(transformer): replace &’a Trivias with Rc<Trivias> (#3580)
`Transformer` needs to borrow `Trivias`.
https://github.com/rolldown/rolldown/pull/1364/files/8be1cc80520e1a466cd7b2d3fb8b637db9e529a9#r1630711060
2024-06-11 13:23:41 +08:00
Dunqing 6978269be0 refactor(transformer/typescript): replace reference collector with symbols references (#3533)
https://github.com/oxc-project/oxc/pull/3524 handled the references correctly, now we can remove the reference collector.
2024-06-05 09:02:51 +00:00
IWANABETHATGUY 0cdb45a1ff feat(oxc_codegen): preserve annotate comment (#3465)
1. Copy tests from
https://github.com/evanw/esbuild/blob/efa3dd2d8e895f7f9a9bef0d588560bbae7d776e/internal/bundler_tests/bundler_dce_test.go#L3833-L3971
2. Add option to preserve annotate comment like `/* #__NO_SIDE_EFFECTS__
*/` and `/* #__PURE__ */`
2024-05-30 15:25:23 +08:00
Boshen a63a45d5b2 refactor(transformer): remove the requirement of Semantic (#3140)
It seems like we need to rebuild the scopes and symbols while
traversing. We can't utilize the scopes and symbols built by semantic
because they are immutable.
2024-04-30 12:48:21 +08:00
Boshen 3419306ac0 feat(transformer): add filename (#2941) 2024-04-11 18:43:51 +08:00
Boshen 293b9f482a feat(transformer): add transform-typescript boilerplate (#2866) 2024-03-30 20:48:35 +08:00
Boshen c1a2958a5a chore: remove oxc_transformer for a reimplementation (#2865)
closes #2860
2024-03-30 17:19:46 +08:00
underfin d9b77d853b refactor(sourcemap): change sourcemap name to take a reference (#2779) 2024-03-23 21:40:05 +08:00
Boshen ef932a3c27 refactor(codegen): clean up API around building sourcemaps (#2602)
closes #2564
2024-03-04 16:03:33 +08:00
Dunqing f760108094 feat(transformer): call build module record (#2529) 2024-02-28 14:35:35 +08:00
Andrew McClenaghan e6d536cb9b feat(codegen): configurable typescript codegen (#2443)
- Adds option to `CodegenOptions` - `enable_typescript` to enable output
of TS.
- Stops skipping output that is TS when `enable_typescript` is enabled
- Adds TS support to 
    - Function
    - FormalParameter
    - BindingPattern
 - Adds basic tests for TS generation

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-02-20 12:09:28 +08:00
Miles Johnson c6ad6603a4 feat(semantic): support scope descendents starting from a certain scope. (#1629)
@Boshen 

The `ScopeTree.descendants` function would return all scopes starting
from the root, and wasn't truly descendants from a specific scope. To
improve this, I've renamed this function to `descendants_from_root` and
have introduced a new `descendants` function that does support from a
specific scope.

Furthermore, I've introduced helper functions to `SymbolTree` to make
reading symbols/scopes easier.

To verify this functionality, I enabled the `function_name` transformer
(and fixed it), and ran some example transforms. Here's the input:

```js
let fn;

fn = function (a, b, c) {
  const d = "";
};

const func = function (arg) {
  {
    const value = "";
  }
};

const f = function (f) {};
```

And the output using _the old implementation_. Note that all function
names are suffixed with a number, this is incorrect, since it was
inheriting far too many scopes.

```js
let fn;
fn = function fn1(a, b, c) {
	const d = '';
};
const func = function func1(arg) {
	{
		const value = '';
	}
};
const f = function f2(f) {
};
```

And here's the output with the new implementation. Note that only `f` is
suffixed with a number. That's because it has a shadowed argument of the
same name.

```js
let fn;
fn = function fn(a, b, c) {
	const d = '';
};
const func = function func(arg) {
	{
		const value = '';
	}
};
const f = function f1(f) {
};
```
2023-12-07 17:29:11 +08:00