Use a better error label

This commit is contained in:
Jarred Sumner
2023-09-16 22:52:49 -07:00
parent 4e0c589562
commit f5b37fa0b0
2 changed files with 19 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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,