Skip to content

Commit

Permalink
CLJS-3413: Macros not loaded w/ single segment namespace loaded via `…
Browse files Browse the repository at this point in the history
…:preloads` (#229)

* test demonstrating that single segment macro namespaces by themselves are not a problem
* if we cannot find a macro namespace in the current namespace try one more time w/ a global lookup
* add clarifying comment about `:preloads` in `cljs.closure/build`
  • Loading branch information
swannodette authored Jun 7, 2024
1 parent e74d48d commit 47a7bfd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3954,8 +3954,12 @@
: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))
;; single segment namespace case
#?(: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
Expand Down
4 changes: 4 additions & 0 deletions src/main/clojure/cljs/closure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/test/cljs/cljs/macro_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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))))
4 changes: 4 additions & 0 deletions src/test/cljs/single_seg_macros.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(ns single-seg-macros)

(defmacro test-macro [a b]
`(+ ~a ~b))

0 comments on commit 47a7bfd

Please sign in to comment.