From a32f8701546e62e136d28b3748bb6d308864fca9 Mon Sep 17 00:00:00 2001 From: AskSkivdal Date: Sun, 14 Dec 2025 20:16:36 +0100 Subject: [PATCH 1/2] Check last part of path in check_token, not the first one --- src/utils.rs | 8 +++++++- test/issue-56/rust.rs | 9 +++++++++ test/issue-56/tsync.sh | 8 ++++++++ test/issue-56/typescript.d.ts | 8 ++++++++ test/issue-56/typescript.ts | 8 ++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/issue-56/rust.rs create mode 100755 test/issue-56/tsync.sh create mode 100644 test/issue-56/typescript.d.ts create mode 100644 test/issue-56/typescript.ts 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, +} From d15d231ccb2977965e48297cf28e3a7e7d27ad37 Mon Sep 17 00:00:00 2001 From: AskSkivdal Date: Sun, 14 Dec 2025 20:17:12 +0100 Subject: [PATCH 2/2] Update test all --- test/test_all.sh | 1 + 1 file changed, 1 insertion(+) 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