This repo demonstrates a bug I found in ClojureScript where macros are not
loaded from preloads whose namespace has only a single part, e.g.
macro-repl-bug.
build.edncontains a basic CLJS build withmacro-repl-bugconfigured in:preloadandapp.mainconfigured as the entry.src/macro_repl_bug.cljccontains two vars: a functionfooand a macrobardefined only in the:cljbranch. The ns:require-macrositself.
To run the project, you'll need both Java and Clojure installed on your system.
- Start a CLJS REPL, e.g.
clj -M -m cljs.main -co build.edn -v -c -r - In the REPL, evaluate
(macro-repl-bug/foo) - Then, evaluate
(macro-repl-bug/bar)
Both foo and bar are executed from the namespace loaded via preloads
cljs.user=> (macro-repl-bug/foo)
:foo
cljs.user=> (macro-repl-bug/bar)
:bar
The macro bar is not found.
cljs.user=> (macro-repl-bug/foo)
WARNING: Use of undeclared Var macro-repl-bug/foo at line 1 <cljs repl>
:foo
cljs.user=> (macro-repl-bug/bar)
WARNING: Use of undeclared Var macro-repl-bug/bar at line 1 <cljs repl>
Execution error (TypeError) at (<cljs repl>:1).
macro_repl_bug.bar is not a function
Namespaces with two or more parts, e.g. macro-repl.works, do work as expected.
cljs.user=> (macro-repl.works/foo)
:foo
cljs.user=> (macro-repl.works/bar)
:bar
Requiring the namespace explicitly from the REPL does allow it to be executed:
cljs.user=> (require '[macro-repl-bug])
nil
cljs.user=> (macro-repl-bug/bar)
:bar
However, in a more complex project with shadow-cljs, this only lasts until the next hot reload of the preloaded namespace. I have not figured out a simple repro for this yet.