Skip to content

fix(bundler): don't let comments leak into minify renamer - #30490

Closed
robobun wants to merge 1 commit into
mainfrom
farm/caaeb90e/minify-comment-bleed-30489
Closed

robobun wants to merge 1 commit into
mainfrom
farm/caaeb90e/minify-comment-bleed-30489

Conversation

@robobun

@robobun robobun commented May 11, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

bun build --minify produces different output for the same code depending on whether (and what) comments appear in the source. From #30489:

$ bun build --minify ./with-comment.js
var x=1,e=2,r=3,a=4,c=5,f=6;function n(){return x+e+r+a+c+f}export{n 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};

The letter chosen for each renamed identifier tracked the contents of the leading comment — stuff it with 42 qs and the output started var q=1,….

Cause

Two independent bugs in the character-frequency analysis that drives minified-identifier naming:

A. scanBig/scan_big overwrote the histogram

computeCharacterFrequency calls scan() once for the source text (+1), then once per comment and import path (-1) to subtract them back out. For text >= 32 bytes the code routes to scanBig, which did:

freqs[0..26].* = deltas['a' .. 'a' + 26].*;   // overwrite, not +=

scanSmall (the short-text path) correctly does freqs[i] += delta. scanBig wiped 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 @Vector adds so scanBig accumulates like scanSmall does. (The rewrite-in-rust port already carries this fix with a detailed port-note, so only the Zig side needed updating.)

B. track_comments flipped on too late to see leading comments

js_lexer.Lexer.init calls step() + next() at construction, which consumes any comments at the top of the file before track_comments flips on. scanCommentText only appends to all_comments when 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 threading minify_identifiers through from Parser.init.

Drive-by: scanSmall digit off-by-one

Pre-existing: scanSmall mapped '0'..'9' to histogram slots 53..62, colliding '9' with '_' at slot 62; scanBig already used the correct 52..61. Fixed in both Zig and Rust so the two paths agree on NameMinifier::DEFAULT_TAIL's slot layout.

Verification

$ 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};

Byte-identical across all comment placements. Tests in test/bundler/bundler_minify.test.ts cover leading / mid-file / trailing comments in both line- and block-comment forms, all padded to force the scanBig path.

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, and src/ast/char_freq.rs so both parsers stay in sync. The Zig fix is retained.

Fixes #30489.

@robobun

robobun commented May 11, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 12:47 PM PT - Jun 25th, 2026

❌ @robobun, your commit 304192b has 2 failures in Build #64665 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 30490

That installs a local version of the PR into your bun-30490 executable, so you can run:

bun-30490 --bun

Comment thread src/ast/char_freq.zig Resolved
@coderabbitai

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Fixes 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.

Changes

Minifier Output Stability

Layer / File(s) Summary
Character Frequency Accumulation
src/js_parser/ast/CharFreq.zig
scanBig now accumulates character frequency deltas into existing histogram buckets instead of overwriting them; scanSmall documents the bucket layout used by both scanning paths.
Lexer Comment Tracking Setup
src/js_parser/lexer.zig
New initWithTrackComments public function sets track_comments before lexing begins, allowing leading comments to be scanned when enabled. Existing init() delegates to it with comment tracking disabled.
Parser Lexer Wiring
src/js_parser/ast/Parser.zig
Parser.init now calls js_lexer.Lexer.initWithTrackComments and passes _options.features.minify_identifiers to enable comment tracking only when identifier minification is active; toLazyExportAST no longer mutates or depends on p.lexer.track_comments.
Parser NewParser Note
src/js_parser/ast/P.zig
NewParser_'s init no longer sets this.lexer.track_comments; assumes lexer was already configured to capture leading comments.
Test Coverage
test/bundler/bundler_minify.test.ts
Adds regression test for #30489: constructs variants with a 42-byte filler in leading/trailing/mid-file line and block comments and asserts the minified /out.js is byte-identical to the baseline for every variant.
Sourcemap Snapshot
test/bundler/bundler_npm.test.ts
Updates two mappings entries in the entry.js.map snapshot for the npm/ReactSSR test.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(bundler): don't let comments leak into minify renamer' clearly and specifically summarizes the primary change: preventing comments from affecting minified identifier naming.
Linked Issues check ✅ Passed All code changes directly address issue #30489: CharFreq.zig accumulation fix prevents histogram overwrites, lexer timing fix ensures leading comments are tracked, and tests verify output stability across comment variations.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the comment-bleed bug: CharFreq.zig, Parser.zig, lexer.zig, P.zig contain core fixes; regression test covers the issue; bundler_npm.test.ts updates reflect expected output shifts from the histogram fix.
Description check ✅ Passed The PR description comprehensively covers the problem, root causes, fix details, and verification. Both required sections (What/How) are present with substantial technical depth.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 450072b and 29058d4.

📒 Files selected for processing (4)
  • src/js_parser/ast/CharFreq.zig
  • src/js_parser/ast/Parser.zig
  • src/js_parser/lexer.zig
  • test/bundler/bundler_minify.test.ts

Comment thread test/bundler/bundler_minify.test.ts Resolved
Comment thread test/bundler/bundler_minify.test.ts Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.initWithTrackComments runs for every file parsed (bundler and runtime transpiler). When minify_identifiers is false the new path is behaviorally identical to the old init, so risk is limited to minify builds, but it's still core parser plumbing.
  • scanBig now does @Vector(26, i32) adds on slices of a stack-local copy of an align(1) buffer. The local var 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 in P.zig:6804 and Parser.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.ci commit (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' vs 52 - '0'); that's a drive-by and not a blocker for this PR.

Comment thread src/ast/char_freq.zig Resolved
Comment thread src/js_parser/parse/parse_entry.zig Resolved
Comment thread test/bundler/bundler_minify.test.ts Resolved
Comment thread src/js_parser/ast/Parser.zig Resolved
Comment thread src/js_parser/lexer.zig Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. CharFreq.scanBig overwrote the histogram on each call instead of accumulating — switched to @Vector element-wise adds so it matches scanSmall. Also fixed a pre-existing scanSmall digit off-by-one (53 - '0' → 52 - '0') so both paths agree on slot layout.
  2. track_comments timing: added Lexer.initWithTrackComments and threaded minify_identifiers through Parser.init so the flag is set before step()/next() consume leading comments. The now-dead post-hoc assignments in P.zig and toLazyExportAST were 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.init runs for every parsed file, so the new initWithTrackComments path is on the hot path (though it only adds one bool write before existing step()/next() calls — init() now delegates with false, so non-minify callers are unchanged).
  • The change is intentionally user-visible: every --minify build 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.ts constants (nt, ar++, and the unchanged expectExactFilesize: 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.

@robobun

robobun commented May 11, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@robobun
robobun force-pushed the farm/caaeb90e/minify-comment-bleed-30489 branch from da107d1 to c5877a9 Compare May 14, 2026 13:28
@robobun

robobun commented May 14, 2026

Copy link
Copy Markdown
Collaborator Author

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:

  • src/ast/char_freq.rs — scan_small digit off-by-one (53 → 52)
  • src/js_parser/lexer.rs — new init_with_track_comments
  • src/js_parser/parse/parse_entry.rs — Parser::init threads features.minify_identifiers

(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 bun.js_parser benefits. All 39 bundler_minify tests + ReactSSR pass locally.

Comment thread src/js_parser/p.zig Resolved
Comment thread src/ast/char_freq.zig Resolved
@robobun
robobun force-pushed the farm/caaeb90e/minify-comment-bleed-30489 branch 2 times, most recently from 2437087 to f8f930f Compare May 14, 2026 13:57
@robobun

robobun commented May 14, 2026

Copy link
Copy Markdown
Collaborator Author

Gate keeps rejecting on an infra issue I can't fix from code:

  • ASAN without fix: 2 failures (expected — proves test exercises the bug)
  • ASAN with fix: all pass (expected — fix works)
  • release without fix: passes against cached c5877a9 release binary (which contains the fix — only the cached binary means the 'without fix' result is wrong)
  • release with fix: release build itself fails, not tests — bake-codegen can't bundle hmr-runtime-{client,server,error}.ts because the CSS define (OVERLAY_CSS) is being mis-parsed as JSON. Reproduces on origin/main at 19d8ade with no changes from this branch — it's a pre-existing defect in the bake codegen on main, unrelated to bun build --minify produces different output for the same code depending on comments #30489.

ASAN exercises the same bundler path, and shows the correct before/after behavior. I've verified locally:

  • git reset --mixed HEAD~1 && git stash push -- src/ + bun bd test bundler_minify: 2 tests fail
  • pop + build + test: all pass

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.

Comment thread src/js_parser/parse/parse_entry.rs Resolved
@robobun
robobun force-pushed the farm/caaeb90e/minify-comment-bleed-30489 branch from f8f930f to 80784c0 Compare May 17, 2026 11:33
Comment thread src/ast/char_freq.zig Resolved
@robobun
robobun force-pushed the farm/caaeb90e/minify-comment-bleed-30489 branch from 80784c0 to 7f9a4d1 Compare June 3, 2026 05:44
@robobun

robobun commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

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).

@robobun

robobun commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI: only debian-13-x64-baseline-test-bun is red (exit 2). The same platform's non-baseline (debian-13-x64-test-bun) and ASAN (debian-13-x64-asan-test-bun) lanes both pass, as do all aarch64, Windows, macOS, Alpine, and Ubuntu test lanes (14/15 green).

My bundler_minify.test.ts tests pass on debian-13-x64 and debian-13-x64-asan, so the baseline-only failure is an unrelated flaky test on that single lane — the diff here is pure parser logic (comment tracking + histogram slot layout), nothing CPU-baseline-specific.

Already spent my one CI re-roll earlier in this PR's history, so not pushing another ci: retrigger. Diff is green on every lane I can control and verified locally (45 bundler_minify tests pass; gate check confirms 2 fail without the fix, all pass with it). Needs a maintainer to re-run the flaky baseline lane or merge.

@robobun
robobun force-pushed the farm/caaeb90e/minify-comment-bleed-30489 branch from 7f9a4d1 to b1609f7 Compare June 20, 2026 22:12
@robobun

robobun commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto latest main (315ed50). Conflict in src/js_parser/parse/parse_entry.rs: main has independently implemented the same leading-comment fix — it now sets lexer.track_comments = options.features.minify_identifiers on init_without_reading before step()/next(), plus the scan_big/scan_small histogram fixes in char_freq.rs landed earlier. Took main's version and dropped my now-redundant init_with_track_comments wrapper, so lexer.rs and parse_entry.rs match main exactly.

Heads up: #30489 is already fixed on main. I verified on a clean origin/main build (no changes from this branch) that both the leading-comment case and the baseline now minify to byte-identical output:

$ 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:

  1. the test/bundler/bundler_minify.test.ts regression test for bun build --minify produces different output for the same code depending on comments #30489 (7 variants, passes on clean main), and
  2. keeping the .zig porting-reference files in sync with the Rust fix.

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 bundler_minify tests pass locally.

Comment thread src/js_parser/lexer.zig Resolved
@robobun
robobun force-pushed the farm/caaeb90e/minify-comment-bleed-30489 branch from b1609f7 to 98e98ef Compare June 20, 2026 22:40

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@robobun
robobun force-pushed the farm/caaeb90e/minify-comment-bleed-30489 branch from 98e98ef to 304192b Compare June 25, 2026 19:09
@robobun

robobun commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto latest main. main's #32621 ("Remove the .zig porting-reference sources") deleted char_freq.zig, lexer.zig, and parse_entry.zig — the files my reference-sync changes were touching. So those changes are now moot, and I resolved the modify/delete conflicts by accepting the deletions.

The PR is now a clean single commit: just the #30489 regression test (+39 lines in test/bundler/bundler_minify.test.ts). The actual bug fix (comment text no longer double-counted in the minify char-frequency histogram) already shipped on main via the Rust parser rewrite. I re-verified on current main (d451445): all 7 CommentBleedIssue30489_* variants pass.

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.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@robobun

robobun commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

#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.

@robobun robobun closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bun build --minify produces different output for the same code depending on comments

1 participant