Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
It is my understanding that a namespace has to {{:require-macros}} itself to have its macros accessible automatically but this no longer seems to be accurate.

Given this minimal example

;; src/demo/lib.cljs
(ns demo.lib)

;; src/demo/lib.clj
(ns demo.lib)

(defmacro foo [& args]
  `(prn ::macro))

;; src/demo/test.cljs
(ns demo.test
  (:require [demo.lib :as lib]))

(lib/foo 1 2 3)


I would expect a warning for {{lib/foo}} since {{demo.lib}} has no {{:require-macros}} for its macros and the {{demo.test}} did not use {{:include-macros}} or {{:refer-macros}}.

Compiling this via the build API does in fact produce the expected warning but only iff the {{demo.lib}} CLJ namespace was not required anywhere else.


WARNING: Use of undeclared Var demo.lib/foo at line 5 src/demo/test.cljs



;; build.clj

(require '[cljs.build.api :as cljs])
;; (require 'demo.lib) ;; requiring this here removes the warning

(cljs/build
  "src"
  {:output-dir "out"
   :optimizations :none
   :verbose true})


Enabling the {{(require 'demo.lib)}} in the {{build.clj}} causes the warning to disappear and the code uses the macro properly.

Some popular libraries (eg. devcards) do not self-require but still work if the macro file was at least required somewhere else.

Is this intended behaviour or just accidental?

3 Answers

0 votes
by

Comment made by: dnolen

It's accidental in a sense - the macro resolution is simple to the point of being a bit naive. I'm not sure if we should do anything about it at this point. It would probably cause quite a bit of breakage and little benefit.

0 votes
by

Comment made by: mfikes

See CRRBV-19

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2454 (reported by thheller)
...