Repository navigation
Conversation
|
Updated 12:47 PM PT - Jun 25th, 2026
❌ @robobun, your commit 304192b has 2 failures in
🧪 To try this PR locally: bunx bun-pr 30490That installs a local version of the PR into your bun-30490 --bun |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughFixes minifier instability where comment characters affected identifier renaming by accumulating character frequency deltas instead of overwriting, adding optional lexer comment-tracking initialization, and adding tests that assert identical minified output across comment variants. ChangesMinifier Output Stability
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/bundler/bundler_minify.test.ts`:
- Around line 1200-1242: Replace the direct Bun.build usage and the custom async
minify function with the test harness helper itBundled: move the entry content
into the itBundled files map (use "entry.js": source), pass minify: true in the
bundler options, and run two itBundled cases (or an itBundled that iterates
variants) to produce baseline and variant bundles; inside the itBundled callback
call the provided bundle/compile runner to get the output text and compare
outputs just like the current expectations (match outputs from the bundle for
variants.baseline and variants[variant]); update references to
tempDirWithFiles/minify/Bun.build to use the itBundled files/options and the
bundler callback instead.
- Around line 1204-1207: Replace the use of String.prototype.repeat when
constructing the test filler: change the filler variable (currently const filler
= "x".repeat(42)) to allocate a Buffer filled with 'x' and convert to string
using Buffer.alloc(42, "x").toString(), so tests use
Buffer.alloc(...).toString() for repetitive strings (affecting the filler used
in CharFreq.scanBig test).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ff1e4e43-db2d-4b66-8fcd-2c8902a71c6f
📒 Files selected for processing (4)
src/js_parser/ast/CharFreq.zigsrc/js_parser/ast/Parser.zigsrc/js_parser/lexer.zigtest/bundler/bundler_minify.test.ts
There was a problem hiding this comment.
The fix looks correct to me, but this touches the lexer init path that runs on every parse and changes minified output shape, and robobun reported build-zig failures on 50801ad (autofix commit's CI status not yet posted) — worth a human look before merging.
Extended reasoning...
Overview
This PR fixes #30489 by addressing two bugs in the minify renamer's character-frequency analysis: (A) scanBig in CharFreq.zig overwrote the histogram on each call instead of accumulating, and (B) track_comments was flipped on in P.init after Lexer.init had already consumed leading comments via step()/next(). The fix changes scanBig's final writes to element-wise @Vector adds, and adds Lexer.initWithTrackComments so Parser.init can set the flag before the first token is read. New tests in bundler_minify.test.ts assert byte-identical output across leading/mid/trailing comment variants.
Security risks
None. This is purely about which single-letter names the minifier picks; it does not affect parsing semantics, runtime behavior, or any trust boundary.
Level of scrutiny
Moderate-to-high. Although the diff is small and the logic is sound (I verified against computeCharacterFrequency in P.zig:991 — it does call scan() repeatedly with +1/-1 deltas, so accumulation is the correct semantics), the change sits on hot paths:
Parser.init→Lexer.initWithTrackCommentsruns for every file parsed (bundler and runtime transpiler). Whenminify_identifiersis false the new path is behaviorally identical to the oldinit, so risk is limited to minify builds, but it's still core parser plumbing.scanBignow does@Vector(26, i32)adds on slices of a stack-local copy of analign(1)buffer. The localvar freqs = out.*should get natural stack alignment so this is fine, but it's the kind of Zig SIMD detail a maintainer should eyeball.- The redundant
this.lexer.track_comments = ...assignments inP.zig:6804andParser.zig:188(toLazyExportAST) are now no-ops but were left in place — harmless, just worth noting.
Other factors
- robobun reported build-zig failures across ~17 platforms on 50801ad; an
autofix.cicommit (29058d4) followed, but its CI status hasn't been posted to the thread yet. I'd want green CI before this lands. - Changing the histogram math will shift which letters the renamer picks for all minified output, which could perturb snapshot tests elsewhere in the suite — another reason to wait for a full CI run.
- I previously left an inline note about a pre-existing off-by-one in
scanSmall's digit mapping (53 - '0'vs52 - '0'); that's a drive-by and not a blocker for this PR.
There was a problem hiding this comment.
All prior feedback addressed and the fix looks correct — deferring to a human since this touches Parser.init/lexer construction and changes minified-identifier output for every bundle (plus the hand-tuned bundler_npm.test.ts constants need CI to confirm).
Extended reasoning...
Overview
Fixes #30489: comments were leaking into the minify renamer's character-frequency histogram, causing identical code with different comments to produce different minified output. Two root causes fixed:
CharFreq.scanBigoverwrote the histogram on each call instead of accumulating — switched to@Vectorelement-wise adds so it matchesscanSmall. Also fixed a pre-existingscanSmalldigit off-by-one (53 - '0'→52 - '0') so both paths agree on slot layout.track_commentstiming: addedLexer.initWithTrackCommentsand threadedminify_identifiersthroughParser.initso the flag is set beforestep()/next()consume leading comments. The now-dead post-hoc assignments inP.zigandtoLazyExportASTwere removed and replaced with explanatory comments.
Tests: 7 itBundled variants (baseline + leading/mid/trailing × line/block comments, all ≥32 bytes to hit scanBig) pin the exact expected minified output. bundler_npm.test.ts ReactSSR mappings updated to the new identifier letters (Y1→nt, GJ++→ar++).
Security risks
None. This only affects which letters the minifier prefers for renamed identifiers; it never changes program semantics, and there's no untrusted input handling, auth, or crypto involved.
Level of scrutiny
Moderate. The histogram fix itself is straightforward and well-tested, but:
Parser.initruns for every parsed file, so the newinitWithTrackCommentspath is on the hot path (though it only adds one bool write before existingstep()/next()calls —init()now delegates withfalse, so non-minify callers are unchanged).- The change is intentionally user-visible: every
--minifybuild will now pick different (correct) identifier letters than before. That's the point of the fix, but it's a global output change. - The hand-updated
bundler_npm.test.tsconstants (nt,ar++, and the unchangedexpectExactFilesize: 221895) are derived from running the new build against React; CI on da107d1 should confirm they match.
Other factors
All seven of my earlier inline comments (scanSmall off-by-one, ReactSSR breakage, dead track_comments writes, comment wording ×2, hashbang leak note) have been addressed or acknowledged and resolved. CodeRabbit's two suggestions (use itBundled, use Buffer.alloc) were also applied. No outstanding review threads. The remaining hashbang/--> leak I flagged is pre-existing and reasonably out of scope.
Given the parser/lexer surface area and the global minifier-output change, a human should sign off rather than auto-approve.
|
Diff is green on the main test lane (debian-13-x64-asan-test-bun, windows-2019-x64-test-bun both ✅). CI has been flaking on unrelated infra/Windows-baseline lanes across the last three pushes — different lane fails each time (linux-x64-build-bun exit 128, then windows-x64-baseline-build-bun exit 1, now windows-2019-x64-baseline-test-bun exit 2). Out of re-rolls; PR needs a maintainer to review and merge. |
da107d1 to
c5877a9
Compare
|
Rebased onto main. Clean rebase (git followed the rewrite-in-rust file renames), but the bundler now runs through the Rust parser and my Zig-only fix didn't reach it — the CLI repro showed the bug again post-rebase. Ported the three changes to Rust in c5877a9:
(scan_big already accumulated correctly on the Rust side — the port carried that fix with a detailed note.) Zig fix retained so test_runner and anything else going through |
2437087 to
f8f930f
Compare
|
Gate keeps rejecting on an infra issue I can't fix from code:
ASAN exercises the same bundler path, and shows the correct before/after behavior. I've verified locally:
Diff is green on every check I can control. The gate's 'release without fix: all passed' is caused by a pre-existing release-build bug in main that leaves the gate's cached binary stale. A maintainer with access to fix bake-codegen or force-clean the cache can unblock this. |
f8f930f to
80784c0
Compare
80784c0 to
7f9a4d1
Compare
|
Rebased onto main again. Conflicts resolved:
Only the lexer.rs + parse_entry.rs plumbing remains Rust-side (char_freq scan fixes already on main). 45 bundler_minify tests pass; gate check verified locally (2 fail without fix, all pass with). |
|
CI: only My Already spent my one CI re-roll earlier in this PR's history, so not pushing another |
7f9a4d1 to
b1609f7
Compare
|
Rebased onto latest main (315ed50). Conflict in Heads up: #30489 is already fixed on main. I verified on a clean $ bun build --minify ./with-comment.js
var e=1,r=2,a=3,c=4,f=5,n=6;function o(){return e+r+a+c+f+n}export{o as go};
$ bun build --minify ./without-comment.js
var e=1,r=2,a=3,c=4,f=5,n=6;function o(){return e+r+a+c+f+n}export{o as go};So this PR's remaining diff is no compiled change — just:
The regression test is still worth landing as a guard against this regressing. But the src change that fixes the bug is already upstream, so the fail-before/pass-after gate no longer applies here (stashing this diff leaves the fix intact on main). A maintainer can merge this as a test-only addition, or close it if the test is considered redundant. All 46 |
b1609f7 to
98e98ef
Compare
There was a problem hiding this comment.
LGTM — after the rebases this is effectively test-only (7 itBundled regression cases for #30489) plus syncing the non-compiled .zig porting references to match the fix already shipping on main in the .rs.
Extended reasoning...
Overview
After several rebases the diff has converged to three files: src/ast/char_freq.zig (scanBig accumulate-not-overwrite + scanSmall 53→52 digit-slot fix + slot-layout comment), src/js_parser/parse/parse_entry.zig (Parser.init now mirrors parse_entry.rs:318-323 — initWithoutReading + set track_comments before the priming step()/next()), and test/bundler/bundler_minify.test.ts (7 itBundled variants pinning byte-identical minified output across leading/mid/trailing line- and block-comment placements). Per CLAUDE.md the .zig siblings are non-compiled porting references; the shipping fix already landed independently on main in the Rust parser, which the author verified against a clean origin/main build. So there is no compiled behavior change in this PR — it's a regression-test addition plus reference-file alignment.
Security risks
None. No auth, crypto, permissions, filesystem, network, or untrusted-input handling is touched. The only runtime-observable change is a new bundler test that asserts on minifier output.
Level of scrutiny
Low. The two .zig edits don't compile or ship and were brought line-for-line into agreement with the .rs that does (verified parse_entry.rs:318-323). The test addition follows the file's existing itBundled conventions, uses Buffer.alloc per the repo guideline, and carries a clear comment block linking #30489. The hardcoded expected output is intentional — pinning exact bytes is the point of the regression guard — and the author confirmed all 46 bundler_minify tests pass on clean main.
Other factors
No CODEOWNERS coverage for these paths. The bug-hunting pass found nothing. Every prior inline comment I left on this PR (scanSmall off-by-one, ReactSSR snapshot, dead track_comments writes, comment wording, initWithTrackComments Zig-only API, stale port-notes) has been addressed and the threads resolved or replied-to; the final commit (98e98ef) dropped the Zig-only constructor and reverted p.zig to main per the last round of feedback. The author noted a maintainer could alternatively close this as redundant since main already carries the fix — that's a project-management call, but from a code-correctness standpoint the regression test is a useful guard and the diff is safe to land.
…30489) Minified output used to shift based on comment contents because the character-frequency histogram driving identifier renaming double-counted comment text. That fix has since landed on main via the Rust parser rewrite; this adds the regression guard so it can't silently come back. Seven itBundled variants pin byte-identical minified output for a source with a 42-byte filler comment in leading / mid-file / trailing positions, in both line- and block-comment forms.
98e98ef to
304192b
Compare
|
Rebased onto latest main. main's #32621 ("Remove the .zig porting-reference sources") deleted The PR is now a clean single commit: just the #30489 regression test (+39 lines in Since the fix is upstream, this is purely a regression guard — the fail-before/pass-after gate doesn't apply (there's no src change to stash). Ready to merge as a test-only addition, or close if considered redundant. |
There was a problem hiding this comment.
LGTM — test-only regression guard for #30489; the fix itself already landed on main.
Extended reasoning...
Overview
After multiple rebases, this PR has been reduced to a single +39-line addition to test/bundler/bundler_minify.test.ts: seven itBundled cases (minify/CommentBleedIssue30489_*) that assert byte-identical minified output across baseline / leading / mid-file / trailing line- and block-comment variants. The underlying bundler fix (CharFreq histogram accumulation + early track_comments) shipped independently on main, and the .zig porting-reference files this PR previously touched were deleted by #32621 — so there is no source change left, only the regression test.
Security risks
None. This is pure test code with no runtime, auth, crypto, filesystem, or network surface; it just feeds string literals through the existing itBundled harness and asserts on output.
Level of scrutiny
Low. Test-only, additive, and follows the established itBundled conventions used throughout the rest of this file. The expected-output string is intentionally pinned so any future histogram regression fails loudly. The test is self-contained (no fixtures, no subprocess spawning beyond what itBundled does internally) and uses Buffer.alloc().toString() per repo guidelines.
Other factors
All prior review threads (mine and CodeRabbit's) are resolved — the itBundled migration, Buffer.alloc swap, comment-wording nits, and .zig/.rs alignment concerns were either addressed in earlier commits or rendered moot when the .zig reference files were removed and the Rust-side fix landed upstream. The bug-hunting pass found nothing on the current revision. The author has verified all 7 variants pass on current main.
|
#30489 was fixed on main separately: the scan_big accumulation fix shipped with the Rust parser (#30412), and track_comments has been set before the first token is read since #32504. This PR had already been reduced to the regression test, and all 7 minify/CommentBleedIssue30489_* cases pass on current main (165dc9f). Closing. |
Problem
bun build --minifyproduces different output for the same code depending on whether (and what) comments appear in the source. From #30489:The letter chosen for each renamed identifier tracked the contents of the leading comment — stuff it with 42
qs and the output startedvar q=1,….Cause
Two independent bugs in the character-frequency analysis that drives minified-identifier naming:
A.
scanBig/scan_bigoverwrote the histogramcomputeCharacterFrequencycallsscan()once for the source text (+1), then once per comment and import path (-1) to subtract them back out. For text>= 32bytes the code routes toscanBig, which did:scanSmall(the short-text path) correctly doesfreqs[i] += delta.scanBigwiped the buffer on every call, so any comment of 32+ bytes clobbered whatever the source-text scan had accumulated.Fixed by switching the four final writes to element-wise
@Vectoradds soscanBigaccumulates likescanSmalldoes. (The rewrite-in-rust port already carries this fix with a detailed port-note, so only the Zig side needed updating.)B.
track_commentsflipped on too late to see leading commentsjs_lexer.Lexer.initcallsstep() + next()at construction, which consumes any comments at the top of the file beforetrack_commentsflips on.scanCommentTextonly appends toall_commentswhen the flag is true, so those leading comments were never recorded and never subtracted from the histogram.Fixed by adding
initWithTrackComments(Zig) /init_with_track_comments(Rust) that sets the flag before reading the first token, and threadingminify_identifiersthrough fromParser.init.Drive-by:
scanSmalldigit off-by-onePre-existing:
scanSmallmapped'0'..'9'to histogram slots 53..62, colliding'9'with'_'at slot 62;scanBigalready used the correct 52..61. Fixed in both Zig and Rust so the two paths agree onNameMinifier::DEFAULT_TAIL's slot layout.Verification
Byte-identical across all comment placements. Tests in
test/bundler/bundler_minify.test.tscover leading / mid-file / trailing comments in both line- and block-comment forms, all padded to force thescanBigpath.Rebase note
Rebased onto main (clean — no textual conflicts; git followed the file renames from the rewrite-in-rust commit). After rebase, the CLI reproducer showed the leading-comment leak was back — the bundler now parses through the Rust port, so the Zig-only fix didn't reach it. Ported all three changes to
src/js_parser/lexer.rs,src/js_parser/parse/parse_entry.rs, andsrc/ast/char_freq.rsso both parsers stay in sync. The Zig fix is retained.Fixes #30489.