Skip to content

Commit 2500879

Browse files
Use inner value of Box (#63). (#64)
Add tests that cover Box values Co-authored-by: Anthony Rubick <[email protected]>
1 parent 439497d commit 2500879

6 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/typescript.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ fn try_match_with_args(ident: &str, args: &syn::PathArguments) -> Result<TsType,
7777
_ => "unknown".to_owned(),
7878
},
7979
}),
80+
"Box" => Ok(TsType {
81+
is_optional: false,
82+
ts_type: match &args {
83+
syn::PathArguments::Parenthesized(parenthesized_argument) => {
84+
format!("{:?}", parenthesized_argument)
85+
}
86+
syn::PathArguments::AngleBracketed(angle_bracketed_argument) => {
87+
convert_generic(angle_bracketed_argument.args.first().unwrap()).ts_type
88+
}
89+
_ => "unknown".to_owned(),
90+
},
91+
}),
8092
"Vec" => Ok(match &args {
8193
syn::PathArguments::Parenthesized(parenthesized_argument) => {
8294
format!("{:?}", parenthesized_argument).into()
@@ -196,6 +208,7 @@ pub fn convert_type(ty: &syn::Type) -> TsType {
196208
is_optional: false,
197209
}
198210
}
211+
199212
_ => "unknown".to_owned().into(),
200213
}
201214
}

test/issue-63/rust.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[tsync]
2+
struct TestStruct {
3+
size: Box<i32>,
4+
}
5+
6+
#[tsync]
7+
const v: Box<i32> = 23;
8+
9+
#[tsync]
10+
struct TestStruct2 {
11+
inner: Box<TestStruct>,
12+
inner_unboxed: TestStruct,
13+
}

test/issue-63/tsync.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
4+
5+
cd $SCRIPT_DIR
6+
7+
cargo run -- -i rust.rs -o typescript.d.ts
8+
cargo run -- -i rust.rs -o typescript.ts

test/issue-63/typescript.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* This file is generated and managed by tsync */
2+
3+
interface TestStruct {
4+
size: number;
5+
}
6+
7+
interface TestStruct2 {
8+
inner: TestStruct;
9+
inner_unboxed: TestStruct;
10+
}

test/issue-63/typescript.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* This file is generated and managed by tsync */
2+
3+
export interface TestStruct {
4+
size: number;
5+
}
6+
7+
export const v = 23;
8+
9+
export interface TestStruct2 {
10+
inner: TestStruct;
11+
inner_unboxed: TestStruct;
12+
}

test/test_all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ cd $SCRIPT_DIR
1717
./issue-43/tsync.sh
1818
./issue-55/tsync.sh
1919
./issue-58/tsync.sh
20+
./issue-63/tsync.sh
2021
./issue-65-untagged-enums/tsync.sh
2122
./raw_identifiers/tsync.sh

0 commit comments

Comments
 (0)