fix(transpiler): parse minifySyntax and minifyIdentifiers as top-level Bun.Transpiler options#28714
fix(transpiler): parse minifySyntax and minifyIdentifiers as top-level Bun.Transpiler options#28714
Conversation
…l Bun.Transpiler options
minifyWhitespace was already accepted as a top-level option on Bun.Transpiler,
but minifySyntax and minifyIdentifiers were silently ignored when passed as
top-level keys. They only worked via minify: { syntax: true } or minify: true.
This caused if ("a" === "b") { ... } to not be DCE'd when using
new Bun.Transpiler({ minifySyntax: true }) — the comparison would fold to
false but the empty if(false){} skeleton remained because minify_syntax
was never actually set on the parser options.
There was a problem hiding this comment.
Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.
Once credits are available, push a new commit or reopen this pull request to trigger a review.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdds top-level minification flags to the transpiler config, expands strict-equality folding logic in expressions, and introduces tests covering minification combined with dead-code elimination and constant-folding behaviors. Changes
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
With strict equality (===), values of different types are never equal. The eql() function was missing cases for: - boolean === string (e.g. true === 'x') - number === string (e.g. 42 === 'x') - string === boolean (e.g. 'x' === true) These returned Equality.unknown instead of Equality.false, preventing DCE when --define substitutes a value of a different type than the comparison target.
Problem
Two issues preventing string comparison DCE:
1.
Bun.TranspilerignoredminifySyntaxtop-level optionBun.TranspileracceptedminifyWhitespaceas a top-level option but silently ignoredminifySyntaxandminifyIdentifiers. They only worked viaminify: { syntax: true }orminify: true.This meant
new Bun.Transpiler({ minifySyntax: true })did not enable syntax minification —if ("a" === "b") { ... }folded the comparison tofalsebut left the emptyif(false){}skeleton.2. Cross-type strict equality not folded in bundler
The
eql()function was missing cases for strict equality between different primitive types:boolean === string(e.g.true === "x")number === string(e.g.42 === "x")string === boolean(e.g."x" === true)These returned
Equality.unknowninstead ofEquality.false, preventing DCE when--definesubstitutes a value of a different type than the comparison target.Fix
minifySyntaxandminifyIdentifiersas top-level config keys inJSTranspiler.zigExpr.zigeql()functionVerification
USE_SYSTEM_BUN=1 bun test→ 11/12 failbun bd test→ 12/12 pass