fix(bundler): add missing semicolons in minified bun module imports (#26372)

## Summary
- Fix missing semicolons in minified output when using both default and
named imports from `"bun"` module
- The issue occurred in `printInternalBunImport` when transitioning
between star_name, default_name, and items sections without flushing
pending semicolons

## Test plan
- Added regression tests in `test/regression/issue/26371.test.ts`
covering:
  - Default + named imports (`import bun, { embeddedFiles } from "bun"`)
- Namespace + named imports (`import * as bun from "bun"; import {
embeddedFiles } from "bun"`)
  - Namespace + default + named imports combination
- Verified test fails with `USE_SYSTEM_BUN=1` (reproduces bug)
- Verified test passes with `bun bd test` (fix works)

Fixes #26371

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
robobun
2026-01-23 23:09:01 -08:00
committed by GitHub
parent f88f60af5a
commit 4680e89a91
2 changed files with 62 additions and 3 deletions

View File

@@ -1109,15 +1109,15 @@ describe("bundler", () => {
"/entry.js": /* js */ `
// Test all equality operators with typeof undefined
console.log(typeof x !== 'undefined');
console.log(typeof x != 'undefined');
console.log(typeof x != 'undefined');
console.log('undefined' !== typeof x);
console.log('undefined' != typeof x);
console.log(typeof x === 'undefined');
console.log(typeof x == 'undefined');
console.log('undefined' === typeof x);
console.log('undefined' == typeof x);
// These should not be optimized
console.log(typeof x === 'string');
console.log(x === 'undefined');
@@ -1135,4 +1135,61 @@ describe("bundler", () => {
);
},
});
// https://github.com/oven-sh/bun/issues/26371
// Minified bundler output missing semicolon between statements when
// using both default and named imports from "bun" module
itBundled("minify/BunImportSemicolonInsertion", {
files: {
"/entry.js": /* js */ `
import bun, { embeddedFiles } from "bun"
console.log(typeof embeddedFiles)
console.log(typeof bun.argv)
`,
},
minifySyntax: true,
minifyWhitespace: true,
minifyIdentifiers: true,
target: "bun",
run: {
stdout: "object\nobject",
},
});
itBundled("minify/BunImportNamespaceAndNamed", {
files: {
"/entry.js": /* js */ `
import * as bun from "bun"
import { embeddedFiles } from "bun"
console.log(typeof embeddedFiles)
console.log(typeof bun.argv)
`,
},
minifySyntax: true,
minifyWhitespace: true,
minifyIdentifiers: true,
target: "bun",
run: {
stdout: "object\nobject",
},
});
itBundled("minify/BunImportDefaultNamespaceAndNamed", {
files: {
"/entry.js": /* js */ `
import bun, * as bunNs from "bun"
import { embeddedFiles } from "bun"
console.log(typeof embeddedFiles)
console.log(typeof bun.argv)
console.log(typeof bunNs.argv)
`,
},
minifySyntax: true,
minifyWhitespace: true,
minifyIdentifiers: true,
target: "bun",
run: {
stdout: "object\nobject\nobject",
},
});
});