mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
@@ -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,
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user