Skip to content

Commit 98800e5

Browse files
committed
always deep-merge ns-info, then macros can emit ns forms that augments the existing ns
1 parent 465c88e commit 98800e5

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3166,7 +3166,16 @@
31663166
:requires requires
31673167
:renames (merge renames core-renames)
31683168
:imports imports}]
3169-
(swap! env/*compiler* update-in [::namespaces name] merge ns-info)
3169+
(swap! env/*compiler* update-in [::namespaces name]
3170+
(fn [the-ns]
3171+
;; just merge - do not replace - then macros can emit
3172+
;; modifications to the ns
3173+
(reduce-kv
3174+
(fn [the-ns k v]
3175+
(if (map? v)
3176+
(update the-ns k merge v)
3177+
(assoc the-ns k v)))
3178+
the-ns ns-info)))
31703179
(merge {:op :ns
31713180
:env env
31723181
:form form

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,9 +1496,14 @@
14961496
(deftest test-cljs-3276-require-from-macro
14971497
(let [cenv (env/default-compiler-env)]
14981498
(env/with-compiler-env cenv
1499-
(ana/analyze-form-seq
1500-
'[(ns test.foo
1501-
(:require-macros [cljs-3276.macros :refer [macro-that-requires]]))
1502-
(macro-that-requires)]))
1503-
(is (= '{cljs-3276.foo cljs-3276.foo} (get-in @cenv [::ana/namespaces 'test.foo :requires])))
1504-
(is (contains? (get @cenv ::ana/namespaces) 'cljs-3276.foo))))
1499+
(comp/with-core-cljs {}
1500+
(fn []
1501+
(ana/analyze-form-seq
1502+
'[(ns test.foo
1503+
(:require [clojure.set :as set])
1504+
(:require-macros [cljs-3276.macros :refer [macro-that-requires]]))
1505+
(macro-that-requires)]))))
1506+
(is (= '{set clojure.set, clojure.set clojure.set, cljs-3276.foo cljs-3276.foo}
1507+
(get-in @cenv [::ana/namespaces 'test.foo :requires])))
1508+
(is (contains? (get @cenv ::ana/namespaces) 'cljs-3276.foo))
1509+
(is (contains? (get @cenv ::ana/namespaces) 'clojure.set))))

0 commit comments

Comments
 (0)