diff --git a/crates/backend/src/codegen/struct.rs b/crates/backend/src/codegen/struct.rs index eaf38521..ae0498f5 100644 --- a/crates/backend/src/codegen/struct.rs +++ b/crates/backend/src/codegen/struct.rs @@ -628,8 +628,14 @@ impl NapiStruct { }; let ty = &field.ty; - let getter_name = Ident::new(&format!("get_{}", field_name), Span::call_site()); - let setter_name = Ident::new(&format!("set_{}", field_name), Span::call_site()); + let getter_name = Ident::new( + &format!("get_{}", rm_raw_prefix(&field_name)), + Span::call_site(), + ); + let setter_name = Ident::new( + &format!("set_{}", rm_raw_prefix(&field_name)), + Span::call_site(), + ); if field.getter { let default_to_napi_value_convert = quote! { @@ -748,12 +754,18 @@ impl NapiStruct { }; if field.getter { - let getter_name = Ident::new(&format!("get_{}", field_name), Span::call_site()); + let getter_name = Ident::new( + &format!("get_{}", rm_raw_prefix(&field_name)), + Span::call_site(), + ); (quote! { .with_getter(#getter_name) }).to_tokens(&mut prop); } if field.writable && field.setter { - let setter_name = Ident::new(&format!("set_{}", field_name), Span::call_site()); + let setter_name = Ident::new( + &format!("set_{}", rm_raw_prefix(&field_name)), + Span::call_site(), + ); (quote! { .with_setter(#setter_name) }).to_tokens(&mut prop); } @@ -904,3 +916,11 @@ impl NapiImpl { }) } } + +fn rm_raw_prefix(s: &str) -> &str { + if s.starts_with("r#") { + &s[2..] + } else { + s + } +} diff --git a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md index 3b6ab303..921209c8 100644 --- a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md +++ b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md @@ -194,6 +194,14 @@ Generated by [AVA](https://avajs.dev). static optionOnly(optional?: string | undefined | null): string␊ }␊ ␊ + export class Selector {␊ + orderBy: Array␊ + select: Array␊ + struct: string␊ + where?: string␊ + constructor(orderBy: Array, select: Array, struct: string, where?: string)␊ + }␊ + ␊ export class Width {␊ value: number␊ constructor(value: number)␊ diff --git a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap index 9b0a029a..ec00a215 100644 Binary files a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap and b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap differ diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index cca48a99..ce84fd02 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -184,6 +184,14 @@ export class Optional { static optionOnly(optional?: string | undefined | null): string } +export class Selector { + orderBy: Array + select: Array + struct: string + where?: string + constructor(orderBy: Array, select: Array, struct: string, where?: string) +} + export class Width { value: number constructor(value: number) diff --git a/examples/napi/src/constructor.rs b/examples/napi/src/constructor.rs new file mode 100644 index 00000000..5661362b --- /dev/null +++ b/examples/napi/src/constructor.rs @@ -0,0 +1,7 @@ +#[napi(constructor)] +pub struct Selector { + pub order_by: Vec, + pub select: Vec, + pub r#struct: String, + pub r#where: Option, +} diff --git a/examples/napi/src/lib.rs b/examples/napi/src/lib.rs index 9fd31d27..cb2b24da 100644 --- a/examples/napi/src/lib.rs +++ b/examples/napi/src/lib.rs @@ -27,6 +27,7 @@ mod bigint; mod callback; mod class; mod class_factory; +mod constructor; mod date; mod either; mod r#enum;