Skip to content

Commit 58e39cb

Browse files
authored
binding ast nodes were missing :children key
fix small bug in passes - not passing opts if provided add compile test cased based on 4clojure example
1 parent 15f330f commit 58e39cb

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/main/cljs/cljs/analyzer/passes.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
(let [child (get ast child-k)]
2929
(if (vector? child)
3030
(into [] (map #(walk % passes opts)) child)
31-
(walk child passes)))))
31+
(walk child passes opts)))))
3232
(some-> ast (apply-passes passes opts)) (:children ast))))

src/main/clojure/cljs/analyzer.cljc

+4-2
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,8 @@
22192219
:init fexpr
22202220
:variadic? (:variadic? fexpr)
22212221
:max-fixed-arity (:max-fixed-arity fexpr)
2222-
:method-params (map :params (:methods fexpr)))]
2222+
:method-params (map :params (:methods fexpr))
2223+
:children [:init])]
22232224
[(assoc-in env [:locals name] be')
22242225
(conj bes be')]))
22252226
[meth-env []] bes)
@@ -2296,7 +2297,8 @@
22962297
:env {:line line :column col}
22972298
:info {:name name
22982299
:shadow shadow}
2299-
:binding-form? true}
2300+
:binding-form? true
2301+
:children [:init]}
23002302
be (if (= :fn (:op init-expr))
23012303
;; TODO: can we simplify - David
23022304
(merge be

src/test/clojure/cljs/analyzer_pass_tests.clj

+21-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@
2424
(analyze expr-env))
2525
ast' (passes/walk ast [(fn [_ ast _] (dissoc ast :env))])]
2626
(is (not (contains? ast' :env)))
27-
(is (not (some #(contains? % :env) (:args ast')))))))
27+
(is (not (some #(contains? % :env) (:args ast')))))
28+
(let [expr-env (assoc (ana/empty-env) :context :expr)
29+
ast (->> `(let [x# 1
30+
y# (fn [] x#)
31+
z# (fn [] y#)]
32+
'x)
33+
(analyze expr-env))
34+
ast' (passes/walk ast [(fn [_ ast _] (dissoc ast :env))])]
35+
(is (not (contains? ast' :env)))
36+
(is (= 3 (count (:bindings ast'))))
37+
(is (not (some #(contains? % :env) (:bindings ast')))))))
2838

2939
(deftest remove-local
3040
(testing "and/or remove local pass"
@@ -156,11 +166,19 @@
156166
(for [e s :when (and (sequential? e) (every? (fn [x] x) e))]
157167
e))
158168
[[]])]))))]
159-
(is (empty? (re-seq #"and_" code))))))
169+
(is (empty? (re-seq #"and_" code))))
170+
(let [code (env/with-compiler-env (env/default-compiler-env)
171+
(comp/with-core-cljs {}
172+
(fn []
173+
(compile-form-seq
174+
'[(or false
175+
(boolean
176+
(for [s (range 1)]
177+
(map (fn [x] x) s))))]))))]
178+
(is (empty? (re-seq #"or_" code))))))
160179

161180
(comment
162181
(test/run-tests)
163182

164183
(require '[clojure.pprint :refer [pprint]])
165-
166184
)

0 commit comments

Comments
 (0)