Files
aba65151d3 feat(bindings): add lint / lintSync API to @swc/react-compiler (#11965)
**Description:**

Adds a dedicated `lint`/`lintSync` API to `@swc/react-compiler` for
running React Compiler's lint pass and getting back structured
diagnostics, without compiling.

This replaces the original approach in this PR (attaching
`reactCompilerDiagnostics` to `@swc/core`'s thrown
`transform`/`transformSync` error), per feedback from @kdy1 and
@magic-akari — a dedicated API scoped to React Compiler, rather than
extending `@swc/core`'s generic error shape. That change is fully
reverted here.

```ts
import { lint, lintSync } from '@swc/react-compiler'

lintSync(code: string, syntax?: ParserConfig): Diagnostic[]
lint(code: string, syntax?: ParserConfig): Promise<Diagnostic[]>
```

- `code` is the raw source text.
- `syntax` is the same `ParserConfig` shape `@swc/core`'s `jsc.parser`
already accepts (`@swc/types`), letting callers opt into
TypeScript/JSX/TSX/decorators per file. Defaults to plain ECMAScript
when omitted, matching `@swc/core`'s own default.
- Each `Diagnostic` includes `severity`, `message`, `ruleId`,
`category`, `reason`, `description`, `loc` (start/end line/column/index
+ filename/identifierName), and `details`.

Motivating use case: building fast, per-rule ESLint integrations on top
of the Rust-based compiler (one `lintSync` call per file, fanned out to
N independently-configurable ESLint rules by `ruleId`) instead of
re-implementing lint checks in JS.

React Compiler's own compile options (`compilationMode`, `target`,
`panicThreshold`, `gating`, `environment`, ...) are intentionally not
exposed yet — investigated and left as-is for now (e.g. raising
`panicThreshold` would route more results through a fallback path that
loses `ruleId`/`category`/`loc`, working against the point of this API).

Validation:

- `cargo fmt --all`
- `cargo clippy --all --all-targets -- -D warnings`
- `cargo test -p swc_ecma_react_compiler`
- `cargo test -p binding_react_compiler_node`
- `cargo check -p binding_core_node` (confirms the revert didn't leave
`@swc/core`'s napi binding referencing removed types)
- `pnpm --filter @swc/react-compiler build:dev && pnpm --filter
@swc/react-compiler test`

**BREAKING CHANGE:**

None. `lint`/`lintSync` are new; the reverted `@swc/core` changes were
never released.

**Related issue (if exists):**

None.

---------

Co-authored-by: Oz <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
Co-authored-by: DongYun Kang <[email protected]>
2026-07-06 14:28:42 +09:00

35 lines
966 B
TOML

[package]
authors = ["강동윤 <[email protected]>"]
build = "build.rs"
edition = "2021"
exclude = ["artifacts.json", "index.node"]
license = "Apache-2.0"
name = "binding_react_compiler_node"
publish = false
version = "0.2.0"
[lib]
bench = false
crate-type = ["cdylib"]
[build-dependencies]
napi-build = { workspace = true }
[dependencies]
backtrace = { workspace = true }
napi = { workspace = true, features = ["napi3", "serde-json"] }
napi-derive = { workspace = true, features = ["type-def"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tracing = { workspace = true, features = ["release_max_level_info"] }
swc_core = { path = "../../crates/swc_core", features = [
"allocator_node",
"common_sourcemap",
"ecma_ast",
"ecma_parser",
] }
swc_ecma_react_compiler = { path = "../../crates/swc_ecma_react_compiler" }
swc_malloc = { path = "../../crates/swc_malloc" }