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
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|f| f.getter)
|
.filter(|f| f.getter)
|
||||||
.map(|f| {
|
.filter_map(|f| {
|
||||||
let mut field_str = String::from("");
|
|
||||||
|
|
||||||
if f.skip_typescript {
|
if f.skip_typescript {
|
||||||
return field_str;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut field_str = String::from("");
|
||||||
|
|
||||||
if !f.comments.is_empty() {
|
if !f.comments.is_empty() {
|
||||||
field_str.push_str(&js_doc_from_comments(&f.comments))
|
field_str.push_str(&js_doc_from_comments(&f.comments))
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ impl NapiStruct {
|
||||||
}
|
}
|
||||||
field_str.push_str(&arg);
|
field_str.push_str(&arg);
|
||||||
|
|
||||||
field_str
|
Some(field_str)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\\n");
|
.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
|
kind: number
|
||||||
constructor(name: string, 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 {
|
export class ClassWithFactory {
|
||||||
name: string
|
name: string
|
||||||
static withName(name: string): ClassWithFactory
|
static withName(name: string): ClassWithFactory
|
||||||
|
|
|
@ -120,3 +120,42 @@ pub struct AnimalWithDefaultConstructor {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub kind: u32,
|
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 {
|
fn enum_to_i32(e: CustomNumEnum) -> i32 {
|
||||||
e as 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
|
/// This is a const
|
||||||
pub const DEFAULT_COST: u32 = 12;
|
pub const DEFAULT_COST: u32 = 12;
|
||||||
|
|
||||||
|
#[napi(skip_typescript)]
|
||||||
|
pub const TYPE_SKIPPED_CONST: u32 = 12;
|
||||||
|
|
||||||
mod array;
|
mod array;
|
||||||
mod r#async;
|
mod r#async;
|
||||||
mod bigint;
|
mod bigint;
|
||||||
|
|
Loading…
Reference in a new issue