Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLJS-3413: Macros not loaded w/ single segment namespace loaded via :preloads #229

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Loading