test: add tests for skip_typescript
This commit is contained in:
parent
df9dc91562
commit
72f58204d2
5 changed files with 61 additions and 5 deletions
|
@ -73,13 +73,13 @@ impl NapiStruct {
|
|||
.fields
|
||||
.iter()
|
||||
.filter(|f| f.getter)
|
||||
.map(|f| {
|
||||
let mut field_str = String::from("");
|
||||
|
||||
.filter_map(|f| {
|
||||
if f.skip_typescript {
|
||||
return field_str;
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut field_str = String::from("");
|
||||
|
||||
if !f.comments.is_empty() {
|
||||
field_str.push_str(&js_doc_from_comments(&f.comments))
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ impl NapiStruct {
|
|||
}
|
||||
field_str.push_str(&arg);
|
||||
|
||||
field_str
|
||||
Some(field_str)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\\n");
|
||||
|
|
7
examples/napi/index.d.ts
vendored
7
examples/napi/index.d.ts
vendored
|
@ -146,6 +146,13 @@ export class AnimalWithDefaultConstructor {
|
|||
kind: number
|
||||
constructor(name: string, kind: number)
|
||||
}
|
||||
export class NinjaTurtle {
|
||||
name: string
|
||||
/** Create your ninja turtle! 🐢 */
|
||||
static newRaph(): NinjaTurtle
|
||||
getMaskColor(): string
|
||||
getName(): string
|
||||
}
|
||||
export class ClassWithFactory {
|
||||
name: string
|
||||
static withName(name: string): ClassWithFactory
|
||||
|
|
|
@ -120,3 +120,42 @@ pub struct AnimalWithDefaultConstructor {
|
|||
pub name: String,
|
||||
pub kind: u32,
|
||||
}
|
||||
|
||||
// Test for skip_typescript
|
||||
#[napi]
|
||||
pub struct NinjaTurtle {
|
||||
pub name: String,
|
||||
#[napi(skip_typescript)]
|
||||
pub mask_color: String,
|
||||
}
|
||||
|
||||
#[napi]
|
||||
impl NinjaTurtle {
|
||||
/// Create your ninja turtle! 🐢
|
||||
#[napi(factory)]
|
||||
pub fn new_raph() -> Self {
|
||||
Self {
|
||||
name: "Raphael".to_owned(),
|
||||
mask_color: "Red".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
/// We are not going to expose this character, so we just skip it...
|
||||
#[napi(factory, skip_typescript)]
|
||||
pub fn new_leo() -> Self {
|
||||
Self {
|
||||
name: "Leonardo".to_owned(),
|
||||
mask_color: "Blue".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn get_mask_color(&self) -> &str {
|
||||
self.mask_color.as_str()
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn get_name(&self) -> &str {
|
||||
self.name.as_str()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,3 +28,10 @@ pub enum CustomNumEnum {
|
|||
fn enum_to_i32(e: CustomNumEnum) -> i32 {
|
||||
e as i32
|
||||
}
|
||||
|
||||
#[napi(skip_typescript)]
|
||||
pub enum SkippedEnums {
|
||||
One = 1,
|
||||
Two,
|
||||
Tree,
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ extern crate serde_derive;
|
|||
/// This is a const
|
||||
pub const DEFAULT_COST: u32 = 12;
|
||||
|
||||
#[napi(skip_typescript)]
|
||||
pub const TYPE_SKIPPED_CONST: u32 = 12;
|
||||
|
||||
mod array;
|
||||
mod r#async;
|
||||
mod bigint;
|
||||
|
|
Loading…
Reference in a new issue