Skip to content

Commit

Permalink
feat: transpile while
Browse files Browse the repository at this point in the history
  • Loading branch information
fcoury committed Jul 9, 2024
1 parent ed40908 commit 3526323
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ impl JsTranspiler {
.join("\n");
format!("while (true) {{\n{}\n}}", body_str)
}
Stmt::While(condition, body, _) => {
let condition_str = self.generate_expr(condition);
let body_str = body
.iter()
.map(|s| self.generate_stmt(s))
.collect::<Vec<_>>()
.join("\n");
format!("while ({}) {{\n{}\n}}", condition_str, body_str)
}
Stmt::Continue(_) => "continue;".to_string(),
Stmt::Break(_) => "break;".to_string(),
Stmt::Struct(_name, _fields, _) => {
Expand Down

0 comments on commit 3526323

Please sign in to comment.