diff options
Diffstat (limited to 'src/bun.js/module_loader.zig')
-rw-r--r-- | src/bun.js/module_loader.zig | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index f5e5cde72..cf86cb460 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -482,10 +482,6 @@ pub const RuntimeTranspilerStore = struct { .source_code = bun.String.createLatin1(parse_result.source.contents), .specifier = String.create(specifier), .source_url = ZigString.init(path.text), - // // TODO: change hash to a bitfield - // .hash = 1, - - // having JSC own the memory causes crashes .hash = 0, }; return; @@ -1290,10 +1286,7 @@ pub const ModuleLoader = struct { std.math.maxInt(u32) else 0, - // // TODO: change hash to a bitfield - // .hash = 1, - // having JSC own the memory causes crashes .hash = 0, }; } @@ -1466,31 +1459,36 @@ pub const ModuleLoader = struct { } } - var parse_result = jsc_vm.bundler.parseMaybeReturnFileOnly( - parse_options, - null, - disable_transpilying, - ) orelse { - if (comptime !disable_transpilying) { - if (jsc_vm.isWatcherEnabled()) { - if (input_file_fd != 0) { - if (jsc_vm.bun_watcher != null and !is_node_override and std.fs.path.isAbsolute(path.text) and !strings.contains(path.text, "node_modules")) { - should_close_input_file_fd = false; - jsc_vm.bun_watcher.?.addFile( - input_file_fd, - path.text, - hash, - loader, - 0, - package_json, - true, - ) catch {}; + var parse_result = switch (disable_transpilying or + (loader == .json and !path.isJSONCFile())) { + inline else => |return_file_only| brk: { + break :brk jsc_vm.bundler.parseMaybeReturnFileOnly( + parse_options, + null, + return_file_only, + ) orelse { + if (comptime !disable_transpilying) { + if (jsc_vm.isWatcherEnabled()) { + if (input_file_fd != 0) { + if (jsc_vm.bun_watcher != null and !is_node_override and std.fs.path.isAbsolute(path.text) and !strings.contains(path.text, "node_modules")) { + should_close_input_file_fd = false; + jsc_vm.bun_watcher.?.addFile( + input_file_fd, + path.text, + hash, + loader, + 0, + package_json, + true, + ) catch {}; + } + } } } - } - } - return error.ParseError; + return error.ParseError; + }; + }, }; if (parse_result.loader == .wasm) { @@ -1535,6 +1533,18 @@ pub const ModuleLoader = struct { return error.ParseError; } + if (loader == .json and !path.isJSONCFile()) { + return ResolvedSource{ + .allocator = null, + .source_code = bun.String.create(parse_result.source.contents), + .specifier = input_specifier, + .source_url = ZigString.init(path.text), + + .hash = 0, + .tag = ResolvedSource.Tag.json_for_object_loader, + }; + } + if (comptime disable_transpilying) { return ResolvedSource{ .allocator = null, @@ -1555,10 +1565,7 @@ pub const ModuleLoader = struct { .source_code = bun.String.createLatin1(parse_result.source.contents), .specifier = input_specifier, .source_url = ZigString.init(path.text), - // // TODO: change hash to a bitfield - // .hash = 1, - // having JSC own the memory causes crashes .hash = 0, }; } @@ -1692,10 +1699,6 @@ pub const ModuleLoader = struct { std.math.maxInt(u32) else 0, - // // TODO: change hash to a bitfield - // .hash = 1, - - // having JSC own the memory causes crashes .hash = 0, .tag = tag, |