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 1022
1022
1023
1023
(defn- var-ast
1024
1024
[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 ))
1026
1029
expr-env (assoc env :context :expr )]
1027
1030
(if-let [var-ns (:ns var)]
1028
1031
{:var (analyze expr-env sym)
1384
1387
1385
1388
(defmethod parse 'fn*
1386
1389
[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)])
1390
1394
; ; turn (fn [] ...) into (fn ([]...))
1391
1395
meths (if (vector? (first meths))
1392
1396
(list meths)
1397
1401
(update-in env [:fn-scope ] conj name-var)
1398
1402
env)
1399
1403
locals (if (and (not (nil? locals))
1400
- ( not ( nil? name)) )
1404
+ named-fn? )
1401
1405
(assoc locals name name-var)
1402
1406
locals)
1403
1407
form-meta (meta form)
1413
1417
methods (map #(disallowing-ns* (analyze-fn-method menv locals % type)) meths)
1414
1418
mfa (apply max (map :max-fixed-arity methods))
1415
1419
variadic (boolean (some :variadic methods))
1416
- locals (if-not ( nil? name)
1420
+ locals (if named-fn?
1417
1421
(update-in locals [name] assoc
1418
1422
; ; TODO: can we simplify? - David
1419
1423
:fn-var true
Original file line number Diff line number Diff line change 609
609
(when (or init (:def-emits-var env))
610
610
(let [mname (munge name)]
611
611
(emit-comment env doc (concat jsdoc (:jsdoc init)))
612
- (when (:def-emits-var env)
613
- (when (= :return (:context env))
612
+ (when (= :return (:context env))
614
613
(emitln " return (" ))
614
+ (when (:def-emits-var env)
615
615
(emitln " (function (){" ))
616
616
(emits var)
617
617
(when init
625
625
{:op :var-special
626
626
:env (assoc env :context :expr )}
627
627
var-ast))
628
- (emitln " );})()" )
629
- (when (= :return (:context env))
630
- (emitln " )" )))
628
+ (emitln " );})()" ))
629
+ (when (= :return (:context env))
630
+ (emitln " )" ))
631
631
; ; NOTE: JavaScriptCore does not like this under advanced compilation
632
632
; ; this change was primarily for REPL interactions - David
633
633
; (emits " = (typeof " mname " != 'undefined') ? " mname " : undefined")
Original file line number Diff line number Diff line change 1135
1135
(is (= (nth " 012" 3 :not-found ) :not-found ))
1136
1136
(is (= (nth " 012" -1 :not-found ) :not-found )))
1137
1137
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
+
1138
1152
(comment
1139
1153
; ; ObjMap
1140
1154
; ; (let [ks (map (partial str "foo") (range 500))
Original file line number Diff line number Diff line change 591
591
nsb (str (a/gen-user-ns b))]
592
592
(is (not= (.substring nsa (- (count nsa) 7 )) (.substring nsb (- (count nsb) 7 ))))
593
593
(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