diff options
Diffstat (limited to 'src/bun.js/javascript.zig')
-rw-r--r-- | src/bun.js/javascript.zig | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index fd2ded108..410f3a776 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -891,6 +891,7 @@ pub const VirtualMachine = struct { _: *JSGlobalObject, specifier: string, source: string, + is_esm: bool, comptime is_a_file_path: bool, comptime realpath: bool, ) !void { @@ -936,7 +937,7 @@ pub const VirtualMachine = struct { jsc_vm.bundler.fs.top_level_dir, // TODO: do we need to handle things like query string params? if (strings.hasPrefixComptime(specifier, "file://")) specifier["file://".len..] else specifier, - .stmt, + if (is_esm) .stmt else .require, .read_only, )) { .success => |r| r, @@ -1012,19 +1013,53 @@ pub const VirtualMachine = struct { } } - pub fn resolveForAPI(res: *ErrorableZigString, global: *JSGlobalObject, specifier: ZigString, source: ZigString) void { - resolveMaybeNeedsTrailingSlash(res, global, specifier, source, false, true); + pub fn resolveForAPI( + res: *ErrorableZigString, + global: *JSGlobalObject, + specifier: ZigString, + source: ZigString, + is_esm: bool, + ) void { + resolveMaybeNeedsTrailingSlash(res, global, specifier, source, is_esm, false, true); } - pub fn resolveFilePathForAPI(res: *ErrorableZigString, global: *JSGlobalObject, specifier: ZigString, source: ZigString) void { - resolveMaybeNeedsTrailingSlash(res, global, specifier, source, true, true); + pub fn resolveFilePathForAPI( + res: *ErrorableZigString, + global: *JSGlobalObject, + specifier: ZigString, + source: ZigString, + is_esm: bool, + ) void { + resolveMaybeNeedsTrailingSlash(res, global, specifier, source, is_esm, true, true); + } + + pub fn resolve( + res: *ErrorableZigString, + global: *JSGlobalObject, + specifier: ZigString, + source: ZigString, + is_esm: bool, + ) void { + resolveMaybeNeedsTrailingSlash(res, global, specifier, source, is_esm, true, false); } - pub fn resolve(res: *ErrorableZigString, global: *JSGlobalObject, specifier: ZigString, source: ZigString) void { - resolveMaybeNeedsTrailingSlash(res, global, specifier, source, true, false); + fn normalizeSource(source: []const u8) []const u8 { + if (strings.hasPrefixComptime(source, "file://")) { + return source["file://".len..]; + } + + return source; } - pub fn resolveMaybeNeedsTrailingSlash(res: *ErrorableZigString, global: *JSGlobalObject, specifier: ZigString, source: ZigString, comptime is_a_file_path: bool, comptime realpath: bool) void { + pub fn resolveMaybeNeedsTrailingSlash( + res: *ErrorableZigString, + global: *JSGlobalObject, + specifier: ZigString, + source: ZigString, + is_esm: bool, + comptime is_a_file_path: bool, + comptime realpath: bool, + ) void { var result = ResolveFunctionResult{ .path = "", .result = null }; var jsc_vm = VirtualMachine.get(); if (jsc_vm.plugin_runner) |plugin_runner| { @@ -1057,7 +1092,7 @@ pub const VirtualMachine = struct { jsc_vm.bundler.linker.log = old_log; jsc_vm.bundler.resolver.log = old_log; } - _resolve(&result, global, specifier.slice(), source.slice(), is_a_file_path, realpath) catch |err_| { + _resolve(&result, global, specifier.slice(), normalizeSource(source.slice()), is_esm, is_a_file_path, realpath) catch |err_| { var err = err_; const msg: logger.Msg = brk: { var msgs: []logger.Msg = log.msgs.items; |