swc-project / swc-project/plugins
[Feature Request] Dead code elimination for assert statements in production builds
@kdy1 is already working on this.
Since Jan 14, 2026.
- Dominant language
- Rust
- Stars
- 389
- Forks
- 106
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
Describe the feature
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:
{
"jsc": {
"transform": {
"optimizer": {
"removeAsserts": true
}
}
}
}
Or via define to replace assert with a no-op that can be tree-shaken.
Alternatives considered:
Using process.env.NODE_ENV checks manually
Babel plugin (babel-plugin-unassert)
Custom SWC plugin
Babel plugin or link to the feature description
No response
Additional context
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.