-
-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Labels
enhancementNew feature or requestNew feature or request
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
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request