From 9bf0706e06d3f4f187eed7fc97272c8932590db7 Mon Sep 17 00:00:00 2001 From: davidnolen Date: Tue, 4 Jun 2024 14:20:48 -0400 Subject: [PATCH 1/4] test demonstrating that single segment namespaces by themselves are not a problem --- src/test/cljs/cljs/macro_test.cljs | 8 ++++++-- src/test/cljs/single_seg_macros.clj | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/test/cljs/single_seg_macros.clj diff --git a/src/test/cljs/cljs/macro_test.cljs b/src/test/cljs/cljs/macro_test.cljs index ed433e4f68..6c7354d56c 100644 --- a/src/test/cljs/cljs/macro_test.cljs +++ b/src/test/cljs/cljs/macro_test.cljs @@ -8,9 +8,10 @@ (ns cljs.macro-test (:refer-clojure :exclude [==]) - (:require [cljs.test :refer-macros [deftest is]]) + (:require [cljs.test :as test :refer-macros [deftest is]]) (:use-macros [cljs.macro-test.macros :only [== sm-cljs-3027]]) - (:require-macros [cljs.macro-test.cljs2852])) + (:require-macros [cljs.macro-test.cljs2852] + [single-seg-macros])) (deftest test-macros (is (= (== 1 1) 2))) @@ -31,3 +32,6 @@ (deftest test-cljs-3027 (is (= {"a" "b"} (sm-cljs-3027)))) + +(deftest test-cljs-3413 + (is (= 5 (single-seg-macros/test-macro 2 3)))) diff --git a/src/test/cljs/single_seg_macros.clj b/src/test/cljs/single_seg_macros.clj new file mode 100644 index 0000000000..679f07fd9a --- /dev/null +++ b/src/test/cljs/single_seg_macros.clj @@ -0,0 +1,4 @@ +(ns single-seg-macros) + +(defmacro test-macro [a b] + `(+ ~a ~b)) From f7e87a5bf521823bff0301b2882fbd3f803e47e6 Mon Sep 17 00:00:00 2001 From: davidnolen Date: Tue, 4 Jun 2024 14:56:37 -0400 Subject: [PATCH 2/4] if we cannot find a macro namespace in the current namespace try one more time w/ a global lookup --- src/main/clojure/cljs/analyzer.cljc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/clojure/cljs/analyzer.cljc b/src/main/clojure/cljs/analyzer.cljc index f0f179a497..7a8850193a 100644 --- a/src/main/clojure/cljs/analyzer.cljc +++ b/src/main/clojure/cljs/analyzer.cljc @@ -3954,8 +3954,11 @@ :cljs [(identical? "clojure.repl" nstr) (find-macros-ns 'cljs.repl)]) #?@(:clj [(.contains nstr ".") (find-ns (symbol nstr))] :cljs [(goog.string/contains nstr ".") (find-macros-ns (symbol nstr))]) - :else (some-> env :ns :require-macros (get (symbol nstr)) #?(:clj find-ns - :cljs find-macros-ns))))) + :else + (or (some-> env :ns :require-macros (get (symbol nstr)) #?(:clj find-ns + :cljs find-macros-ns)) + #?(:clj (find-ns (symbol nstr)) + :cljs (find-macros-ns (symbol nstr))))))) (defn get-expander* [sym env] (when-not (or (some? (gets env :locals sym)) ; locals hide macros From 4733dd83d980f80ab251eb51d4767a003cbb4377 Mon Sep 17 00:00:00 2001 From: davidnolen Date: Thu, 6 Jun 2024 15:51:01 -0400 Subject: [PATCH 3/4] add comment --- src/main/clojure/cljs/analyzer.cljc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/clojure/cljs/analyzer.cljc b/src/main/clojure/cljs/analyzer.cljc index 7a8850193a..376956d8e8 100644 --- a/src/main/clojure/cljs/analyzer.cljc +++ b/src/main/clojure/cljs/analyzer.cljc @@ -3957,6 +3957,7 @@ :else (or (some-> env :ns :require-macros (get (symbol nstr)) #?(:clj find-ns :cljs find-macros-ns)) + ;; single segment namespace case #?(:clj (find-ns (symbol nstr)) :cljs (find-macros-ns (symbol nstr))))))) From 72d6330195676228d0f8f8a98b17c2033757858b Mon Sep 17 00:00:00 2001 From: davidnolen Date: Fri, 7 Jun 2024 14:15:13 -0400 Subject: [PATCH 4/4] add clarifying comment about :preloads --- src/main/clojure/cljs/closure.clj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/clojure/cljs/closure.clj b/src/main/clojure/cljs/closure.clj index 8d4b41244f..dffd923fcf 100644 --- a/src/main/clojure/cljs/closure.clj +++ b/src/main/clojure/cljs/closure.clj @@ -3081,6 +3081,10 @@ [(-compile (io/resource "cljs/nodejs.cljs") (assoc opts :output-file "nodejs.js"))])) deps/dependency-order + ;; NOTE: :preloads are compiled *after* + ;; user specified inputs. Thus user code cannot + ;; depend on anything (i.e. fn/macros) defined + ;; in preloads via global access pattern (add-preloads opts) remove-goog-base add-goog-base