Fix transpiler encoding issue (#18057)

This commit is contained in:
ippsav
2025-03-12 20:58:53 +00:00
committed by GitHub
parent b3246b6971
commit 96fa32bcc1
2 changed files with 35 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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", () => {