Skip to content

Commit

Permalink
Fix bundling for bun not using ascii_only (#9571)
Browse files Browse the repository at this point in the history
* Fix bundling not using ascii_only

* add utf8 test to bundler_compile & make test source ascii

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and zackradisic committed Mar 25, 2024
1 parent 0b5b43f commit 3e7a25c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/js_printer.zig
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions test/bundler/bundler_compile.test.ts
Expand Up @@ -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}"}' },
});
});
24 changes: 24 additions & 0 deletions 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`);
});

0 comments on commit 3e7a25c

Please sign in to comment.