Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/data/tests/can_quote_non_identifier_field_names/input.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[typeshare]
pub struct LinkedData {
#[serde(rename = "@type")]
pub kind: String,
#[serde(rename = "schema.org")]
pub schema_org: String,
#[serde(rename = "2fa")]
pub two_factor: bool,
#[serde(rename = "$ref")]
pub reference: String,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface LinkedData {
"@type": string;
"schema.org": string;
"2fa": boolean;
$ref: string;
}

7 changes: 6 additions & 1 deletion core/src/language/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,12 @@ impl TypeScript {
}

fn typescript_property_aware_rename(name: &str) -> String {
if name.chars().any(|c| c == '-') {
let mut chars = name.chars();
let is_identifier = chars
.next()
.is_some_and(|c| c.is_alphabetic() || c == '_' || c == '$')
&& chars.all(|c| c.is_alphanumeric() || c == '_' || c == '$');
if !is_identifier {
return format!("{name:?}");
}
name.to_string()
Expand Down
1 change: 1 addition & 0 deletions core/tests/snapshot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ tests! {
can_handle_serde_rename_on_top_level: [swift { prefix: "OP".to_string(), }, kotlin, scala, typescript, go, python];
can_generate_unit_structs: [swift, kotlin, scala, typescript, go, python];
kebab_case_rename: [swift, kotlin, scala, typescript, go, python];
can_quote_non_identifier_field_names: [typescript];

/// Globals get topologically sorted
orders_types: [swift, kotlin, go, python];
Expand Down