This commit introduces two main changes:
1. Refactors the variable names used during the creation of
`NapiStruct` in `crates/macro/src/parser/mod.rs`. The goal is to
make the source of `NapiStruct.name` (the Rust identifier) and
`NapiStruct.js_name` (the JavaScript name, potentially from a
`#[napi(js_name = "...")]` attribute) more explicit. This change
is primarily for code readability and maintainability. The core
logic remains the same.
2. Adds a new test case to `examples/napi` to specifically verify
the behavior of `#[napi(js_name = "...")]` on structs. This
includes:
- A new Rust struct `OriginalRustNameForJsNamedStruct` in
`examples/napi/src/class.rs` decorated with
`#[napi(js_name = "MyJsNamedClass")]`.
- Corresponding tests in `examples/napi/__tests__/values.spec.ts`
that check for correct class instantiation, method calls, and
type alias generation (`OriginalRustNameForJsNamedStruct` as an
alias for `MyJsNamedClass`).
Note: I encountered some issues running the full build and tests for the example due to pre-commit hooks in the testing environment that I couldn't bypass. However, I believe the changes are correct based on static analysis and focused checks.
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
* Implement FromNapiValue trait as macro
Code behavior should remain the same, with much less copy-pasting of the same code.
Additionally, this commit adds a unit tests for test for FromNapiValue
for tuple trait which appears to be currently missing.
* Simplify macro arr_get
Rewrite the macro to reduce the size of expanded code of the macro
(from 4088 to 2429 lines). Although this is a minor change,
this may help reduce the size of compiled library.
* Refactor typegen Type::Path
Removes the need for keeping mutable variable, as its only assigned once.
* [API BREAKING] Update api for calling functions.
This commit introduces new type FnArgs,
that is created with the goal of distinguishing between
calling JS function from rust with tuple as argument
and calling with multiple arguments.
Currently there is no possibility to add ToNapiValue value,
as tuple is used to call callback functions with more than one
argument from rust.
With this change, callbacks with multiple arguments,
should be called, with converting tuple of argument
into FnArgs struct, either by calling into() on such
tuple, or by creating FnArgs struct directly.
* Add support for FnArgs when generating TS types
Updated the macro for generating typescript types,
to correctly handle FnArgs struct. This is now treated
as passthrough type and generates the output from the
type inside of FnArgs struct.
* Implement ToNapiValue trait for tuple
With the changes to callback calling API, it's now possible
to safely add this change. This change allows to pass tuple
from rust code to JS to match the existing FromNapiValue trait
currently existing in the library.