AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack Only Passes Comments To SWC Wasm Plugins When Both Leading And Trailing Comments Exist

Turbopack's comment proxy is enabled only when a source file contains both leading and trailing comments. Files with only one type of comment (e.g., only a leading istanbul ignore hint) get an empty comment store, causing SWC wasm plugins to silently skip comment-driven transformations. The expected behavior is to enable the proxy when any comments are present.

highConfidence 95%Next.jsAffected V16.4.0-Canary.6

Origin Analysis

In `turbopack/crates/turbopack-ecmascript-plugins/src/transform/swc_ecma_transform_plugins.rs`, the condition for `should_enable_comments_proxy` uses logical AND (`&&`) instead of logical OR (`||`), requiring both leading and trailing comments to be non-empty before passing comments to SWC plugins.
1. Clone https://github.com/instagibb/turbopack-comments-repro 2. Run `npm run dev` with Turbopack (Next.js default) 3. Open http://localhost:3000/ and observe that the istanbul ignore hint in `leading-only.ts` is not honored (function is instrumented), while `with-trailing.ts` is correctly ignored. 4. Compare with `npm run dev:webpack` where both cases honor the hint.

Fixing Code Block

Edge Case Audit

Enabling the proxy for files with only one comment type may slightly increase overhead for those files and could expose plugins to comments they previously did not receive. Plugins that were written assuming comments only exist when both types are present might behave differently. Rollback is straightforward by reverting to `&&`, but this would reintroduce the silent failure for leading-only or trailing-only comments. No data loss or security risk is expected.

Ecosystem Topology