Skip to content

Commit 6cb4117

Browse files
committed
refactor: return non-nullable from InitFunction
1 parent e0b8538 commit 6cb4117

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/root.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ pub fn @"export"(comptime value: anytype) void {
6161
/// ```
6262
pub fn init(comptime f: InitFunction) void {
6363
const module = opaque {
64-
pub fn napi_register_module_v1(env: c.napi_env, exp: c.napi_value) callconv(.c) c.napi_value {
64+
pub fn napi_register_module_v1(env: c.napi_env, _: c.napi_value) callconv(.c) c.napi_value {
6565
const node = NodeContext.init(env);
6666

6767
const exports = f(node) catch |err| {
6868
node.handleError(err);
6969
return null;
7070
};
7171

72-
return if (exports) |v| v.napi_value else exp;
72+
return exports.napi_value;
7373
}
7474
};
7575

@@ -79,7 +79,7 @@ pub fn init(comptime f: InitFunction) void {
7979
/// The InitFunction to pass to the `register` method. The `ctx` parameter
8080
/// represents the Node context. The returned value becomes the `exports` value
8181
/// of the JS module.
82-
pub const InitFunction = fn (ctx: NodeContext) anyerror!?NodeValue;
82+
pub const InitFunction = fn (ctx: NodeContext) anyerror!NodeValue;
8383

8484
inline fn registerModule(comptime ptr: *const anyopaque) void {
8585
@export(ptr, .{ .name = "napi_register_module_v1" });

tests/zig_modules/test-module/src/root.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ comptime {
1111
node_api.init(init);
1212
}
1313

14-
fn init(node: node_api.NodeContext) !?node_api.NodeValue {
14+
fn init(node: node_api.NodeContext) !node_api.NodeValue {
1515
const ptr = try std.heap.c_allocator.create(WrapTarget);
1616
ptr.* = .{ .foo = 123, .bar = "hopla" };
1717

0 commit comments

Comments
 (0)