Skip to content

Commit 1b70bac

Browse files
committed
fix: escaping is not needed in schemy-ts
1 parent 74dd354 commit 1b70bac

1 file changed

Lines changed: 2 additions & 29 deletions

File tree

schemy-ts/src/main.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ pub struct Item {
138138
}
139139

140140
mod string_helpers {
141-
use std::{borrow::Cow, collections::HashSet, sync::LazyLock};
141+
use std::borrow::Cow;
142142

143-
use log::{info, trace};
143+
use log::trace;
144144

145145
pub fn capitalize(s: Cow<'_, str>) -> Cow<'_, str> {
146146
trace!("Capitalizing {s}");
@@ -207,30 +207,6 @@ mod string_helpers {
207207
Cow::Owned(result)
208208
}
209209
}
210-
211-
static KEYWORD_SET: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
212-
info!("Initializing KEYWORD_SET");
213-
[
214-
"as", "break", "const", "continue", "crate", "else", "enum", "extern", "false", "fn",
215-
"for", "if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref",
216-
"return", "self", "Self", "static", "struct", "super", "trait", "true", "type",
217-
"unsafe", "use", "where", "while", "async", "await", "dyn", "abstract", "become",
218-
"box", "do", "final", "macro", "override", "priv", "try", "typeof", "unsized",
219-
"virtual", "yield",
220-
]
221-
.into_iter()
222-
.collect()
223-
});
224-
225-
pub fn escape_if_keyword(s: Cow<'_, str>) -> Cow<'_, str> {
226-
trace!("Checking if {s} is a keyword");
227-
if KEYWORD_SET.contains(s.as_ref()) {
228-
let escaped_string = format!("_{}", s);
229-
Cow::Owned(escaped_string)
230-
} else {
231-
s
232-
}
233-
}
234210
}
235211

236212
use string_helpers::*;
@@ -242,7 +218,6 @@ impl Item {
242218
let name = self.label.value();
243219
let name = Cow::Borrowed(name);
244220
let name = replace_leading_digit_with_word(name);
245-
let name = escape_if_keyword(name);
246221

247222
name
248223
}
@@ -253,7 +228,6 @@ impl Item {
253228
let name = self.label.value();
254229
let name = Cow::Borrowed(name);
255230
let name = replace_leading_digit_with_word(name);
256-
let name = escape_if_keyword(name);
257231
let name = format!("{name}Enum");
258232
let name = Cow::Owned(name);
259233

@@ -268,7 +242,6 @@ impl Item {
268242
let name = replace_leading_digit_with_word(name);
269243
let name = name.to_snake_case();
270244
let name = Cow::Owned(name);
271-
let name = escape_if_keyword(name);
272245

273246
name
274247
}

0 commit comments

Comments
 (0)