diff --git a/src/utils.rs b/src/utils.rs index fa60d73..dbc03e7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -94,7 +94,13 @@ fn check_token(token: proc_macro2::TokenTree, arg: &str) -> Option { // returns true. .map_while(check_expression_is_path) // Check if any yielded paths equal `arg` - .any(|expr_path| expr_path.path.segments[0].ident.to_string().eq(arg)) + .any(|expr_path| { + if let Some(last) = expr_path.path.segments.last() { + last.ident.to_string().eq(arg) + } else { + false + } + }) // If so, return `Some(arg)`, otherwise `None`. .then_some(arg.to_owned()) }) diff --git a/test/issue-56/rust.rs b/test/issue-56/rust.rs new file mode 100644 index 0000000..09f39f4 --- /dev/null +++ b/test/issue-56/rust.rs @@ -0,0 +1,9 @@ +#[derive(serde_repr::Serialize_repr)] +#[repr(u16)] +#[tsync] +pub enum KeyCode { + Space = 32, + Apostrophe = 39, + Comma = 44, + Minus = 45, +} diff --git a/test/issue-56/tsync.sh b/test/issue-56/tsync.sh new file mode 100755 index 0000000..1764bd6 --- /dev/null +++ b/test/issue-56/tsync.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +cd $SCRIPT_DIR + +cargo run -- -i rust.rs -o typescript.d.ts +cargo run -- -i rust.rs -o typescript.ts \ No newline at end of file diff --git a/test/issue-56/typescript.d.ts b/test/issue-56/typescript.d.ts new file mode 100644 index 0000000..ac1d1c3 --- /dev/null +++ b/test/issue-56/typescript.d.ts @@ -0,0 +1,8 @@ +/* This file is generated and managed by tsync */ + +declare enum KeyCode { + Space = 32, + Apostrophe = 39, + Comma = 44, + Minus = 45, +} diff --git a/test/issue-56/typescript.ts b/test/issue-56/typescript.ts new file mode 100644 index 0000000..9b032ef --- /dev/null +++ b/test/issue-56/typescript.ts @@ -0,0 +1,8 @@ +/* This file is generated and managed by tsync */ + +export enum KeyCode { + Space = 32, + Apostrophe = 39, + Comma = 44, + Minus = 45, +} diff --git a/test/test_all.sh b/test/test_all.sh index 89de09f..5af45fb 100755 --- a/test/test_all.sh +++ b/test/test_all.sh @@ -17,6 +17,7 @@ cd $SCRIPT_DIR ./issue-42-serde-rename/tsync.sh ./issue-43/tsync.sh ./issue-55/tsync.sh +./issue-56/tsync.sh ./issue-58/tsync.sh ./issue-60/tsync.sh ./issue-63/tsync.sh