diff options
author | 2021-12-30 21:12:32 -0800 | |
---|---|---|
committer | 2021-12-30 21:12:32 -0800 | |
commit | e75c711c68896f5952793601f156c921c814caab (patch) | |
tree | f3b30e2281c7231d480bb84503d17b2370866ff9 /src/resolver | |
parent | 8d031f13c0e04629d431176e211a31224b7618c0 (diff) | |
download | bun-e75c711c68896f5952793601f156c921c814caab.tar.gz bun-e75c711c68896f5952793601f156c921c814caab.tar.zst bun-e75c711c68896f5952793601f156c921c814caab.zip |
Upgrade to latest Zig, remove dependency on patched version of Zig (#96)
* Prepare to upgrade zig
* zig fmt
* AllocGate
* Update data_url.zig
* wip
* few files
* just headers now?
* I think everything works?
* Update mimalloc
* Update hash_map.zig
* Perf improvements to compensate for Allocgate
* Bump
* :camera:
* Update bun.lockb
* Less branching
* [js parser] Slightly reduce memory usage
* Update js_parser.zig
* WIP remove unused
* [JS parser] WIP support for `with` keyword
* Remove more dead code
* Fix all the build errors!
* cleanup
* Move `network_thread` up
* Bump peechy
* Update README.md
Diffstat (limited to 'src/resolver')
-rw-r--r-- | src/resolver/data_url.zig | 53 | ||||
-rw-r--r-- | src/resolver/dir_info.zig | 17 | ||||
-rw-r--r-- | src/resolver/package_json.zig | 38 | ||||
-rw-r--r-- | src/resolver/resolve_path.zig | 117 | ||||
-rw-r--r-- | src/resolver/resolver.zig | 80 | ||||
-rw-r--r-- | src/resolver/tsconfig_json.zig | 25 |
6 files changed, 109 insertions, 221 deletions
diff --git a/src/resolver/data_url.zig b/src/resolver/data_url.zig index dd443dbe8..8a9186bf8 100644 --- a/src/resolver/data_url.zig +++ b/src/resolver/data_url.zig @@ -1,8 +1,18 @@ -usingnamespace @import("../global.zig"); +const _global = @import("../global.zig"); +const string = _global.string; +const Output = _global.Output; +const Global = _global.Global; +const Environment = _global.Environment; +const strings = _global.strings; +const MutableString = _global.MutableString; +const stringZ = _global.stringZ; +const default_allocator = _global.default_allocator; +const C = _global.C; const std = @import("std"); const assert = std.debug.assert; const mem = std.mem; +const Allocator = mem.Allocator; // https://github.com/Vexu/zuri/blob/master/src/zuri.zig#L61-L127 pub const PercentEncoding = struct { @@ -31,7 +41,7 @@ pub const PercentEncoding = struct { } /// decode path if it is percent encoded - pub fn decode(allocator: *Allocator, path: []const u8) EncodeError!?[]u8 { + pub fn decode(allocator: Allocator, path: []const u8) EncodeError!?[]u8 { var ret: ?[]u8 = null; errdefer if (ret) |some| allocator.free(some); var ret_index: usize = 0; @@ -65,32 +75,6 @@ pub const PercentEncoding = struct { if (ret) |some| return allocator.shrink(some, ret_index); return null; } - - /// percent encode if path contains characters not allowed in paths - pub fn encode(allocator: *Allocator, path: []const u8) EncodeError!?[]u8 { - var ret: ?[]u8 = null; - var ret_index: usize = 0; - for (path) |c, i| { - if (c != '/' and !isPchar(path[i..])) { - if (ret == null) { - ret = try allocator.alloc(u8, path.len * 3); - mem.copy(u8, ret.?, path[0..i]); - ret_index = i; - } - const hex_digits = "0123456789ABCDEF"; - ret.?[ret_index] = '%'; - ret.?[ret_index + 1] = hex_digits[(c & 0xF0) >> 4]; - ret.?[ret_index + 2] = hex_digits[c & 0x0F]; - ret_index += 3; - } else if (ret != null) { - ret.?[ret_index] = c; - ret_index += 1; - } - } - - if (ret) |some| return allocator.shrink(some, ret_index); - return null; - } }; pub const MimeType = enum { @@ -144,17 +128,4 @@ pub const DataURL = struct { pub fn decode_mime_type(d: DataURL) MimeType { return MimeType.decode(d.mime_type); } - - pub fn decode_data(d: *DataURL, allocator: *std.mem.Allocator, url: string) !string { - // Try to read base64 data - if (d.is_base64) { - const size = try std.base64.standard.Decoder.calcSizeForSlice(d.data); - var buf = try allocator.alloc(u8, size); - try std.base64.standard.Decoder.decode(buf, d.data); - return buf; - } - - // Try to read percent-escaped data - return try PercentEncoding.decode(allocator, url); - } }; diff --git a/src/resolver/dir_info.zig b/src/resolver/dir_info.zig index b79067a48..86a9bc791 100644 --- a/src/resolver/dir_info.zig +++ b/src/resolver/dir_info.zig @@ -1,4 +1,15 @@ -usingnamespace @import("../global.zig"); +const _global = @import("../global.zig"); +const string = _global.string; +const Output = _global.Output; +const Global = _global.Global; +const Environment = _global.Environment; +const strings = _global.strings; +const MutableString = _global.MutableString; +const stringZ = _global.stringZ; +const default_allocator = _global.default_allocator; +const C = _global.C; +const StoredFileDescriptorType = _global.StoredFileDescriptorType; +const FeatureFlags = _global.FeatureFlags; const allocators = @import("../allocators.zig"); const DirInfo = @This(); @@ -50,7 +61,7 @@ pub fn getFileDescriptor(dirinfo: *const DirInfo) StoredFileDescriptorType { pub fn getEntries(dirinfo: *const DirInfo) ?*Fs.FileSystem.DirEntry { var entries_ptr = Fs.FileSystem.instance.fs.entries.atIndex(dirinfo.entries) orelse return null; switch (entries_ptr.*) { - .entries => |entr| { + .entries => { return &entries_ptr.entries; }, .err => { @@ -62,7 +73,7 @@ pub fn getEntries(dirinfo: *const DirInfo) ?*Fs.FileSystem.DirEntry { pub fn getEntriesConst(dirinfo: *const DirInfo) ?*const Fs.FileSystem.DirEntry { const entries_ptr = Fs.FileSystem.instance.fs.entries.atIndex(dirinfo.entries) orelse return null; switch (entries_ptr.*) { - .entries => |entr| { + .entries => { return &entries_ptr.entries; }, .err => { diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index 099035299..c2c86186a 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -1,4 +1,14 @@ -usingnamespace @import("../global.zig"); +const _global = @import("../global.zig"); +const string = _global.string; +const Output = _global.Output; +const Global = _global.Global; +const Environment = _global.Environment; +const strings = _global.strings; +const MutableString = _global.MutableString; +const StoredFileDescriptorType = _global.StoredFileDescriptorType; +const stringZ = _global.stringZ; +const default_allocator = _global.default_allocator; +const C = _global.C; const Api = @import("../api/schema.zig").Api; const std = @import("std"); const options = @import("../options.zig"); @@ -28,7 +38,7 @@ pub const PackageJSON = struct { }; const node_modules_path = std.fs.path.sep_str ++ "node_modules" ++ std.fs.path.sep_str; - pub fn nameForImport(this: *const PackageJSON, allocator: *std.mem.Allocator) !string { + pub fn nameForImport(this: *const PackageJSON, allocator: std.mem.Allocator) !string { if (strings.indexOf(this.source.path.text, node_modules_path)) |_| { return this.name; } else { @@ -100,7 +110,7 @@ pub const PackageJSON = struct { fn loadDefineDefaults( env: *options.Env, json: *const js_ast.E.Object, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, ) !void { var valid_count: usize = 0; for (json.properties) |prop| { @@ -123,7 +133,7 @@ pub const PackageJSON = struct { fn loadOverrides( framework: *options.Framework, json: *const js_ast.E.Object, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, ) void { var valid_count: usize = 0; for (json.properties) |prop| { @@ -146,7 +156,7 @@ pub const PackageJSON = struct { fn loadDefineExpression( env: *options.Env, json: *const js_ast.E.Object, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, ) anyerror!void { for (json.properties) |prop| { switch (prop.key.?.data) { @@ -182,7 +192,7 @@ pub const PackageJSON = struct { fn loadFrameworkExpression( framework: *options.Framework, json: js_ast.Expr, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, comptime read_define: bool, ) bool { if (json.asProperty("client")) |client| { @@ -277,7 +287,7 @@ pub const PackageJSON = struct { package_json: *const PackageJSON, pair: *FrameworkRouterPair, json: js_ast.Expr, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, comptime read_defines: bool, comptime load_framework: LoadFramework, ) void { @@ -362,7 +372,6 @@ pub const PackageJSON = struct { if (router.expr.asProperty("extensions")) |extensions_expr| { if (extensions_expr.expr.asArray()) |*array| { - const count = array.array.items.len; var valid_count: usize = 0; while (array.next()) |expr| { @@ -476,7 +485,7 @@ pub const PackageJSON = struct { json_source.path.pretty = r.prettyPath(json_source.path); const json: js_ast.Expr = (r.caches.json.parseJSON(r.log, json_source, r.allocator) catch |err| { - if (isDebug) { + if (Environment.isDebug) { Output.printError("{s}: JSON parse error: {s}", .{ package_json_path, @errorName(err) }); } return null; @@ -560,7 +569,6 @@ pub const PackageJSON = struct { if (bun_json.expr.asProperty("macros")) |macros| { if (macros.expr.data == .e_object) { - var always_bundle_count: u16 = 0; const properties = macros.expr.data.e_object.properties; for (properties) |property| { @@ -764,7 +772,7 @@ pub const ExportsMap = struct { root: Entry, exports_range: logger.Range = logger.Range.None, - pub fn parse(allocator: *std.mem.Allocator, source: *const logger.Source, log: *logger.Log, json: js_ast.Expr) ?ExportsMap { + pub fn parse(allocator: std.mem.Allocator, source: *const logger.Source, log: *logger.Log, json: js_ast.Expr) ?ExportsMap { var visitor = Visitor{ .allocator = allocator, .source = source, .log = log }; const root = visitor.visit(json); @@ -780,7 +788,7 @@ pub const ExportsMap = struct { } pub const Visitor = struct { - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, source: *const logger.Source, log: *logger.Log, @@ -949,7 +957,7 @@ pub const ExportsMap = struct { pub fn valueForKey(this: *const Entry, key_: string) ?Entry { switch (this.data) { - .map => |map| { + .map => { var slice = this.data.map.list.slice(); const keys = slice.items(.key); for (keys) |key, i| { @@ -973,7 +981,7 @@ pub const ESModule = struct { debug_logs: ?*resolver.DebugLogs = null, conditions: ConditionsMap, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, pub const Resolution = struct { status: Status = Status.Undefined, @@ -1425,7 +1433,7 @@ pub const ESModule = struct { var last_exception = Status.Undefined; var last_debug = Resolution.Debug{ .token = target.first_token }; - for (array) |targetValue, i| { + for (array) |targetValue| { // Let resolved be the result, continuing the loop on any Invalid Package Target error. const result = r.resolveTarget(package_url, targetValue, subpath, pattern); if (result.status == .InvalidPackageTarget or result.status == .Null) { diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig index 587a8e9ed..f7335a8b4 100644 --- a/src/resolver/resolve_path.zig +++ b/src/resolver/resolve_path.zig @@ -29,8 +29,6 @@ pub fn longestCommonPathGeneric(strings: []const []const u8, comptime separator: min_length = @minimum(str.len, min_length); } - var last_common_separator_is_at_end = false; - var index: usize = 0; var last_common_separator: usize = 0; @@ -316,7 +314,7 @@ pub fn relativePlatform(from: []const u8, to: []const u8, comptime platform: Pla return relativeNormalized(normalized_from, normalized_to, platform, always_copy); } -pub fn relativeAlloc(allocator: *std.mem.Allocator, from: []const u8, to: []const u8) ![]const u8 { +pub fn relativeAlloc(allocator: std.mem.Allocator, from: []const u8, to: []const u8) ![]const u8 { if (comptime FeatureFlags.use_std_path_relative) { return try std.fs.path.relative(allocator, from, to); } else { @@ -430,7 +428,7 @@ pub const Platform = enum { }; } - pub const current: Platform = switch (std.Target.current.os.tag) { + pub const current: Platform = switch (@import("builtin").target.os.tag) { .windows => Platform.windows, else => Platform.posix, }; @@ -506,7 +504,7 @@ pub const Platform = enum { pub fn resolve(comptime _platform: Platform) Platform { if (comptime _platform == .auto) { - return switch (std.Target.current.os.tag) { + return switch (@import("builtin").target.os.tag) { .windows => Platform.windows, .freestanding, .emscripten, .other => Platform.loose, @@ -526,19 +524,14 @@ pub fn normalizeString(str: []const u8, comptime allow_above_root: bool, comptim pub fn normalizeStringBuf(str: []const u8, buf: []u8, comptime allow_above_root: bool, comptime _platform: Platform, comptime preserve_trailing_slash: anytype) []u8 { const platform = comptime _platform.resolve(); - switch (platform) { + switch (comptime platform) { .auto => unreachable, .windows => { - return normalizeStringWindowsBuf( - str, - buf, - allow_above_root, - preserve_trailing_slash, - ); + @compileError("Not implemented"); }, .posix => { - return normalizeStringPosixBuf( + return normalizeStringLooseBuf( str, buf, allow_above_root, @@ -557,7 +550,7 @@ pub fn normalizeStringBuf(str: []const u8, buf: []u8, comptime allow_above_root: } } -pub fn normalizeStringAlloc(allocator: *std.mem.Allocator, str: []const u8, comptime allow_above_root: bool, comptime _platform: Platform) ![]const u8 { +pub fn normalizeStringAlloc(allocator: std.mem.Allocator, str: []const u8, comptime allow_above_root: bool, comptime _platform: Platform) ![]const u8 { return try allocator.dupe(u8, normalizeString(str, allow_above_root, _platform)); } @@ -602,12 +595,6 @@ pub fn joinStringBuf(buf: []u8, _parts: anytype, comptime _platform: Platform) [ return std.fs.path.join(&alloc.allocator, _parts) catch unreachable; } - if (_parts.len == 0) { - return _cwd; - } - - var parts = _parts; - var written: usize = 0; const platform = comptime _platform.resolve(); @@ -631,19 +618,18 @@ pub fn joinStringBuf(buf: []u8, _parts: anytype, comptime _platform: Platform) [ // Preserve leading separator if (_parts[0].len > 0 and _parts[0][0] == _platform.separator()) { - const out = switch (platform) { - .loose => normalizeStringLooseBuf(parser_join_input_buffer[0..written], buf[1..], false, false), - .windows => normalizeStringWindows(parser_join_input_buffer[0..written], buf[1..], false, false), - else => normalizeStringPosixBuf(parser_join_input_buffer[0..written], buf[1..], false, false), + const out = switch (comptime platform) { + // .loose => + .windows => @compileError("Not implemented yet"), + else => normalizeStringLooseBuf(parser_join_input_buffer[0..written], buf[1..], false, false), }; buf[0] = _platform.separator(); return buf[0 .. out.len + 1]; } else { return switch (platform) { - .loose => normalizeStringLooseBuf(parser_join_input_buffer[0..written], buf[0..], false, false), - .windows => normalizeStringWindows(parser_join_input_buffer[0..written], buf[0..], false, false), - else => normalizeStringPosixBuf(parser_join_input_buffer[0..written], buf[0..], false, false), + else => normalizeStringLooseBuf(parser_join_input_buffer[0..written], buf[0..], false, false), + .windows => @compileError("Not implemented yet"), }; } } @@ -676,7 +662,6 @@ inline fn _joinAbsStringBuf(comptime is_sentinel: bool, comptime ReturnType: typ var cwd = _cwd; var out: usize = 0; // When parts[0] is absolute, we treat that as, effectively, the cwd - var ignore_cwd = cwd.len == 0; // Windows leading separators can be a lot of things... // So we need to do this instead of just checking the first char. @@ -712,7 +697,7 @@ inline fn _joinAbsStringBuf(comptime is_sentinel: bool, comptime ReturnType: typ std.debug.assert(out < buf.len); std.mem.copy(u8, buf[0..out], start); - for (parts) |part, i| { + for (parts) |part| { // Do not normalize here // It will break stuff! var normalized_part = part; @@ -774,71 +759,6 @@ pub fn lastIndexOfSeparatorLoose(slice: []const u8) ?usize { return std.mem.lastIndexOfAny(u8, slice, "/\\"); } -pub fn normalizeStringPosix(str: []const u8, comptime allow_above_root: bool, comptime preserve_trailing_slash: bool) []u8 { - return normalizeStringGenericBuf( - str, - &parser_buffer, - allow_above_root, - std.fs.path.sep_posix, - isSepPosix, - lastIndexOfSeparatorPosix, - preserve_trailing_slash, - ); -} - -pub fn normalizeStringPosixBuf( - str: []const u8, - buf: []u8, - comptime allow_above_root: bool, - comptime preserve_trailing_slash: bool, -) []u8 { - return normalizeStringGeneric( - str, - buf, - allow_above_root, - std.fs.path.sep_posix, - isSepPosix, - lastIndexOfSeparatorPosix, - preserve_trailing_slash, - ); -} - -pub fn normalizeStringWindows(str: []const u8, comptime allow_above_root: bool, comptime preserve_trailing_slash: bool) []u8 { - return normalizeStringGenericBuf( - str, - &parser_buffer, - allow_above_root, - std.fs.path.sep_windows, - isSepWin32, - lastIndexOfSeparatorWindows, - preserve_trailing_slash, - ); -} - -pub fn normalizeStringWindowsBuf(str: []const u8, buf: []u8, comptime allow_above_root: bool, comptime preserve_trailing_slash: bool) []u8 { - return normalizeStringGeneric( - str, - buf, - allow_above_root, - std.fs.path.sep_windows, - isSepWin32, - lastIndexOfSeparatorWindows, - preserve_trailing_slash, - ); -} - -pub fn normalizeStringLoose(str: []const u8, comptime allow_above_root: bool, comptime preserve_trailing_slash: bool) []u8 { - return normalizeStringGenericBuf( - str, - &parser_buffer, - allow_above_root, - std.fs.path.sep_posix, - isSepAny, - lastIndexOfSeparatorLoose, - preserve_trailing_slash, - ); -} - pub fn normalizeStringLooseBuf(str: []const u8, buf: []u8, comptime allow_above_root: bool, comptime preserve_trailing_slash: bool) []u8 { return normalizeStringGeneric( str, @@ -1032,15 +952,6 @@ test "relative" { var t = tester.Tester.t(default_allocator); defer t.report(@src()); - const strs = [_][]const u8{ - "/var/boo/foo/", - "/var/boo/foo/baz/", - "/var/boo/foo/beep/", - "/var/boo/foo/beep/bleep", - "/bar/baz", - "/bar/not-related", - "/bar/file.txt", - }; _ = t.expect("var/foo", try relativeAlloc(default_allocator, "/", "/var/foo/"), @src()); _ = t.expect("index.js", try relativeAlloc(default_allocator, "/app/public/", "/app/public/index.js"), @src()); _ = t.expect("..", try relativeAlloc(default_allocator, "/app/public/index.js", "/app/public/"), @src()); diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 34dc09088..571abbc8d 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -1,4 +1,16 @@ -usingnamespace @import("../global.zig"); +const _global = @import("../global.zig"); +const string = _global.string; +const Output = _global.Output; +const Global = _global.Global; +const Environment = _global.Environment; +const strings = _global.strings; +const MutableString = _global.MutableString; +const FeatureFlags = _global.FeatureFlags; +const PathString = _global.PathString; +const stringZ = _global.stringZ; +const default_allocator = _global.default_allocator; +const StoredFileDescriptorType = _global.StoredFileDescriptorType; +const C = _global.C; const ast = @import("../import_record.zig"); const logger = @import("../logger.zig"); const options = @import("../options.zig"); @@ -12,17 +24,18 @@ const MacroRemap = @import("./package_json.zig").MacroMap; const ESModule = @import("./package_json.zig").ESModule; const BrowserMap = @import("./package_json.zig").BrowserMap; const CacheSet = cache.Set; -usingnamespace @import("./data_url.zig"); +const DataURL = @import("./data_url.zig").DataURL; pub const DirInfo = @import("./dir_info.zig"); -const HTTPWatcher = if (isTest) void else @import("../http.zig").Watcher; +const HTTPWatcher = if (Environment.isTest) void else @import("../http.zig").Watcher; const Wyhash = std.hash.Wyhash; const ResolvePath = @import("./resolve_path.zig"); const NodeFallbackModules = @import("../node_fallbacks.zig"); const Mutex = @import("../lock.zig").Lock; const StringBoolMap = std.StringHashMap(bool); +const FileDescriptorType = _global.FileDescriptorType; const allocators = @import("../allocators.zig"); - +const Msg = logger.Msg; const Path = Fs.Path; const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle; @@ -162,7 +175,7 @@ pub const Result = struct { suggestion_text: string = "", suggestion_message: string = "", - pub fn init(allocator: *std.mem.Allocator) DebugMeta { + pub fn init(allocator: std.mem.Allocator) DebugMeta { return DebugMeta{ .notes = std.ArrayList(logger.Data).init(allocator) }; } @@ -181,7 +194,7 @@ pub const Result = struct { } }; - pub fn hash(this: *const Result, root_dir: string, loader: options.Loader) u32 { + pub fn hash(this: *const Result, _: string, _: options.Loader) u32 { const module = this.path_pair.primary.text; const node_module_root = std.fs.path.sep_str ++ "node_modules" ++ std.fs.path.sep_str; if (strings.lastIndexOf(module, node_module_root)) |end_| { @@ -226,7 +239,7 @@ pub const DebugLogs = struct { pub const FlushMode = enum { fail, success }; - pub fn init(allocator: *std.mem.Allocator) !DebugLogs { + pub fn init(allocator: std.mem.Allocator) !DebugLogs { var mutable = try MutableString.init(allocator, 0); return DebugLogs{ .indent = mutable, @@ -235,7 +248,6 @@ pub const DebugLogs = struct { } pub fn deinit(d: DebugLogs) void { - var allocator = d.notes.allocator; d.notes.deinit(); // d.indent.deinit(); } @@ -270,39 +282,6 @@ pub const DebugLogs = struct { } }; -pub const TSConfigExtender = struct { - visited: *StringBoolMap, - file_dir: string, - r: *ThisResolver, - - pub fn extends(ctx: *TSConfigExtender, ext: String, range: logger.Range) ?*TSConfigJSON { - unreachable; - // if (isPackagePath(extends)) { - // // // If this is a package path, try to resolve it to a "node_modules" - // // // folder. This doesn't use the normal node module resolution algorithm - // // // both because it's different (e.g. we don't want to match a directory) - // // // and because it would deadlock since we're currently in the middle of - // // // populating the directory info cache. - // // var current = ctx.file_dir; - // // while (true) { - // // // Skip "node_modules" folders - // // if (!strings.eql(std.fs.path.basename(current), "node_modules")) { - // // var paths1 = [_]string{ current, "node_modules", extends }; - // // var join1 = r.fs.absAlloc(ctx.r.allocator, &paths1) catch unreachable; - // // const res = ctx.r.parseTSConfig(join1, ctx.1) catch |err| { - // // if (err == error.ENOENT) { - // // continue; - // // } else if (err == error.ParseErrorImportCycle) {} else if (err != error.ParseErrorAlreadyLogged) {} - // // return null; - // // }; - // // return res; - - // // } - // // } - // } - } -}; - pub const MatchResult = struct { path_pair: PathPair, dirname_fd: StoredFileDescriptorType = 0, @@ -338,7 +317,7 @@ pub const Resolver = struct { opts: options.BundleOptions, fs: *Fs.FileSystem, log: *logger.Log, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, node_module_bundle: ?*NodeModuleBundle, extension_order: []const string = undefined, timer: std.time.Timer = undefined, @@ -399,7 +378,7 @@ pub const Resolver = struct { dir_cache: *DirInfo.HashMap, pub fn init1( - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, log: *logger.Log, _fs: *Fs.FileSystem, opts: options.BundleOptions, @@ -1042,7 +1021,7 @@ pub const Resolver = struct { return result; } - if (res.package_json) |pkg| { + if (res.package_json != null) { var base_dir_info = res.dir_info orelse (r.readDirInfo(res.path_pair.primary.name.dir) catch null) orelse return result; if (base_dir_info.getEnclosingBrowserScope()) |browser_scope| { if (r.checkBrowserMap( @@ -1387,11 +1366,11 @@ pub const Resolver = struct { } // TODO: - pub fn prettyPath(r: *ThisResolver, path: Path) string { + pub fn prettyPath(_: *ThisResolver, path: Path) string { return path.text; } - pub fn binDirs(r: *const ThisResolver) []const string { + pub fn binDirs(_: *const ThisResolver) []const string { if (!bin_folders_loaded) return &[_]string{}; return bin_folders.constSlice(); } @@ -1461,7 +1440,7 @@ pub const Resolver = struct { .hash = 0, .status = .not_found, }; - const root_path = if (comptime isWindows) + const root_path = if (comptime Environment.isWindows) std.fs.path.diskDesignator(path) else // we cannot just use "/" @@ -1730,7 +1709,6 @@ pub const Resolver = struct { if (strings.eql(key, path)) { for (entry.value_ptr.*) |original_path| { var absolute_original_path = original_path; - var was_alloc = false; if (!std.fs.path.isAbsolute(absolute_original_path)) { const parts = [_]string{ abs_base_url, original_path }; @@ -2202,7 +2180,7 @@ pub const Resolver = struct { } const dir_info = (r.dirInfoCached(path) catch |err| { - if (comptime isDebug) Output.prettyErrorln("err: {s} reading {s}", .{ @errorName(err), path }); + if (comptime Environment.isDebug) Output.prettyErrorln("err: {s} reading {s}", .{ @errorName(err), path }); return null; }) orelse return null; var package_json: ?*PackageJSON = null; @@ -2376,7 +2354,7 @@ pub const Resolver = struct { // Try the path with extensions std.mem.copy(u8, &load_as_file_buf, path); - for (r.extension_order) |ext| { + for (extension_order) |ext| { var buffer = load_as_file_buf[0 .. path.len + ext.len]; std.mem.copy(u8, buffer[path.len..buffer.len], ext); const file_name = buffer[path.len - base.len .. buffer.len]; @@ -2522,7 +2500,7 @@ pub const Resolver = struct { if (r.care_about_bin_folder) { append_bin_dir: { if (info.has_node_modules) { - if (entries.getComptimeQuery("node_modules")) |q| { + if (entries.hasComptimeQuery("node_modules")) { if (!bin_folders_loaded) { bin_folders_loaded = true; bin_folders = BinFolderArray.init(0) catch unreachable; diff --git a/src/resolver/tsconfig_json.zig b/src/resolver/tsconfig_json.zig index ac132c326..9c457682c 100644 --- a/src/resolver/tsconfig_json.zig +++ b/src/resolver/tsconfig_json.zig @@ -1,4 +1,13 @@ -usingnamespace @import("../global.zig"); +const _global = @import("../global.zig"); +const string = _global.string; +const Output = _global.Output; +const Global = _global.Global; +const Environment = _global.Environment; +const strings = _global.strings; +const MutableString = _global.MutableString; +const stringZ = _global.stringZ; +const default_allocator = _global.default_allocator; +const C = _global.C; const std = @import("std"); const options = @import("../options.zig"); const logger = @import("../logger.zig"); @@ -77,7 +86,7 @@ pub const TSConfigJSON = struct { } pub fn parse( - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, log: *logger.Log, source: logger.Source, json_cache: *cache.Json, @@ -180,7 +189,7 @@ pub const TSConfigJSON = struct { if (compiler_opts.expr.asProperty("paths")) |paths_prop| { switch (paths_prop.expr.data) { .e_object => { - var paths = paths_prop.expr.getObject(); + var paths = paths_prop.expr.data.e_object; result.base_url_for_paths = if (result.base_url.len > 0) result.base_url else "."; result.paths = PathsMap.init(allocator); for (paths.properties) |property| { @@ -216,7 +225,7 @@ pub const TSConfigJSON = struct { // and then, if that didn't work, also check "projectRoot/generated/folder1/file2". switch (value_prop.data) { .e_array => { - const array = value_prop.getArray(); + const array = value_prop.data.e_array; if (array.items.len > 0) { var values = allocator.alloc(string, array.items.len) catch unreachable; @@ -282,9 +291,9 @@ pub const TSConfigJSON = struct { return _result; } - pub fn isValidTSConfigPathPattern(text: string, log: *logger.Log, source: *const logger.Source, loc: logger.Loc, allocator: *std.mem.Allocator) bool { + pub fn isValidTSConfigPathPattern(text: string, log: *logger.Log, source: *const logger.Source, loc: logger.Loc, allocator: std.mem.Allocator) bool { var found_asterisk = false; - for (text) |c, i| { + for (text) |c| { if (c == '*') { if (found_asterisk) { const r = source.rangeOfString(loc); @@ -298,7 +307,7 @@ pub const TSConfigJSON = struct { return true; } - pub fn parseMemberExpressionForJSX(log: *logger.Log, source: *const logger.Source, loc: logger.Loc, text: string, allocator: *std.mem.Allocator) ![]string { + pub fn parseMemberExpressionForJSX(log: *logger.Log, source: *const logger.Source, loc: logger.Loc, text: string, allocator: std.mem.Allocator) ![]string { if (text.len == 0) { return &([_]string{}); } @@ -323,7 +332,7 @@ pub const TSConfigJSON = struct { return c == '/' or c == '\\'; } - pub fn isValidTSConfigPathNoBaseURLPattern(text: string, log: *logger.Log, source: *const logger.Source, allocator: *std.mem.Allocator, loc: logger.Loc) bool { + pub fn isValidTSConfigPathNoBaseURLPattern(text: string, log: *logger.Log, source: *const logger.Source, allocator: std.mem.Allocator, loc: logger.Loc) bool { var c0: u8 = 0; var c1: u8 = 0; var c2: u8 = 0; |