Skip to content

Commit a178d91

Browse files
committed
refactor(js): unify exportModule and
exportModuleWithOptions into single function
1 parent 787d922 commit a178d91

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

examples/js_dsl/mod.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub fn getEnvRefcount() Number {
306306
// ============================================================================
307307

308308
comptime {
309-
js.exportModuleWithOptions(@This(), .{
309+
js.exportModule(@This(), .{
310310
.init = struct {
311311
fn f(refcount: u32) !void {
312312
const count = module_init_count.fetchAdd(1, .monotonic);

src/js.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pub const createPromise = @import("js/promise.zig").createPromise;
4343
pub const wrapFunction = @import("js/wrap_function.zig").wrapFunction;
4444
pub const wrapClass = @import("js/wrap_class.zig").wrapClass;
4545
pub const exportModule = @import("js/export_module.zig").exportModule;
46-
pub const exportModuleWithOptions = @import("js/export_module.zig").exportModuleWithOptions;
4746

4847
// Comptime helpers (public for advanced use)
4948
pub const isDslType = @import("js/wrap_function.zig").isDslType;

src/js/export_module.zig

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@ const context = @import("context.zig");
44
const wrap_function = @import("wrap_function.zig");
55
const wrap_class = @import("wrap_class.zig");
66

7-
/// Simple module export — scans pub decls and registers them.
8-
/// No lifecycle hooks or env refcounting.
7+
/// Scans pub decls of `Module` and registers them as JS exports.
98
///
10-
/// Usage: `comptime { js.exportModule(@This()); }`
11-
pub fn exportModule(comptime Module: type) void {
12-
exportModuleWithOptions(Module, .{});
13-
}
14-
15-
/// Module export with optional lifecycle hooks and env refcounting.
16-
///
17-
/// Options fields (all optional):
18-
/// .init = fn (refcount: u32) !void — called during registration
19-
/// .cleanup = fn (refcount: u32) void — called on env exit
9+
/// Optional second argument for lifecycle hooks:
10+
/// js.exportModule(@This(), .{
11+
/// .init = fn (refcount: u32) !void, — called during registration
12+
/// .cleanup = fn (refcount: u32) void, — called on env exit
13+
/// })
2014
///
2115
/// The DSL manages an atomic refcount internally:
2216
/// - .init receives the refcount BEFORE increment (0 = first env)
2317
/// - .cleanup receives the refcount AFTER decrement (0 = last env)
24-
pub fn exportModuleWithOptions(comptime Module: type, comptime options: anytype) void {
18+
///
19+
/// Usage:
20+
/// comptime { js.exportModule(@This()); }
21+
/// comptime { js.exportModule(@This(), .{ .init = ..., .cleanup = ... }); }
22+
pub fn exportModule(comptime Module: type, comptime options: anytype) void {
2523
const has_init = @hasField(@TypeOf(options), "init");
2624
const has_cleanup = @hasField(@TypeOf(options), "cleanup");
2725
const has_lifecycle = has_init or has_cleanup;

0 commit comments

Comments
 (0)