aboutsummaryrefslogtreecommitdiff
path: root/src/resolver
diff options
context:
space:
mode:
Diffstat (limited to 'src/resolver')
-rw-r--r--src/resolver/package_json.zig12
-rw-r--r--src/resolver/resolve_path.zig12
-rw-r--r--src/resolver/resolver.zig40
3 files changed, 35 insertions, 29 deletions
diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig
index e759374e7..75e6a7c98 100644
--- a/src/resolver/package_json.zig
+++ b/src/resolver/package_json.zig
@@ -1026,7 +1026,7 @@ pub const PackageJSON = struct {
hasher.update(std.mem.asBytes(&this.hash));
hasher.update(module);
- return @truncate(u32, hasher.final());
+ return @as(u32, @truncate(hasher.final()));
}
};
@@ -1359,14 +1359,14 @@ pub const ESModule = struct {
pub fn parseName(specifier: string) ?string {
var slash = strings.indexOfCharNeg(specifier, '/');
if (!strings.startsWithChar(specifier, '@')) {
- slash = if (slash == -1) @intCast(i32, specifier.len) else slash;
- return specifier[0..@intCast(usize, slash)];
+ slash = if (slash == -1) @as(i32, @intCast(specifier.len)) else slash;
+ return specifier[0..@as(usize, @intCast(slash))];
} else {
if (slash == -1) return null;
- const slash2 = strings.indexOfChar(specifier[@intCast(usize, slash) + 1 ..], '/') orelse
- specifier[@intCast(u32, slash + 1)..].len;
- return specifier[0 .. @intCast(usize, slash + 1) + slash2];
+ const slash2 = strings.indexOfChar(specifier[@as(usize, @intCast(slash)) + 1 ..], '/') orelse
+ specifier[@as(u32, @intCast(slash + 1))..].len;
+ return specifier[0 .. @as(usize, @intCast(slash + 1)) + slash2];
}
}
diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig
index e63318887..877f32ded 100644
--- a/src/resolver/resolve_path.zig
+++ b/src/resolver/resolve_path.zig
@@ -25,11 +25,11 @@ const IsSeparatorFunc = fn (char: u8) bool;
const LastSeparatorFunction = fn (slice: []const u8) ?usize;
inline fn @"is .."(slice: []const u8) bool {
- return slice.len >= 2 and @bitCast(u16, slice[0..2].*) == comptime std.mem.readIntNative(u16, "..");
+ return slice.len >= 2 and @as(u16, @bitCast(slice[0..2].*)) == comptime std.mem.readIntNative(u16, "..");
}
inline fn isDotSlash(slice: []const u8) bool {
- return @bitCast(u16, slice[0..2].*) == comptime std.mem.readIntNative(u16, "./");
+ return @as(u16, @bitCast(slice[0..2].*)) == comptime std.mem.readIntNative(u16, "./");
}
inline fn @"is ../"(slice: []const u8) bool {
@@ -376,7 +376,7 @@ pub fn relativeToCommonPath(
var out_slice: []u8 = buf[0..0];
if (normalized_from.len > 0) {
- var i: usize = @intCast(usize, @intFromBool(normalized_from[0] == separator)) + 1 + last_common_separator;
+ var i: usize = @as(usize, @intCast(@intFromBool(normalized_from[0] == separator))) + 1 + last_common_separator;
while (i <= normalized_from.len) : (i += 1) {
if (i == normalized_from.len or (normalized_from[i] == separator and i + 1 < normalized_from.len)) {
@@ -878,14 +878,14 @@ inline fn _joinAbsStringBuf(comptime is_sentinel: bool, comptime ReturnType: typ
{
var part_i: u16 = 0;
- var part_len: u16 = @truncate(u16, parts.len);
+ var part_len: u16 = @as(u16, @truncate(parts.len));
while (part_i < part_len) {
if (_platform.isAbsolute(parts[part_i])) {
cwd = parts[part_i];
parts = parts[part_i + 1 ..];
- part_len = @truncate(u16, parts.len);
+ part_len = @as(u16, @truncate(parts.len));
part_i = 0;
continue;
}
@@ -959,7 +959,7 @@ pub fn lastIndexOfNonSeparatorPosix(slice: []const u8) ?u32 {
var i: usize = slice.len;
while (i != 0) : (i -= 1) {
if (slice[i] != std.fs.path.sep_posix) {
- return @intCast(u32, i);
+ return @as(u32, @intCast(i));
}
}
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index 409df85af..cf337d324 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -283,10 +283,10 @@ pub const Result = struct {
if (strings.lastIndexOf(module, node_module_root)) |end_| {
var end: usize = end_ + node_module_root.len;
- return @truncate(u32, bun.hash(module[end..]));
+ return @as(u32, @truncate(bun.hash(module[end..])));
}
- return @truncate(u32, bun.hash(this.path_pair.primary.text));
+ return @as(u32, @truncate(bun.hash(this.path_pair.primary.text)));
}
};
@@ -1262,7 +1262,7 @@ pub const Resolver = struct {
if (NodeFallbackModules.Map.get(import_path_without_node_prefix)) |*fallback_module| {
result.path_pair.primary = fallback_module.path;
result.module_type = .cjs;
- result.package_json = @ptrFromInt(*PackageJSON, @intFromPtr(fallback_module.package_json));
+ result.package_json = @as(*PackageJSON, @ptrFromInt(@intFromPtr(fallback_module.package_json)));
result.is_from_node_modules = true;
return .{ .success = result };
// "node:*
@@ -1693,7 +1693,7 @@ pub const Resolver = struct {
// check the global cache directory for a package.json file.
var manager = r.getPackageManager();
var dependency_version = Dependency.Version{};
- var dependency_behavior = @enumFromInt(Dependency.Behavior, Dependency.Behavior.normal);
+ var dependency_behavior = @as(Dependency.Behavior, @enumFromInt(Dependency.Behavior.normal));
var string_buf = esm.version;
// const initial_pending_tasks = manager.pending_tasks;
@@ -2466,15 +2466,15 @@ pub const Resolver = struct {
top_parent = result;
break;
}
- bufs(.dir_entry_paths_to_resolve)[@intCast(usize, i)] = DirEntryResolveQueueItem{
+ bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))] = DirEntryResolveQueueItem{
.unsafe_path = top,
.result = result,
.fd = 0,
};
if (rfs.entries.get(top)) |top_entry| {
- bufs(.dir_entry_paths_to_resolve)[@intCast(usize, i)].safe_path = top_entry.entries.dir;
- bufs(.dir_entry_paths_to_resolve)[@intCast(usize, i)].fd = top_entry.entries.fd;
+ bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].safe_path = top_entry.entries.dir;
+ bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].fd = top_entry.entries.fd;
}
i += 1;
}
@@ -2484,21 +2484,21 @@ pub const Resolver = struct {
if (result.status != .unknown) {
top_parent = result;
} else {
- bufs(.dir_entry_paths_to_resolve)[@intCast(usize, i)] = DirEntryResolveQueueItem{
+ bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))] = DirEntryResolveQueueItem{
.unsafe_path = root_path,
.result = result,
.fd = 0,
};
if (rfs.entries.get(top)) |top_entry| {
- bufs(.dir_entry_paths_to_resolve)[@intCast(usize, i)].safe_path = top_entry.entries.dir;
- bufs(.dir_entry_paths_to_resolve)[@intCast(usize, i)].fd = top_entry.entries.fd;
+ bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].safe_path = top_entry.entries.dir;
+ bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].fd = top_entry.entries.fd;
}
i += 1;
}
}
- var queue_slice: []DirEntryResolveQueueItem = bufs(.dir_entry_paths_to_resolve)[0..@intCast(usize, i)];
+ var queue_slice: []DirEntryResolveQueueItem = bufs(.dir_entry_paths_to_resolve)[0..@as(usize, @intCast(i))];
if (Environment.allow_assert) std.debug.assert(queue_slice.len > 0);
var open_dir_count: usize = 0;
@@ -2626,7 +2626,7 @@ pub const Resolver = struct {
// Directories must always end in a trailing slash or else various bugs can occur.
// This covers "what happens when the trailing"
- end += @intCast(usize, @intFromBool(safe_path.len > end and end > 0 and safe_path[end - 1] != std.fs.path.sep and safe_path[end] == std.fs.path.sep));
+ end += @as(usize, @intCast(@intFromBool(safe_path.len > end and end > 0 and safe_path[end - 1] != std.fs.path.sep and safe_path[end] == std.fs.path.sep)));
break :brk safe_path[dir_path_i..end];
};
@@ -2779,8 +2779,8 @@ pub const Resolver = struct {
(prefix.len >= longest_match_prefix_length and
suffix.len > longest_match_suffix_length))
{
- longest_match_prefix_length = @intCast(i32, prefix.len);
- longest_match_suffix_length = @intCast(i32, suffix.len);
+ longest_match_prefix_length = @as(i32, @intCast(prefix.len));
+ longest_match_suffix_length = @as(i32, @intCast(suffix.len));
longest_match = TSConfigMatch{ .prefix = prefix, .suffix = suffix, .original_paths = original_paths };
}
}
@@ -3378,7 +3378,13 @@ pub const Resolver = struct {
continue;
};
- var _result = r.loadFromMainField(path, dir_info, field_rel_path, key, extension_order) orelse continue;
+ var _result = r.loadFromMainField(
+ path,
+ dir_info,
+ field_rel_path,
+ key,
+ if (strings.eqlComptime(key, "main")) r.opts.main_field_extension_order else extension_order,
+ ) orelse continue;
// If the user did not manually configure a "main" field order, then
// use a special per-module automatic algorithm to decide whether to
@@ -3389,13 +3395,13 @@ pub const Resolver = struct {
if (main_field_values.get("main")) |main_rel_path| {
if (main_rel_path.len > 0) {
- absolute_result = r.loadFromMainField(path, dir_info, main_rel_path, "main", extension_order);
+ absolute_result = r.loadFromMainField(path, dir_info, main_rel_path, "main", r.opts.main_field_extension_order);
}
} else {
// Some packages have a "module" field without a "main" field but
// still have an implicit "index.js" file. In that case, treat that
// as the value for "main".
- absolute_result = r.loadAsIndexWithBrowserRemapping(dir_info, path, extension_order);
+ absolute_result = r.loadAsIndexWithBrowserRemapping(dir_info, path, r.opts.main_field_extension_order);
}
if (absolute_result) |auto_main_result| {