Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tagged template literal with unicode #15047

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/bun.js/RuntimeTranspilerCache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
/// Version 11: Fix \uFFFF printing regression
/// Version 12: "use strict"; makes it CommonJS if we otherwise don't know which one to pick.
/// Version 13: Hoist `import.meta.require` definition, see #15738
const expected_version = 13;
/// Version 14: Emits utf-16 files in rare cases
const expected_version = 14;

const bun = @import("root").bun;
const std = @import("std");
Expand Down Expand Up @@ -633,14 +634,14 @@ pub const RuntimeTranspilerCache = struct {
return;
}
bun.assert(this.entry == null);
const output_code = bun.String.createLatin1(output_code_bytes);
const output_code = bun.String.createLatin1OrUTF8(output_code_bytes);
this.output_code = output_code;

toFile(this.input_byte_length.?, this.input_hash.?, this.features_hash.?, sourcemap, output_code, this.exports_kind) catch |err| {
debug("put() = {s}", .{@errorName(err)});
return;
};
if (comptime bun.Environment.allow_assert)
debug("put() = {d} bytes", .{output_code.latin1().len});
debug("put() = {d} bytes", .{output_code.length()});
}
};
10 changes: 5 additions & 5 deletions src/bun.js/module_loader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ pub const RuntimeTranspilerStore = struct {
const bytecode_slice = parse_result.already_bundled.bytecodeSlice();
this.resolved_source = ResolvedSource{
.allocator = null,
.source_code = bun.String.createLatin1(parse_result.source.contents),
.source_code = bun.String.createLatin1OrUTF8(parse_result.source.contents),
.already_bundled = true,
.hash = 0,
.bytecode_cache = if (bytecode_slice.len > 0) bytecode_slice.ptr else null,
Expand Down Expand Up @@ -657,7 +657,7 @@ pub const RuntimeTranspilerStore = struct {
const source_code = brk: {
const written = printer.ctx.getWritten();

const result = cache.output_code orelse bun.String.createLatin1(written);
const result = cache.output_code orelse bun.String.createLatin1OrUTF8(written);

if (written.len > 1024 * 1024 * 2 or vm.smol) {
printer.ctx.buffer.deinit();
Expand Down Expand Up @@ -1439,7 +1439,7 @@ pub const ModuleLoader = struct {

return ResolvedSource{
.allocator = null,
.source_code = bun.String.createLatin1(printer.ctx.getWritten()),
.source_code = bun.String.createLatin1OrUTF8(printer.ctx.getWritten()),
.specifier = String.init(specifier),
.source_url = String.init(path.text),
.is_commonjs_module = parse_result.ast.has_commonjs_export_names or parse_result.ast.exports_kind == .cjs,
Expand Down Expand Up @@ -1774,7 +1774,7 @@ pub const ModuleLoader = struct {
const bytecode_slice = parse_result.already_bundled.bytecodeSlice();
return ResolvedSource{
.allocator = null,
.source_code = bun.String.createLatin1(parse_result.source.contents),
.source_code = bun.String.createLatin1OrUTF8(parse_result.source.contents),
.specifier = input_specifier,
.source_url = input_specifier.createIfDifferent(path.text),
.already_bundled = true,
Expand Down Expand Up @@ -1932,7 +1932,7 @@ pub const ModuleLoader = struct {
.allocator = null,
.source_code = brk: {
const written = printer.ctx.getWritten();
const result = cache.output_code orelse bun.String.createLatin1(written);
const result = cache.output_code orelse bun.String.createLatin1OrUTF8(written);

if (written.len > 1024 * 1024 * 2 or jsc_vm.smol) {
printer.ctx.buffer.deinit();
Expand Down
Loading