[Feature Request] Dead code elimination for assert statements in production builds
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
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
- 主要语言
- Rust
- 星标
- 387
- 派生
- 111
- 平均合并
- 3 小时 40 分钟
- 30 天内合并 PR
- 18
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
swc-project/plugins 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 57/100
swc-project/plugins#691 ·
维护者通常 1 天内回复
-
graphql-codegen-client-preset: inline calls, the leftover tag import, and name-only matching keep the document map in bundles可能已有人在做 @kdy1 于 27 天前认领。 未关闭
swc-project/plugins#687 · 已指派 1 人 ·
维护者通常 1 天内回复
-
`mut-cjs-exports` doesn't properly handle circular imports with barrel files可能重新可做 @kdy1 于 253 天前认领,目前没有进行中的 PR。 未关闭
swc-project/plugins#577 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 35/100
swc-project/plugins#214 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 10/100
swc-project/plugins#147 ·
维护者通常 1 天内回复
查看 swc-project/plugins 的全部 Issue
相似的 Issue
-
bug good first issue web
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
triage: not actionable
难度 2/5 1-3 小时 新手友好度 66/100
oxc-project/oxc#30518 · 1 条评论 ·
维护者通常 1 天内回复
-
area: panel
难度 2/5 1-3 小时 新手友好度 68/100
frandev94/shattered-islands#98 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复