Skip to content

Commit 2931216

Browse files
committed
CLJS-3125: set! emits invalid js when used as expression
1 parent c247649 commit 2931216

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/main/clojure/cljs/compiler.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@
12371237

12381238
(defmethod emit* :set!
12391239
[{:keys [target val env]}]
1240-
(emit-wrap env (emits target " = " val)))
1240+
(emit-wrap env (emits "(" target " = " val ")")))
12411241

12421242
(defn emit-global-export [ns-name global-exports lib]
12431243
(emitln (munge ns-name) "."

src/test/cljs/cljs/specials_test.cljs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
;; Copyright (c) Rich Hickey. All rights reserved.
2+
;; The use and distribution terms for this software are covered by the
3+
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
;; which can be found in the file epl-v10.html at the root of this distribution.
5+
;; By using this software in any fashion, you are agreeing to be bound by
6+
;; the terms of this license.
7+
;; You must not remove this notice, or any other, from this software.
8+
9+
(ns cljs.specials-test
10+
(:require [cljs.test :refer-macros [deftest is]]))
11+
12+
(defprotocol IFoo3125
13+
(-mutate [this]))
14+
15+
(defrecord Foo3125 [^:mutable x]
16+
IFoo3125
17+
(-mutate [this] (* 3 (set! x (inc x)))))
18+
19+
(def ^:dynamic *test-cljs-3125* 4)
20+
21+
(deftest test-cljs-3125
22+
(is (== 12 (let [o #js {}] (* 6 (set! (.-a o) 2)))))
23+
(is (== 12 (let [o #js {}] (* 6 (set! o -a 2)))))
24+
(is (== 15 (* 3 (set! *test-cljs-3125* (inc *test-cljs-3125*)))))
25+
(is (== 18 (-mutate (->Foo3125 5)))))

src/test/cljs/test_runner.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
[cljs.pprint]
3838
[cljs.pprint-test]
3939
[cljs.spec-test]
40+
[cljs.specials-test]
4041
[cljs.spec.test-test]
4142
[cljs.clojure-alias-test]
4243
[cljs.hash-map-test]
@@ -85,6 +86,7 @@
8586
'cljs.import-test
8687
'cljs.pprint
8788
'cljs.spec-test
89+
'cljs.specials-test
8890
'cljs.spec.test-test
8991
'cljs.clojure-alias-test
9092
'cljs.hash-map-test

src/test/self/self_parity/test.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
[cljs.pprint]
304304
[cljs.pprint-test]
305305
[cljs.spec-test]
306+
[cljs.specials-test]
306307
[cljs.spec.test-test]
307308
[cljs.clojure-alias-test]
308309
[cljs.hash-map-test]
@@ -351,6 +352,7 @@
351352
'cljs.pprint
352353
'cljs.pprint-test
353354
'cljs.spec-test
355+
'cljs.specials-test
354356
'cljs.spec.test-test
355357
'cljs.clojure-alias-test
356358
'cljs.hash-map-test

0 commit comments

Comments
 (0)