Commit Graph

33 Commits

Author SHA1 Message Date
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
Boshen ea51b0b5c8 feat(napi)!: standardize function naming with sync suffixes (#15661)
closes #15576

## Summary

Standardizes function naming across all NAPI packages (parser, transform, minify) with a consistent pattern:
- Async functions: `verb` (no suffix)
- Sync functions: `verbSync` (with Sync suffix)

## Changes

### Breaking Changes

**napi/parser:**
- `parseAsync` → `parse` (async)
- `parseSync` remains unchanged (sync)

**napi/transform:**
- `transformAsync` → `transform` (async)
- `transform` → `transformSync` (sync)
- `isolatedDeclaration` → `isolatedDeclarationSync` (sync)
- Added new `isolatedDeclaration` function (async)
- `moduleRunnerTransform` → `moduleRunnerTransformSync` (sync)
- Added new `moduleRunnerTransform` function (async)

**napi/minify:**
- `minify` → `minifySync` (sync)
- Added new `minify` function (async)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-11-13 12:28:23 +00:00
Boshen 8b30a5bbd6 feat(codegen)!: introduce CommentOptions (#12114)
Control printing of comments more precisely via more options:

The logic change here is that jsdoc is no longer part of annotation
comments.

```rust
pub struct CommentOptions {
    /// Print normal comments that do not have special meanings.
    ///
    /// At present only statement level comments are printed.
    ///
    /// Default is `true`.
    pub normal: bool,

    /// Print jsdoc comments.
    ///
    /// * jsdoc: `/** jsdoc */`
    ///
    /// Default is `true`.
    pub jsdoc: bool,

    /// Print annotation comments.
    ///
    /// * pure: `/* #__PURE__ */` and `/* #__NO_SIDE_EFFECTS__ */`
    /// * webpack: `/* webpackChunkName */`
    /// * vite: `/* @vite-ignore */`
    /// * coverage: `v8 ignore`, `c8 ignore`, `node:coverage`, `istanbul ignore`
    ///
    /// Default is `true`.
    pub annotation: bool,

    /// Print legal comments.
    ///
    /// * starts with `//!` or `/*!`.
    /// * contains `/* @license */` or `/* @preserve */`
    ///
    /// Default is [LegalComment::Inline].
    pub legal: LegalComment,
}
```

closes #12030
related https://github.com/rolldown/tsdown/issues/357
2025-07-07 08:57:59 +00:00
Boshen 315143ae42 refactor(codegen)!: remove useless CodeGenerator type alias (#10702) 2025-04-29 17:01:07 +00:00
Boshen 2cedfe4148 feat(napi): add codeframe to napi error (#9893)
closes #8684
2025-03-19 08:41:31 +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
overlookmotel 3858221f45 refactor(global): sort imports (#7883)
Pure refactor. Re-order imports for clarity:

1. `std`
2. External crates
3. `oxc_*` crates
4. Current crate `use crate::...`
5. Super `use super::...`
6. Local modules

This order is from "furthest away" to "closest". This makes it clearer to see what is coming from where.

`cargo +nightly fmt` (#7877) did a lot of the work, but unfortunately `rustfmt` does not have an option to (a) put workspace crates in a separate block from external crates and (b) move `mod` statements to after `use` statements.
2024-12-14 15:07:21 +00:00
Boshen 7fb9d47460 style(rust): cargo +nightly fmt (#7877) 2024-12-14 06:03:31 +00:00
Boshen 18d0ce3c06 fix(napi): rename Error to OxcError to avoid name collision (#7780) 2024-12-11 00:30:07 +08:00
Boshen 85eec3c82e feat(napi/transform,napi/parser): return structured error object (#7724)
closes #7261
2024-12-08 14:11:56 +00:00
Boshen 771c698a81 feat(oxc): remove oxc_napi crate (#7634)
napi has a limitation, it cannot feature gate type exposure.

closes #7623
2024-12-04 10:07:32 +08:00
Boshen b4f3812c4a refactor(oxc_napi): remove source_map - moved to its crate (#7614) 2024-12-03 14:42:34 +00:00
Boshen bd977cf742 feat(oxc): add oxc_napi crate (#7612) 2024-12-03 14:02:47 +00:00
Kevin Deng 三咲智子 be2293a1b5 fix(napi/transform): respect options.sourcemap for id (#7590)
Don't pass `source_map_path` if `options.sourcemap` is undefined or
false; then, `IsolatedDeclarationsResult.map` should be undefined.

Downstream issue
https://github.com/unplugin/unplugin-isolated-decl/issues/42

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-12-03 11:57:44 +08:00
Boshen 91c87dd380 refactor(codegen)!: remove Codegen::enableSourceMap API (#6452) 2024-10-12 04:56:43 +00:00
Boshen 7645e5c34b refactor(codegen)!: remove CommentOptions API (#6451) 2024-10-11 13:53:28 +00:00
Boshen 520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +00:00
Boshen 020bb80b65 refactor(codegen)!: change to CodegenReturn::code and CodegenReturn::map (#6310) 2024-10-06 05:05:47 +00:00
Boshen a0ccc26c12 feat(napi/transform): add lang option to change source type (#6309)
part of #6274 and #6156

```
    /// Treat the source text as `js`, `jsx`, `ts`, or `tsx`.
    #[napi(ts_type = "'js' | 'jsx' | 'ts' | 'tsx'")]
    pub lang: Option<String>,
```
2024-10-06 04:53:47 +00:00
Boshen 58a8615747 refactor(napi/transform): remove context (#6306) 2024-10-06 01:57:49 +00:00
Boshen 8729755baa feat(oxc,napi/transform): napi/transform use oxc compiler pipeline (#6298)
part of #6156
2024-10-05 16:35:09 +00:00
Boshen 2f888ed871 feat(oxc): add napi transform options (#6268) 2024-10-03 13:36:38 +00:00
Boshen 54c1c53e69 refactor(napi/transform): remove a call on TransformOptions::clone (#6210) 2024-10-01 09:52:39 +00:00
Boshen 84a5816d03 feat(isolated_declarations): add stripInternal (#5878)
closes #3906
closes #5687
closes #3958

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2024-09-19 23:14:47 +08:00
Boshen 6c04fa1e46 fix(napi/transform): make isolated_declaration options optional (#5880)
closes #5871
2024-09-19 08:07:54 +00:00
Boshen dfbde2c602 feat(isolated_declarations): print jsdoc comments (#5858) 2024-09-18 14:09:00 +00:00
Boshen 1bed5ce2a5 chore: run cargo +nightly fmt to sort imports (#5503)
They are never going to be stable are they ... https://github.com/oxc-project/oxc/blob/cedf7a4daa4084523050d9ae1b4555e5174c6347/.rustfmt.toml#L8-L16
2024-09-06 04:04:26 +00:00
Boshen b1d0075359 feat(napi/transform)!: align output API sourceText -> code with babel (#5398)
And `sourceMap` -> `map`

closes #5397
2024-09-02 07:53:46 +00:00
dalaoshu 72740b3f78 feat(isolated_declaration): support sourcemap option (#5170)
closes #4313
2024-08-25 13:32:47 +08:00
Boshen ce4d4698b4 feat(codegen)!: remove const generic MINIFY (#5001)
This is a premature optimization, makes the code complicated, and bloats the final binary size.

The minify option is moved to `CodegenOptions`
2024-08-20 08:13:27 +00:00
Boshen 4d0b40ad10 fix(napi/transform): fix wrong isolated declarations emit 2024-08-08 14:36:41 +08:00
DonIsaac 9b51e045c7 refactor: overhaul napi transformer package (#4592)
## What This PR Does
- Support declaration emit with `transform()`
- Consolidate shared parsing and error reporting logic into a `TransformContext`
- Add JSDoc comments to options

I'm getting this package ready for consumption in [oxc-jest](https://github.com/oxc-project/oxc-jest).
2024-08-06 01:14:10 +00:00
Boshen 720983a965 feat(napi/transform): allow setting sourceType to transform (#4113)
closes #4071

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-07-08 19:09:45 +08:00