Skip to content
Browse files

* src/clj/cljs/compiler.clj: CLJS-198: support (set! o -property valu…

…e) form. Simplifies interop with many JS APIs, macros like 'doto' becomes more useful.
  • Loading branch information...
1 parent dbcb9f6 commit 8b37ace4ae7d780515ad1255b64597e50adc7507 David Nolen committed Apr 23, 2012
Showing with 33 additions and 29 deletions.
  1. +33 −29 src/clj/cljs/compiler.clj
View
62 src/clj/cljs/compiler.clj
@@ -991,35 +991,39 @@
{:env env :op :new :ctor ctorexpr :args argexprs :children (conj argexprs ctorexpr)})))
(defmethod parse 'set!
- [_ env [_ target val] _]
- (disallowing-recur
- (let [enve (assoc env :context :expr)
- targetexpr (cond
- (= target '*unchecked-if*)
- (do
- (reset! *unchecked-if* val)
- ::set-unchecked-if)
-
- (symbol? target)
- (do
- (let [local (-> env :locals target)]
- (assert (or (nil? local)
- (and (:field local)
- (:mutable local)))
- "Can't set! local var or non-mutable field"))
- (analyze-symbol enve target))
-
- :else
- (when (seq? target)
- (let [targetexpr (analyze-seq enve target nil)]
- (when (:field targetexpr)
- targetexpr))))
- valexpr (analyze enve val)]
- (assert targetexpr "set! target must be a field or a symbol naming a var")
- (cond
- (= targetexpr ::set-unchecked-if) {:env env :op :no-op}
- :else {:env env :op :set! :target targetexpr
- :val valexpr :children [targetexpr valexpr]}))))
+ [_ env [_ target val alt] _]
+ (let [[target val] (if alt
+ ;; (set! o -prop val)
+ [`(. ~target ~val) alt]
+ [target val])]
+ (disallowing-recur
+ (let [enve (assoc env :context :expr)
+ targetexpr (cond
+ (= target '*unchecked-if*)
+ (do
+ (reset! *unchecked-if* val)
+ ::set-unchecked-if)
+
+ (symbol? target)
+ (do
+ (let [local (-> env :locals target)]
+ (assert (or (nil? local)
+ (and (:field local)
+ (:mutable local)))
+ "Can't set! local var or non-mutable field"))
+ (analyze-symbol enve target))
+
+ :else
+ (when (seq? target)
+ (let [targetexpr (analyze-seq enve target nil)]
+ (when (:field targetexpr)
+ targetexpr))))
+ valexpr (analyze enve val)]
+ (assert targetexpr "set! target must be a field or a symbol naming a var")
+ (cond
+ (= targetexpr ::set-unchecked-if) {:env env :op :no-op}
+ :else {:env env :op :set! :target targetexpr
+ :val valexpr :children [targetexpr valexpr]})))))
(defmethod parse 'ns
[_ env [_ name & args] _]

0 comments on commit 8b37ace

Please sign in to comment.
Something went wrong with that request. Please try again.