Skip to content

Commit b0ec424

Browse files
committed
track function scopes, prep work for CLJS-937
1 parent 195b254 commit b0ec424

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/clj/cljs/analyzer.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@
849849
(get-in env [:js-globals name]))}}
850850
(when-let [tag (-> name meta :tag)]
851851
{:ret-tag tag})))
852+
env (update-in env [:fn-scope] (fnil conj []) name-var)
852853
locals (if (and locals name) (assoc locals name name-var) locals)
853854
type (-> form meta ::type)
854855
protocol-impl (-> form meta ::protocol-impl)
@@ -884,7 +885,8 @@
884885
(warning :variadic-max-arity env {:name name-var}))
885886
(when (not= (distinct param-counts) param-counts)
886887
(warning :overload-arity env {:name name-var})))
887-
{:env env :op :fn :form form :name name-var :methods methods :variadic variadic
888+
{:env env
889+
:op :fn :form form :name name-var :methods methods :variadic variadic
888890
:tag 'function
889891
:recur-frames *recur-frames* :loop-lets *loop-lets*
890892
:jsdoc [(when variadic "@param {...*} var_args")]

test/clj/cljs/analyzer_tests.clj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,20 @@
324324
;; actual: (not (= #{file-reloading dev client} #{file-reloading dev client core}))
325325
(is (= (set (a/ns-dependents 'utils))
326326
#{'file-reloading 'dev 'client 'core}))))
327+
328+
;; =============================================================================
329+
;; Namespace metadata
330+
331+
(deftest test-fn-scope
332+
(is (= (get-in
333+
(a/analyze ns-env
334+
'(fn foo []
335+
(fn bar [])))
336+
[:children 0 :children 0 :env :fn-scope])
337+
'[{:name foo, :info {:shadow nil}} {:name bar, :info {:shadow nil}}]))
338+
(is (= (get-in
339+
(a/analyze ns-env
340+
'(defn foo []
341+
(fn bar [])))
342+
[:init :children 0 :children 0 :env :fn-scope])
343+
'[{:name foo, :info {:shadow nil}} {:name bar, :info {:shadow nil}}])))

0 commit comments

Comments
 (0)