mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Use a better error label
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user