Skip to content

feat(node-loader): disambiguate ObjectPattern and ArrayPattern parameters for signature discovery - #950

Merged
viferga merged 3 commits into
metacall:developfrom
TheDoomBoy-jab:fix/node-loader-object-pattern
Nov 15, 2026
Merged

viferga merged 3 commits into
metacall:developfrom
TheDoomBoy-jab:fix/node-loader-object-pattern

Conversation

@TheDoomBoy-jab

@TheDoomBoy-jab TheDoomBoy-jab commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

This PR implements parameter disambiguation for destructured objects (ObjectPattern) and arrays (ArrayPattern) vs positional parameters in the Node.js loader reflection mechanism.

• bootstrap.js:
• Detects ObjectPattern and default-assigned ObjectPattern in the AST and marks their parameter type as 'Map'.
• Detects ArrayPattern and default-assigned ArrayPattern in the AST and marks their parameter type as 'Array'.
• Maintains 1-to-1 index alignment between args and types, pushing null for regular positional parameters.
• Exposes types on the discovery descriptor only when typed parameters are present.
• node_loader_impl.cpp:
• Adds napi_typeof check on parameter_type before attempting string conversion.
• If valuetype == napi_string, retrieves the type string and calls signature_set(...) with loader_impl_type(...).
• If valuetype != napi_string (e.g. null for positional parameters in mixed signatures like foo(x, { a, b })), gracefully registers the parameter as untyped (NULL) without throwing N-API type errors.
• metacall_node_test.cpp:
• Tests parameter type inspection (METACALL_MAP, METACALL_ARRAY) and validates end-to-end function invocation and return values for both destructured map and array functions.

@TheDoomBoy-jab
TheDoomBoy-jab force-pushed the fix/node-loader-object-pattern branch from f2b3181 to 681c61a Compare November 6, 2026 14:13
@viferga

viferga commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

I ran the CI, I have a question, what's the array that you left as TODO?

// TODO: Support ArrayPattern for array destructuring if needed

Can you implement it too?

@TheDoomBoy-jab

Copy link
Copy Markdown
Contributor Author

@viferga so like an arraypattern is when the args map into an array for the ast, example args when passed like this function idk([a,b]){}, it's just adding another if else condition so that it identifies arrayPattern, yeah i will add that to this!

@viferga

viferga commented Nov 14, 2026

Copy link
Copy Markdown
Member

Can you add a call to each function to validate it also works?

@TheDoomBoy-jab

Copy link
Copy Markdown
Contributor Author

on it

@TheDoomBoy-jab

Copy link
Copy Markdown
Contributor Author

added the function calls in the test

@TheDoomBoy-jab TheDoomBoy-jab changed the title feat(node-loader): disambiguate ObjectPattern parameters for signatur… feat(node-loader): disambiguate ObjectPattern and ArrayPattern parameters for signature discovery Nov 14, 2026
@viferga

viferga commented Nov 14, 2026

Copy link
Copy Markdown
Member

Excellent mate, running the CI.

@viferga
viferga merged commit 97f2d05 into metacall:develop Nov 15, 2026
83 of 100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants