Skip to content

Commit

Permalink
update set!
Browse files Browse the repository at this point in the history
  • Loading branch information
y2k committed Feb 25, 2024
1 parent 14c2639 commit 1892cc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion clj2js/lib/clj2js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let rec compile_ (context : context) (node : cljexp) : context * string =
| RBList [ Atom (_, "type"); arg ] ->
Printf.sprintf "typeof %s" (compile arg) |> withContext
| RBList [ Atom (_, "set!"); target; value ] ->
Printf.sprintf "(%s = %s)" (compile target) (compile value) |> withContext
Printf.sprintf "(%s = %s);" (compile target) (compile value) |> withContext
| RBList [ Atom (_, field); target ]
when String.starts_with ~prefix:".-" field ->
Printf.sprintf "%s.%s" (compile target)
Expand Down
10 changes: 5 additions & 5 deletions clj2js/test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ bar(2)|};
assert_ "(do (foo 1 2) (bar 3 4) (baz 5 6))"
"(function () { foo(1, 2); bar(3, 4); return baz(5, 6) })()";
assert_ "(str a (if b c d))" {|("" + a + (b ? c : d))|};
assert_ "(set! foo 1)" "(foo = 1)";
assert_ "(set! foo.bar 1)" "(foo.bar = 1)";
assert_ "(set! (.-bar foo) 1)" "(foo.bar = 1)";
assert_ "(set! (.-bar (foo 2)) 1)" "(foo(2).bar = 1)";
assert_ "(set! (.-bar (get xs 2)) 1)" "(xs[2].bar = 1)";
assert_ "(set! foo 1)" "(foo = 1);";
assert_ "(set! foo.bar 1)" "(foo.bar = 1);";
assert_ "(set! (.-bar foo) 1)" "(foo.bar = 1);";
assert_ "(set! (.-bar (foo 2)) 1)" "(foo(2).bar = 1);";
assert_ "(set! (.-bar (get xs 2)) 1)" "(xs[2].bar = 1);";
assert_ "(defmacro foo [a b] (list a 1)) (foo c d)" "c(1)";
assert_ "(defmacro foo [a b] (list a 1) (list b 2)) (foo c d)" "c(1);\nd(2)";
assert_ "(type a)" "typeof a";
Expand Down

0 comments on commit 1892cc1

Please sign in to comment.