diff --git a/src/js_printer.zig b/src/js_printer.zig index 09b3bfdbbf8d4..486f94e23bb50 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -6036,7 +6036,8 @@ pub fn printWithWriterAndPlatform( comptime generate_source_maps: bool, ) PrintResult { const PrinterType = NewPrinter( - false, + // if it's bun, it is also ascii_only + is_bun_platform, Writer, false, is_bun_platform, diff --git a/test/bundler/bundler_compile.test.ts b/test/bundler/bundler_compile.test.ts index 70c2827656d00..1fdada5873270 100644 --- a/test/bundler/bundler_compile.test.ts +++ b/test/bundler/bundler_compile.test.ts @@ -220,4 +220,13 @@ describe("bundler", () => { }, run: { stdout: "Hello, world!", setCwd: true }, }); + itBundled("compile/Utf8", { + compile: true, + files: { + "/entry.ts": /* js */ ` + console.log(JSON.stringify({\u{6211}: "\u{6211}"})); + `, + }, + run: { stdout: '{"\u{6211}":"\u{6211}"}' }, + }); }); diff --git a/test/regression/issue/09559.test.ts b/test/regression/issue/09559.test.ts new file mode 100644 index 0000000000000..9177085602db2 --- /dev/null +++ b/test/regression/issue/09559.test.ts @@ -0,0 +1,24 @@ +import { $ } from "bun"; +import { expect, test } from "bun:test"; +import { bunEnv, bunExe, tempDirWithFiles } from "harness"; +import { readdirSync } from "node:fs"; +import { join } from "path"; + +test("bun build --target bun should support non-ascii source", async () => { + const files = { + "index.js": ` + console.log(JSON.stringify({\u{6211}: "a"})); + + const \u{6211} = "b"; + console.log(JSON.stringify({\u{6211}})); + `, + }; + const filenames = Object.keys(files); + const source = tempDirWithFiles("source", files); + + $.throws(true); + await $`${bunExe()} build --target bun ${join(source, "index.js")} --outfile ${join(source, "bundle.js")}`; + const result = await $`${bunExe()} ${join(source, "bundle.js")}`.text(); + + expect(result).toBe(`{"\u{6211}":"a"}\n{"\u{6211}":"b"}\n`); +});