File tree Expand file tree Collapse file tree 4 files changed +39
-11
lines changed
Expand file tree Collapse file tree 4 files changed +39
-11
lines changed Original file line number Diff line number Diff line change 10221022
10231023(defn- var-ast
10241024 [env sym]
1025- (let [var (resolve-var env sym (confirm-var-exists-throw ))
1025+ ; ; we need to dissoc locals for the `(let [x 1] (def x x))` case, because we
1026+ ; ; want the var's AST and `resolve-var` will check locals first. - António Monteiro
1027+ (let [env (dissoc env :locals )
1028+ var (resolve-var env sym (confirm-var-exists-throw ))
10261029 expr-env (assoc env :context :expr )]
10271030 (if-let [var-ns (:ns var)]
10281031 {:var (analyze expr-env sym)
13841387
13851388(defmethod parse 'fn*
13861389 [op env [_ & args :as form] name _]
1387- (let [[name meths] (if (symbol? (first args))
1388- [(first args) (next args)]
1389- [name (seq args)])
1390+ (let [named-fn? (symbol? (first args))
1391+ [name meths] (if named-fn?
1392+ [(first args) (next args)]
1393+ [name (seq args)])
13901394 ; ; turn (fn [] ...) into (fn ([]...))
13911395 meths (if (vector? (first meths))
13921396 (list meths)
13971401 (update-in env [:fn-scope ] conj name-var)
13981402 env)
13991403 locals (if (and (not (nil? locals))
1400- ( not ( nil? name)) )
1404+ named-fn? )
14011405 (assoc locals name name-var)
14021406 locals)
14031407 form-meta (meta form)
14131417 methods (map #(disallowing-ns* (analyze-fn-method menv locals % type)) meths)
14141418 mfa (apply max (map :max-fixed-arity methods))
14151419 variadic (boolean (some :variadic methods))
1416- locals (if-not ( nil? name)
1420+ locals (if named-fn?
14171421 (update-in locals [name] assoc
14181422 ; ; TODO: can we simplify? - David
14191423 :fn-var true
Original file line number Diff line number Diff line change 609609 (when (or init (:def-emits-var env))
610610 (let [mname (munge name)]
611611 (emit-comment env doc (concat jsdoc (:jsdoc init)))
612- (when (:def-emits-var env)
613- (when (= :return (:context env))
612+ (when (= :return (:context env))
614613 (emitln " return (" ))
614+ (when (:def-emits-var env)
615615 (emitln " (function (){" ))
616616 (emits var)
617617 (when init
625625 {:op :var-special
626626 :env (assoc env :context :expr )}
627627 var-ast))
628- (emitln " );})()" )
629- (when (= :return (:context env))
630- (emitln " )" )))
628+ (emitln " );})()" ))
629+ (when (= :return (:context env))
630+ (emitln " )" ))
631631 ; ; NOTE: JavaScriptCore does not like this under advanced compilation
632632 ; ; this change was primarily for REPL interactions - David
633633 ; (emits " = (typeof " mname " != 'undefined') ? " mname " : undefined")
Original file line number Diff line number Diff line change 11351135 (is (= (nth " 012" 3 :not-found ) :not-found ))
11361136 (is (= (nth " 012" -1 :not-found ) :not-found )))
11371137
1138+ (let [foo-1536 2 ]
1139+ (def foo-1536 foo-1536 ))
1140+
1141+ (let [foo-1536-2 1 ]
1142+ (defn foo-1536-2 []
1143+ foo-1536-2 ))
1144+
1145+ (deftest test-cljs-1536
1146+ (is (= foo-1536 2 ))
1147+ (is (= (foo-1536-2 ) 1 ))
1148+ ; ; these two lines generate a `:redef-in-file` warning, which is caused by `cljs.test/is`
1149+ (is (= ((let [z 1 ] (defn z [] z ))) 1 ))
1150+ (is (= (let [w 1 ] ((defn w [] w ))) 1 )))
1151+
11381152(comment
11391153 ; ; ObjMap
11401154 ; ; (let [ks (map (partial str "foo") (range 500))
Original file line number Diff line number Diff line change 591591 nsb (str (a/gen-user-ns b))]
592592 (is (not= (.substring nsa (- (count nsa) 7 )) (.substring nsb (- (count nsb) 7 ))))
593593 (is (= (.substring nsa 0 (- (count nsa) 7 )) (.substring nsb 0 (- (count nsb) 7 )))))))
594+
595+ (deftest test-cljs-1536
596+ (let [parsed (e/with-compiler-env test-cenv
597+ (a/analyze (assoc test-env :def-emits-var true )
598+ '(def x 1 )))]
599+ (is (some? (:var-ast parsed))))
600+ (let [parsed (e/with-compiler-env test-cenv
601+ (a/analyze (assoc test-env :def-emits-var true )
602+ '(let [y 1 ] (def y 2 ))))]
603+ (is (some? (-> parsed :expr :ret :var-ast )))))
You can’t perform that action at this time.
0 commit comments