You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] Dead code elimination for assert statements in production builds #574
It would be useful to have an option to strip assert statements during production builds, similar to how other languages handle assertions (e.g., Python's -O flag, C's NDEBUG).
Use case:
import assert from 'assert';
function divide(a, b) {
assert(b !== 0, 'Division by zero');
return a / b;
}
In development, assertions help catch bugs early. In production, they add unnecessary overhead and bundle size.
Proposed solution:
A configuration option in .swcrc:
It should be straightforward to implement. You can simply fork the existing remove-console plugin and make a few small adjustments to compile it as a Wasm plugin.
It should be straightforward to implement. You can simply fork the existing remove-console plugin and make a few small adjustments to compile it as a Wasm plugin.
Thanks for the pointer! I'll check out the remove-console plugin and use it as a reference.
Activity
kdy1 commentedon Jan 14, 2026
I think this should be a Wasm plugin. Are you fine with that?
magic-akari commentedon Jan 14, 2026
It should be straightforward to implement. You can simply fork the existing remove-console plugin and make a few small adjustments to compile it as a Wasm plugin.
chunghyunleeme commentedon Jan 15, 2026
Sure, a Wasm plugin sounds good to me. I'll give it a try.
chunghyunleeme commentedon Jan 15, 2026
Thanks for the pointer! I'll check out the remove-console plugin and use it as a reference.
feat: Add remove-assert plugin for SWC
kdy1 commentedon Jan 19, 2026
Claude (@claude) fix it
claude commentedon Jan 19, 2026
feat(remove-assert): Add SWC plugin for removing assert statements
kdy1 commentedon Feb 5, 2026
Claude (@claude) Implement it.
claude commentedon Feb 5, 2026
Claude finished Donny/강동윤 (@kdy1)'s task in 5m 32s —— View job •
claude/issue-574-20260205-2359• Create PR ➔Implementation Complete! ✅
Successfully implemented the
@swc/plugin-remove-assertWasm plugin for dead code elimination of assert statements in production builds.Tasks
What was implemented
Plugin capabilities:
assert()callsassert.method()calls (e.g.,assert.strictEqual,assert.deepEqual)excludeoption to preserve specific assert methodsremove-consolepluginFiles created:
Usage example:
{ "jsc": { "experimental": { "plugins": [ ["@swc/plugin-remove-assert", {}] ] } } }Or with exclusions:
{ "jsc": { "experimental": { "plugins": [ ["@swc/plugin-remove-assert", { "exclude": ["strictEqual"] }] ] } } }Example transformation:
Input:
Output:
--- | Branch: claude/issue-574-20260205-2359
feat: Add remove-assert plugin for dead code elimination