Skip to content

feat(fmt): prototype SWC Next 0.2.0 via crate and decoder - #465

Draft
SoonIter wants to merge 1 commit into
mainfrom
codex/poc-fmt-swc-next-native
Draft

feat(fmt): prototype SWC Next 0.2.0 via crate and decoder#465
SoonIter wants to merge 1 commit into
mainfrom
codex/poc-fmt-swc-next-native

Conversation

@SoonIter

@SoonIter SoonIter commented Sep 7, 2026

Copy link
Copy Markdown
Member

Summary

This draft evaluates replacing Yuku in rs fmt by compiling swc_next_bridge = "=0.2.0" into rstack's existing native binding and decoding its Buffer with @swc-next/decoder@0.2.0. The thin NAPI adapter delegates parsing and serialization to the upstream crate, uses the lazy generated loader, and requires no parser npm package or separate SWC Next native binary.

It shares the Prettier adapter and compatibility tests with #464, retains explicit Prettier parsers and project plugin precedence, and isolates its formatting cache. Both routes record the same upstream gap: function implementations in declaration files are accepted rather than diagnosed; explicit experimental aliases become swc-next and swc-next-ts.

On macOS arm64, debug/release native builds, Rust formatting/Clippy/tests, pnpm check, spelling, and the complete JS suite pass (380 passed, one existing skipped test). packages/rstack/SWC_NEXT_POC.md includes reproduction and limits; serializer and decoder upgrades must stay synchronized, and cross-platform parity and throughput are not established.

Related Links

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying rstack-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: 61def22
Status: ✅  Deploy successful!
Preview URL: https://0f1cd851.rstack-cli.pages.dev
Branch Preview URL: https://codex-poc-fmt-swc-next-nativ.rstack-cli.pages.dev

View logs

SoonIter commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

Known compatibility difference in swc-next 0.2.0, found by the existing rs fmt tests for .d.ts, .d.mts, and .d.cts:

export function value() { return 1; }

This is valid in a normal .ts file, but declaration files should contain a signature such as export function value(): number;. swc-next 0.2.0 currently returns no diagnostics for the implementation even with lang: "dts" explicitly selected, so this is not a filename-to-language mapping issue.

The previous Yuku adapter reported this with semanticErrors: false, and Babel reports it with its TypeScript dts: true option. TypeScript reports TS1183 during semantic checking when declaration checking is enabled (skipLibCheck: false); its syntactic diagnostics alone do not report it.

Upstream draft fix: https://github.com/swc-project/swc-next/pull/631. It proposes extending the existing ambient-implementation diagnostic to inherited ambient contexts, with regression tests and four additional passing conformance cases.

This PoC remains pinned to 0.2.0, and its tests explicitly record the current acceptance difference. The draft fix is not included in that published version; the rejection expectation can be restored after upgrading to a release containing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant