Skip to content

Commit

Permalink
binding ast nodes were missing :children key
Browse files Browse the repository at this point in the history
fix small bug in passes - not passing opts if provided

add compile test cased based on 4clojure example
  • Loading branch information
swannodette authored May 19, 2021
1 parent 15f330f commit 58e39cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/cljs/cljs/analyzer/passes.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
(let [child (get ast child-k)]
(if (vector? child)
(into [] (map #(walk % passes opts)) child)
(walk child passes)))))
(walk child passes opts)))))
(some-> ast (apply-passes passes opts)) (:children ast))))
6 changes: 4 additions & 2 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,8 @@
:init fexpr
:variadic? (:variadic? fexpr)
:max-fixed-arity (:max-fixed-arity fexpr)
:method-params (map :params (:methods fexpr)))]
:method-params (map :params (:methods fexpr))
:children [:init])]
[(assoc-in env [:locals name] be')
(conj bes be')]))
[meth-env []] bes)
Expand Down Expand Up @@ -2296,7 +2297,8 @@
:env {:line line :column col}
:info {:name name
:shadow shadow}
:binding-form? true}
:binding-form? true
:children [:init]}
be (if (= :fn (:op init-expr))
;; TODO: can we simplify - David
(merge be
Expand Down
24 changes: 21 additions & 3 deletions src/test/clojure/cljs/analyzer_pass_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@
(analyze expr-env))
ast' (passes/walk ast [(fn [_ ast _] (dissoc ast :env))])]
(is (not (contains? ast' :env)))
(is (not (some #(contains? % :env) (:args ast')))))))
(is (not (some #(contains? % :env) (:args ast')))))
(let [expr-env (assoc (ana/empty-env) :context :expr)
ast (->> `(let [x# 1
y# (fn [] x#)
z# (fn [] y#)]
'x)
(analyze expr-env))
ast' (passes/walk ast [(fn [_ ast _] (dissoc ast :env))])]
(is (not (contains? ast' :env)))
(is (= 3 (count (:bindings ast'))))
(is (not (some #(contains? % :env) (:bindings ast')))))))

(deftest remove-local
(testing "and/or remove local pass"
Expand Down Expand Up @@ -156,11 +166,19 @@
(for [e s :when (and (sequential? e) (every? (fn [x] x) e))]
e))
[[]])]))))]
(is (empty? (re-seq #"and_" code))))))
(is (empty? (re-seq #"and_" code))))
(let [code (env/with-compiler-env (env/default-compiler-env)
(comp/with-core-cljs {}
(fn []
(compile-form-seq
'[(or false
(boolean
(for [s (range 1)]
(map (fn [x] x) s))))]))))]
(is (empty? (re-seq #"or_" code))))))

(comment
(test/run-tests)

(require '[clojure.pprint :refer [pprint]])

)

0 comments on commit 58e39cb

Please sign in to comment.