Skip to content

Commit

Permalink
Use bun.ComptimeStringMap instead of std.StaticStringMap (oven-sh…
Browse files Browse the repository at this point in the history
…#12351)

Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
  • Loading branch information
Jarred-Sumner and Jarred-Sumner authored Jul 5, 2024
1 parent 4f3ef07 commit ee25618
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/bun.js/ipc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub const Mode = enum {
/// This must match the behavior of node.js, and supports bun <--> node.js/etc communication.
json,

const Map = std.StaticStringMap(Mode).initComptime(.{
const Map = bun.ComptimeStringMap(Mode, .{
.{ "advanced", .advanced },
.{ "json", .json },
});
Expand Down
17 changes: 9 additions & 8 deletions src/js_lexer_tables.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const unicode = std.unicode;
const default_allocator = bun.default_allocator;
const string = @import("string_types.zig").string;
const CodePoint = @import("string_types.zig").CodePoint;
const ComptimeStringMap = bun.ComptimeStringMap;

pub const T = enum(u8) {
t_end_of_file,
Expand Down Expand Up @@ -159,7 +160,7 @@ pub const T = enum(u8) {
}
};

pub const Keywords = std.StaticStringMap(T).initComptime(.{
pub const Keywords = ComptimeStringMap(T, .{
.{ "break", .t_break },
.{ "case", .t_case },
.{ "catch", .t_catch },
Expand Down Expand Up @@ -198,7 +199,7 @@ pub const Keywords = std.StaticStringMap(T).initComptime(.{
.{ "with", .t_with },
});

pub const StrictModeReservedWords = std.StaticStringMap(void).initComptime(.{
pub const StrictModeReservedWords = ComptimeStringMap(void, .{
.{ "implements", {} },
.{ "interface", {} },
.{ "let", {} },
Expand All @@ -210,7 +211,7 @@ pub const StrictModeReservedWords = std.StaticStringMap(void).initComptime(.{
.{ "yield", {} },
});

pub const StrictModeReservedWordsRemap = std.StaticStringMap(string).initComptime(.{
pub const StrictModeReservedWordsRemap = ComptimeStringMap(string, .{
.{ "implements", "_implements" },
.{ "interface", "_interface" },
.{ "let", "_let" },
Expand All @@ -235,7 +236,7 @@ pub const PropertyModifierKeyword = enum {
p_set,
p_static,

pub const List = std.StaticStringMap(PropertyModifierKeyword).initComptime(.{
pub const List = ComptimeStringMap(PropertyModifierKeyword, .{
.{ "abstract", .p_abstract },
.{ "async", .p_async },
.{ "declare", .p_declare },
Expand All @@ -250,7 +251,7 @@ pub const PropertyModifierKeyword = enum {
});
};

pub const TypeScriptAccessibilityModifier = std.StaticStringMap(void).initComptime(.{
pub const TypeScriptAccessibilityModifier = ComptimeStringMap(void, .{
.{ "override", void },
.{ "private", void },
.{ "protected", void },
Expand Down Expand Up @@ -519,7 +520,7 @@ pub const TypescriptStmtKeyword = enum {
ts_stmt_global,
ts_stmt_declare,

pub const List = std.StaticStringMap(TypescriptStmtKeyword).initComptime(.{
pub const List = ComptimeStringMap(TypescriptStmtKeyword, .{
.{
"type",
TypescriptStmtKeyword.ts_stmt_type,
Expand Down Expand Up @@ -552,7 +553,7 @@ pub const TypescriptStmtKeyword = enum {
};

// Error: meta is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`.
pub const ChildlessJSXTags = std.StaticStringMap(void).initComptime(.{
pub const ChildlessJSXTags = ComptimeStringMap(void, .{
.{ "area", void },
.{ "base", void },
.{ "br", void },
Expand All @@ -572,7 +573,7 @@ pub const ChildlessJSXTags = std.StaticStringMap(void).initComptime(.{
});

// In a microbenchmark, this outperforms
pub const jsxEntity = std.StaticStringMap(CodePoint).initComptime(.{
pub const jsxEntity = ComptimeStringMap(CodePoint, .{
.{ "Aacute", @as(CodePoint, 0x00C1) },
.{ "aacute", @as(CodePoint, 0x00E1) },
.{ "Acirc", @as(CodePoint, 0x00C2) },
Expand Down
4 changes: 2 additions & 2 deletions src/js_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ pub const TypeScript = struct {
else => return null,
}
}
pub const IMap = std.StaticStringMap(Kind).initComptime(.{
pub const IMap = bun.ComptimeStringMap(Kind, .{
.{ "unique", .unique },
.{ "abstract", .abstract },
.{ "asserts", .asserts },
Expand Down Expand Up @@ -2560,7 +2560,7 @@ const AsyncPrefixExpression = enum(u2) {
is_async,
is_await,

const map = std.StaticStringMap(AsyncPrefixExpression).initComptime(.{
const map = bun.ComptimeStringMap(AsyncPrefixExpression, .{
.{ "yield", .is_yield },
.{ "await", .is_await },
.{ "async", .is_async },
Expand Down
2 changes: 1 addition & 1 deletion src/open.zig
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub const Editor = enum(u8) {
const StringMap = std.EnumMap(Editor, string);
const StringArrayMap = std.EnumMap(Editor, []const [:0]const u8);

const name_map = std.StaticStringMap(Editor).initComptime(.{
const name_map = bun.ComptimeStringMap(Editor, .{
.{ "sublime", .sublime },
.{ "subl", .sublime },
.{ "vscode", .vscode },
Expand Down
4 changes: 2 additions & 2 deletions src/options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub const ExternalModules = struct {
"zlib",
};

pub const NodeBuiltinsMap = std.StaticStringMap(void).initComptime(.{
pub const NodeBuiltinsMap = bun.ComptimeStringMap(void, .{
.{ "_http_agent", {} },
.{ "_http_client", {} },
.{ "_http_common", {} },
Expand Down Expand Up @@ -370,7 +370,7 @@ pub const ModuleType = enum {
cjs,
esm,

pub const List = std.StaticStringMap(ModuleType).initComptime(.{
pub const List = bun.ComptimeStringMap(ModuleType, .{
.{ "commonjs", ModuleType.cjs },
.{ "module", ModuleType.esm },
});
Expand Down
2 changes: 1 addition & 1 deletion src/resolver/tsconfig_json.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub const TSConfigJSON = struct {
remove,
invalid,

pub const List = std.StaticStringMap(ImportsNotUsedAsValue).initComptime(.{
pub const List = bun.ComptimeStringMap(ImportsNotUsedAsValue, .{
.{ "preserve", .preserve },
.{ "error", .err },
.{ "remove", .remove },
Expand Down
20 changes: 10 additions & 10 deletions test/js/node/timers.promises/timers.promises.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ describe("setTimeout", () => {
it("abort() does not emit global error", async () => {
let unhandledRejectionCaught = false;

const catchUnhandledRejection = () => {
const catchUnhandledRejection = () => {
unhandledRejectionCaught = true;
};
process.on('unhandledRejection', catchUnhandledRejection);
process.on("unhandledRejection", catchUnhandledRejection);

const c = new AbortController();

global.setTimeout(() => c.abort());

await setTimeout(100, undefined, { signal: c.signal }).catch(() => "aborted");

// let unhandledRejection to be fired
await setTimeout(100)
await setTimeout(100);

process.off('unhandledRejection', catchUnhandledRejection);
process.off("unhandledRejection", catchUnhandledRejection);

expect(c.signal.aborted).toBe(true);
expect(unhandledRejectionCaught).toBe(false);
Expand All @@ -30,21 +30,21 @@ describe("setImmediate", () => {
it("abort() does not emit global error", async () => {
let unhandledRejectionCaught = false;

const catchUnhandledRejection = () => {
const catchUnhandledRejection = () => {
unhandledRejectionCaught = true;
};
process.on('unhandledRejection', catchUnhandledRejection);
process.on("unhandledRejection", catchUnhandledRejection);

const c = new AbortController();

global.setImmediate(() => c.abort());

await setImmediate(undefined, { signal: c.signal }).catch(() => "aborted");

// let unhandledRejection to be fired
await setTimeout(100)
await setTimeout(100);

process.off('unhandledRejection', catchUnhandledRejection);
process.off("unhandledRejection", catchUnhandledRejection);

expect(c.signal.aborted).toBe(true);
expect(unhandledRejectionCaught).toBe(false);
Expand Down

0 comments on commit ee25618

Please sign in to comment.