diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig index 41b60234bb..e792d33944 100644 --- a/src/bun.js/api/JSTranspiler.zig +++ b/src/bun.js/api/JSTranspiler.zig @@ -199,7 +199,7 @@ pub const TransformTask = struct { if (printed > 0) { buffer_writer = printer.ctx; buffer_writer.buffer.list.items = buffer_writer.written; - this.output_code = bun.String.createLatin1(buffer_writer.written); + this.output_code = bun.String.createUTF8(buffer_writer.written); } else { this.output_code = bun.String.empty; } diff --git a/test/bundler/transpiler/transpiler.test.js b/test/bundler/transpiler/transpiler.test.js index 3336ccc15a..9f49e13b10 100644 --- a/test/bundler/transpiler/transpiler.test.js +++ b/test/bundler/transpiler/transpiler.test.js @@ -3235,6 +3235,40 @@ console.log(foo, array); expect(exports[1]).toBe("default"); expect(exports).toHaveLength(3); }); + + it("#17961 - node target", async () => { + // Issue #17961: Transpiler encoding issue with UTF-8 characters + const transpiler = new Bun.Transpiler({ + loader: "ts", + target: "node", + }); + + const input = `let list = ["•", "-", "◦", "▪", "▫"];`; + const result = await transpiler.transform(input); + expect(result).toBe(`let list = ["•", "-", "◦", "▪", "▫"];\n`); + }); + + it("#17961 - browser target", async () => { + const transpiler = new Bun.Transpiler({ + loader: "ts", + target: "browser", + }); + + const input = `let list = ["•", "-", "◦", "▪", "▫"];`; + const result = await transpiler.transform(input); + expect(result).toBe(`let list = ["•", "-", "◦", "▪", "▫"];\n`); + }); + + it("#17961 - bun target", async () => { + const transpiler = new Bun.Transpiler({ + loader: "ts", + target: "bun", + }); + + const input = `let list = ["•", "-", "◦", "▪", "▫"];\n`; + const result = await transpiler.transform(input); + expect(result).toBe(`let list = [\"\\u2022\", \"-\", \"\\u25E6\", \"\\u25AA\", \"\\u25AB\"];\n`); + }); }); describe("edge cases", () => {