diff options
author | 2023-09-16 22:52:49 -0700 | |
---|---|---|
committer | 2023-09-16 22:52:49 -0700 | |
commit | ea660b338d6898adce2cc95629cb1461b4333ff8 (patch) | |
tree | 496ce03cbb9fed7dfb1dec430fc30dedd64d4ba7 | |
parent | 8c8dd8b69c15920f3e2c1ef69f2cf0064efb997a (diff) | |
download | bun-ea660b338d6898adce2cc95629cb1461b4333ff8.tar.gz bun-ea660b338d6898adce2cc95629cb1461b4333ff8.tar.zst bun-ea660b338d6898adce2cc95629cb1461b4333ff8.zip |
Use a better error labeljarred/cleanup-error
-rw-r--r-- | src/bundler/bundle_v2.zig | 4 | ||||
-rw-r--r-- | src/import_record.zig | 17 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 64aaf54d9..359272e5f 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -512,7 +512,7 @@ pub const BundleV2 = struct { import_record.range, this.graph.allocator, "Browser build cannot {s} Node.js module: \"{s}\". To use Node.js builtins, set target to 'node' or 'bun'", - .{ import_record.kind.label(), path_to_use }, + .{ import_record.kind.errorLabel(), path_to_use }, import_record.kind, ) catch unreachable; } else { @@ -1915,7 +1915,7 @@ pub const BundleV2 = struct { import_record.range, this.graph.allocator, "Browser build cannot {s} Node.js builtin: \"{s}\". To use Node.js builtins, set target to 'node' or 'bun'", - .{ import_record.kind.label(), import_record.path.text }, + .{ import_record.kind.errorLabel(), import_record.path.text }, import_record.kind, ) catch @panic("unexpected log error"); } else { diff --git a/src/import_record.zig b/src/import_record.zig index 3044c9b47..d48cfb1b0 100644 --- a/src/import_record.zig +++ b/src/import_record.zig @@ -51,10 +51,27 @@ pub const ImportKind = enum(u8) { break :brk labels; }; + pub const error_labels: Label = brk: { + var labels = Label.initFill(""); + labels.set(ImportKind.entry_point, "entry point"); + labels.set(ImportKind.stmt, "import"); + labels.set(ImportKind.require, "require()"); + labels.set(ImportKind.dynamic, "import()"); + labels.set(ImportKind.require_resolve, "require.resolve"); + labels.set(ImportKind.at, "@import"); + labels.set(ImportKind.url, "url()"); + labels.set(ImportKind.internal, "<bun internal>"); + break :brk labels; + }; + pub inline fn label(this: ImportKind) []const u8 { return all_labels.get(this); } + pub inline fn errorLabel(this: ImportKind) []const u8 { + return error_labels.get(this); + } + pub inline fn isCommonJS(this: ImportKind) bool { return switch (this) { .require, .require_resolve => true, |