Skip to content

Commit

Permalink
feat: support template string work correct with $ char
Browse files Browse the repository at this point in the history
  • Loading branch information
meloalright committed Feb 6, 2024
1 parent 19dfbaa commit c8eb63e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion rustle/src/compiler/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,33 @@ fn traverse(node: &Fragment, parent: String, analysis: &AnalysisResult, code: &m
parent, event_name, event_handler
));
} else {
let value = match &attr.value {
let mut value = match &attr.value {
Expr::Ident(ident) => ident.sym.to_string(),
Expr::Lit(Lit::Str(str)) => format!("\"{}\"", str.value),
expr => expr_to_string(expr),
_ => {
todo!()
},
};
{
// replace `{xx} xx` => `${xx} xx`
let mut index = 0usize;
while index < value.len() {
if value.chars().nth(index).unwrap() == '{' {
let mut next_pointer = index + 1;
while next_pointer < value.len() {
if value.chars().nth(next_pointer).unwrap() == '}' {
// match
value.insert(index, '$');
next_pointer += 1;
index += 1;
}
next_pointer += 1;
}
}
index += 1;
}
}
code.create.push(format!(
"{}.{} = {};",
parent, attr.name, value
Expand Down

0 comments on commit c8eb63e

Please sign in to comment.