Working on implementing the typescript target

This commit is contained in:
Fabian Stamm
2025-05-26 23:54:41 +02:00
parent c8e72dbba8
commit 45ebb2c0d7
5 changed files with 472 additions and 53 deletions

View File

@ -45,7 +45,29 @@ impl CompileContext {
}
}
pub fn write_file(&self, filename: &str, content: String) -> Result<()> {
pub fn to_snake(name: &str) -> String {
let mut result = String::new();
let mut last_upper = false;
for c in name.chars() {
if c.is_uppercase() {
if last_upper {
result.push(c.to_ascii_lowercase());
} else {
if !result.is_empty() {
result.push('_');
}
result.push(c.to_ascii_lowercase());
}
last_upper = true;
} else {
result.push(c);
last_upper = false;
}
}
result
}
pub fn write_file(&self, filename: &str, content: &str) -> Result<()> {
let res_path = self.output_folder.clone().join(filename);
let res_dir = res_path.parent().context("Path has no parent!")?;
std::fs::create_dir_all(res_dir)?;