From 4680e89a915f5a6aee4ebb3fde794792bd48f69b Mon Sep 17 00:00:00 2001 From: robobun Date: Fri, 23 Jan 2026 23:09:01 -0800 Subject: [PATCH] fix(bundler): add missing semicolons in minified bun module imports (#26372) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 Co-authored-by: Claude Opus 4.5 --- src/js_printer.zig | 2 + test/bundler/bundler_minify.test.ts | 63 +++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/js_printer.zig b/src/js_printer.zig index 9ba58ad1c5..0431180838 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -964,6 +964,7 @@ fn NewPrinter( } if (import.default_name) |default| { + p.printSemicolonIfNeeded(); p.print("var "); p.printSymbol(default.ref.?); if (comptime Statement == void) { @@ -984,6 +985,7 @@ fn NewPrinter( } if (import.items.len > 0) { + p.printSemicolonIfNeeded(); p.printWhitespacer(ws("var {")); if (!import.is_single_line) { diff --git a/test/bundler/bundler_minify.test.ts b/test/bundler/bundler_minify.test.ts index 0865d9a372..66fa487207 100644 --- a/test/bundler/bundler_minify.test.ts +++ b/test/bundler/bundler_minify.test.ts @@ -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", + }, + }); });