aboutsummaryrefslogtreecommitdiff
path: root/src/bundler/entry_points.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bundler/entry_points.zig')
-rw-r--r--src/bundler/entry_points.zig32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/bundler/entry_points.zig b/src/bundler/entry_points.zig
index 5e8310d92..9101cef08 100644
--- a/src/bundler/entry_points.zig
+++ b/src/bundler/entry_points.zig
@@ -6,6 +6,7 @@ const Fs = @import("../fs.zig");
const js_ast = bun.JSAst;
const Bundler = bun.Bundler;
const strings = bun.strings;
+
pub const FallbackEntryPoint = struct {
code_buffer: [8096]u8 = undefined,
path_buffer: [bun.MAX_PATH_BYTES]u8 = undefined,
@@ -156,6 +157,25 @@ pub const ClientEntryPoint = struct {
}
};
+const QuoteEscapeFormat = struct {
+ data: []const u8,
+
+ pub fn format(self: QuoteEscapeFormat, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
+ var i: usize = 0;
+ while (std.mem.indexOfAnyPos(u8, self.data, i, "\"\n\\")) |j| : (i = j + 1) {
+ try writer.writeAll(self.data[i..j]);
+ try writer.writeAll(switch (self.data[j]) {
+ '"' => "\\\"",
+ '\n' => "\\n",
+ '\\' => "\\\\",
+ else => unreachable,
+ });
+ }
+ if (i == self.data.len) return;
+ try writer.writeAll(self.data[i..]);
+ }
+};
+
pub const ServerEntryPoint = struct {
source: logger.Source = undefined,
@@ -185,7 +205,7 @@ pub const ServerEntryPoint = struct {
allocator,
\\// @bun
\\var hmrSymbol = Symbol.for("BunServerHMR");
- \\import * as start from '{s}{s}';
+ \\import * as start from "{}{}";
\\var entryNamespace = start;
\\if (typeof entryNamespace?.then === 'function') {{
\\ entryNamespace = entryNamespace.then((entryNamespace) => {{
@@ -211,15 +231,15 @@ pub const ServerEntryPoint = struct {
\\
,
.{
- dir_to_use,
- original_path.filename,
+ QuoteEscapeFormat{ .data = dir_to_use },
+ QuoteEscapeFormat{ .data = original_path.filename },
},
);
}
break :brk try std.fmt.allocPrint(
allocator,
\\// @bun
- \\import * as start from '{s}{s}';
+ \\import * as start from "{}{}";
\\var entryNamespace = start;
\\if (typeof entryNamespace?.then === 'function') {{
\\ entryNamespace = entryNamespace.then((entryNamespace) => {{
@@ -233,8 +253,8 @@ pub const ServerEntryPoint = struct {
\\
,
.{
- dir_to_use,
- original_path.filename,
+ QuoteEscapeFormat{ .data = dir_to_use },
+ QuoteEscapeFormat{ .data = original_path.filename },
},
);
};