feat(fmt): use SWC Next parser - #464
Conversation
Deploying rstack-cli with
|
| Latest commit: |
889d13e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://727ecb63.rstack-cli.pages.dev |
| Branch Preview URL: | https://codex-poc-fmt-swc-next-npm.rstack-cli.pages.dev |
|
Known compatibility difference in swc-next 0.2.0, found by the existing export function value() { return 1; }This is valid in a normal The previous Yuku adapter reported this with 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. |
0016242 to
dae1f31
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The broad @swc-next/* release-age exemption must be scoped to the pinned packages and version.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
What changed in this PR
Migrates rs fmt to use @swc-next/parser@0.2.2 by default while retaining Prettier compatibility and replacing Yuku.
Changes:
- Added SWC Next parser integration and tests.
- Updated dependencies, lockfile, Renovate rules, and attribution.
- Updated English and Chinese formatting documentation.
| File | Reviewed changes |
|---|---|
website/docs/zh/guide/formatting.mdx |
Updated Chinese formatting documentation. |
website/docs/en/guide/formatting.mdx |
Updated English formatting documentation. |
pnpm-workspace.yaml |
Updated dependency and release-age configuration. Critical: the @swc-next/* exemption is broader than the pinned dependency and should be scoped. |
pnpm-lock.yaml |
Replaced Yuku packages with SWC Next dependencies. |
packages/rstack/THIRD_PARTY_NOTICES.md |
Updated third-party attribution. |
packages/rstack/tests/fmt/swcNextPlugin.test.ts |
Added and updated parser integration coverage. |
packages/rstack/src/fmt/swcNextPlugin.ts |
Implemented the SWC Next parser adapter. |
packages/rstack/src/fmt/prettierPlugins.ts |
Registered SWC Next as the default parser plugin. |
packages/rstack/package.json |
Updated runtime dependencies. |
.github/renovate.json |
Updated dependency maintenance rules. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
The upstream fixes included in
Verified inputs, outputs, and implementation detailsRe-tested the three upstream fixes included in These fixes are implemented upstream; this PR brings them into 1. Nested conditional + typed arrow — swc-next#635Input ( cond ? inner ? items.map((item): Item => item) : (a) : b => b;
Formatted output with this PR, also identical to native Prettier TypeScript: cond ? (inner ? items.map((item): Item => item) : a) : (b) => b;The simpler 2. Bare call signature: prevent silent content loss — swc-next#636Input ( (name: string): void;
The same content inside an MDX code fence: ```ts
(name: string): void;
```Main produces an empty fence: ```ts
```This PR preserves the original fence and signature unchanged. Prettier retains embedded source when its parser rejects it. Yuku's missing-arrow branch returns no node without a diagnostic; #636 adds the diagnostic for a committed arrow head. 3. Ambient function bodies: preserve scope during recovery — swc-next#631Compared with SWC Next 0.2.0, #631 adds the missing diagnostic for inputs such as Input ( // Keep the namespace on one line to exercise closing-brace recovery.
declare namespace N { function value() { return 1; } const after: number; }
declare const outside: number;
Yuku returns immediately at the invalid body's opening brace. #631 consumes that body before recovering a bodyless signature, so its This is a parser recovery improvement: both formatter adapters still reject this invalid declaration file. The function body is deliberately omitted from SWC Next's recovered AST; it is not formatted as valid code. |
|
Benchmarked the SWC Next and Yuku adapters bundled in
SWC Next was slightly slower in this run. It was faster in 6/20 whole-repository pairs and 5/20 JS/TS pairs. These results describe this machine and corpus, not parser performance in general. Setup
node <variant>/packages/rstack/bin/rs.js fmt --check --no-cache --parallel-workers 8 .
node <variant>/packages/rstack/bin/rs.js fmt --check --no-cache --parallel-workers 8 '**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}'All 92 runs, including warmups, passed. Both variants discovered identical file manifests and produced output identical to the source files; source hashes were unchanged afterward. Times include CLI startup, discovery, worker startup, parsing and Prettier printing, but exclude file write-back. ¹ Median of the 20 per-round percentage changes; it is not the percentage difference between the two independently calculated medians. Positive values mean SWC Next took longer. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |

Motivation
Use
@swc-next/parser@0.2.2as the default JavaScript, JSX and TypeScript parser inrs fmt.Changes
Validation
@swc-next/parserto 0.2.2The corpus check used Rsbuild
f69eb5a, Yuku 0.10.2 and Prettier 3.9.7, honoring its existing JS/TS fixture exclusions. It did not modify repository files or measure performance.