Merge pull request #964 from napi-rs/fix-struct-gen
fix(napi-derive): return Class instance in function
This commit is contained in:
commit
b05e0e713f
6 changed files with 25 additions and 1 deletions
|
@ -163,7 +163,7 @@ impl NapiStruct {
|
|||
|
||||
fn gen_to_napi_value_ctor_impl(&self) -> TokenStream {
|
||||
let name = &self.name;
|
||||
let js_name_str = &self.js_name;
|
||||
let js_name_str = format!("{}\0", &self.js_name);
|
||||
|
||||
let mut field_conversions = vec![];
|
||||
let mut field_destructions = vec![];
|
||||
|
|
|
@ -144,6 +144,11 @@ Generated by [AVA](https://avajs.dev).
|
|||
whoami(): string␊
|
||||
/** This is static... */␊
|
||||
static getDogKind(): Kind␊
|
||||
returnOtherClass(): Dog␊
|
||||
}␊
|
||||
export class Dog {␊
|
||||
name: string␊
|
||||
constructor(name: string)␊
|
||||
}␊
|
||||
/** Smoking test for type generation */␊
|
||||
export class Blake2BHasher {␊
|
||||
|
|
Binary file not shown.
|
@ -69,6 +69,7 @@ import {
|
|||
appendBuffer,
|
||||
returnNull,
|
||||
returnUndefined,
|
||||
Dog,
|
||||
} from '../'
|
||||
|
||||
test('export const', (t) => {
|
||||
|
@ -125,6 +126,7 @@ test('class', (t) => {
|
|||
|
||||
dog.name = '可乐'
|
||||
t.is(dog.name, '可乐')
|
||||
t.deepEqual(dog.returnOtherClass(), new Dog('Doge'))
|
||||
})
|
||||
|
||||
test('class factory', (t) => {
|
||||
|
|
5
examples/napi/index.d.ts
vendored
5
examples/napi/index.d.ts
vendored
|
@ -134,6 +134,11 @@ export class Animal {
|
|||
whoami(): string
|
||||
/** This is static... */
|
||||
static getDogKind(): Kind
|
||||
returnOtherClass(): Dog
|
||||
}
|
||||
export class Dog {
|
||||
name: string
|
||||
constructor(name: string)
|
||||
}
|
||||
/** Smoking test for type generation */
|
||||
export class Blake2BHasher {
|
||||
|
|
|
@ -60,6 +60,18 @@ impl Animal {
|
|||
pub fn get_dog_kind() -> Kind {
|
||||
Kind::Dog
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn return_other_class(&self) -> Dog {
|
||||
Dog {
|
||||
name: "Doge".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(constructor)]
|
||||
pub struct Dog {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// Smoking test for type generation
|
||||
|
|
Loading…
Reference in a new issue