diff options
author | 2021-05-27 16:38:53 -0700 | |
---|---|---|
committer | 2021-05-27 16:38:53 -0700 | |
commit | d1b3bce06733bd37aee2e22a8bc6d792e6edf53a (patch) | |
tree | 78978275977ab365761800e251b5d4d3c2359d58 | |
parent | 05b9e8941703dfcabf87ee6efcd71e694177c2c5 (diff) | |
download | bun-d1b3bce06733bd37aee2e22a8bc6d792e6edf53a.tar.gz bun-d1b3bce06733bd37aee2e22a8bc6d792e6edf53a.tar.zst bun-d1b3bce06733bd37aee2e22a8bc6d792e6edf53a.zip |
lots
-rw-r--r-- | src/bundler.zig | 31 | ||||
-rw-r--r-- | src/cli.zig | 8 | ||||
-rw-r--r-- | src/js_ast.zig | 21 | ||||
-rw-r--r-- | src/js_lexer.zig | 4 | ||||
-rw-r--r-- | src/js_parser/js_parser.zig | 4 |
5 files changed, 42 insertions, 26 deletions
diff --git a/src/bundler.zig b/src/bundler.zig index a64a09d97..96ec6027c 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -191,7 +191,6 @@ pub const Bundler = struct { const loader = bundler.options.loaders.get(resolve_result.path_pair.primary.name.ext) orelse .file; var file_path = resolve_result.path_pair.primary; file_path.pretty = relative_paths_list.append(bundler.fs.relativeTo(file_path.text)) catch unreachable; - var result = bundler.parse(file_path, loader) orelse return null; switch (result.loader) { @@ -206,20 +205,32 @@ pub const Bundler = struct { switch (err) { error.ModuleNotFound => { if (Resolver.Resolver.isPackagePath(import_record.path.text)) { - try bundler.log.addRangeErrorFmt( - &result.source, - import_record.range, - bundler.allocator, - "Could not resolve: \"{s}\". Maybe you need to run \"npm install\" (or yarn/pnpm)?", - .{import_record.path.text}, - ); + if (bundler.options.platform != .node and options.ExternalModules.isNodeBuiltin(import_record.path.text)) { + try bundler.log.addRangeErrorFmt( + &result.source, + import_record.range, + bundler.allocator, + "Could not resolve: \"{s}\". Try setting --platform=\"node\"", + .{import_record.path.text}, + ); + } else { + try bundler.log.addRangeErrorFmt( + &result.source, + import_record.range, + bundler.allocator, + "Could not resolve: \"{s}\". Maybe you need to \"npm install\" (or yarn/pnpm)?", + .{import_record.path.text}, + ); + } } else { try bundler.log.addRangeErrorFmt( &result.source, import_record.range, bundler.allocator, - "Could not resolve: \"{s}\" relative to \"{s}\"", - .{ import_record.path.text, bundler.fs.relativeTo(result.source.key_path.text) }, + "Could not resolve: \"{s}\"", + .{ + import_record.path.text, + }, ); } }, diff --git a/src/cli.zig b/src/cli.zig index 27e834bb8..dbacee76f 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -330,7 +330,13 @@ pub const Cli = struct { const do_we_need_to_close = open_file_limit > result.output_files.len * 2; did_write = true; var root_dir = try std.fs.openDirAbsolute(result.outbase, std.fs.Dir.OpenDirOptions{}); - defer root_dir.close(); + + defer { + if (do_we_need_to_close) { + root_dir.close(); + } + } + for (result.output_files) |f| { var fp = f.path; if (fp[0] == std.fs.path.sep) { diff --git a/src/js_ast.zig b/src/js_ast.zig index 7c94b9872..4b65d8018 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -42,7 +42,7 @@ pub const ExprNodeList = []Expr; pub const StmtNodeList = []Stmt; pub const BindingNodeList = []Binding; -pub const ImportItemStatus = enum { +pub const ImportItemStatus = enum(u2) { none, // The linker doesn't report import/export mismatch errors @@ -52,7 +52,7 @@ pub const ImportItemStatus = enum { missing, }; -pub const AssignTarget = enum { +pub const AssignTarget = enum(u2) { none, replace, // "a = b" update, // "a += b" @@ -65,8 +65,6 @@ pub const Flags = struct { is_key_before_rest: bool = false, }; - // Instead of 5 bytes for booleans, we can store it in 5 bits - // It will still round up to 1 byte. But that's 4 bytes less! pub const Property = packed struct { is_computed: bool = false, is_method: bool = false, @@ -177,7 +175,7 @@ pub const Binding = struct { } } - pub const Tag = packed enum { + pub const Tag = enum(u5) { b_identifier, b_array, b_property, @@ -340,7 +338,7 @@ pub const G = struct { kind: Kind = Kind.normal, flags: Flags.Property = Flags.Property.None, - pub const Kind = packed enum { + pub const Kind = enum(u2) { normal, get, set, @@ -678,7 +676,7 @@ pub const E = struct { op: Op.Code, }; - pub const Boolean = struct { value: bool }; + pub const Boolean = packed struct { value: bool }; pub const Super = struct {}; pub const Null = struct {}; pub const This = struct {}; @@ -1024,7 +1022,7 @@ pub const E = struct { no: ExprNodeIndex, }; - pub const Require = struct { + pub const Require = packed struct { import_record_index: u32 = 0, }; @@ -1305,7 +1303,7 @@ pub const Stmt = struct { } } - pub const Tag = packed enum { + pub const Tag = enum(u6) { s_block, s_break, s_class, @@ -1927,7 +1925,7 @@ pub const Expr = struct { } } - pub const Tag = packed enum { + pub const Tag = enum(u6) { e_array, e_unary, e_binary, @@ -1963,7 +1961,6 @@ pub const Expr = struct { e_import, e_this, e_class, - e_require, pub fn isArray(self: Tag) bool { @@ -2676,7 +2673,7 @@ pub const S = struct { // statements where the import is never used. was_ts_import_equals: bool = false, - pub const Kind = enum { + pub const Kind = enum(u2) { k_var, k_let, k_const, diff --git a/src/js_lexer.zig b/src/js_lexer.zig index 1ee2ae084..80a30e045 100644 --- a/src/js_lexer.zig +++ b/src/js_lexer.zig @@ -1504,7 +1504,9 @@ pub const Lexer = struct { } pub fn expected(self: *LexerType, token: T) !void { - if (tokenToString.get(token).len > 0) { + if (self.is_log_disabled) { + return error.Backtrack; + } else if (tokenToString.get(token).len > 0) { try self.expectedString(tokenToString.get(token)); } else { try self.unexpected(); diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index 7e9105ab8..6776dba7b 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -3274,7 +3274,7 @@ pub const P = struct { try p.lexer.expect(.t_close_brace); }, else => { - try p.lexer.unexpected(); + // try p.lexer.unexpected(); return error.Backtrack; }, } @@ -6489,7 +6489,7 @@ pub const P = struct { } pub const Backtracking = struct { - pub fn lexerBacktracker(p: *P, func: anytype) bool { + pub inline fn lexerBacktracker(p: *P, func: anytype) bool { var old_lexer = std.mem.toBytes(p.lexer); const old_log_disabled = p.lexer.is_log_disabled; p.lexer.is_log_disabled = true; |