Yes! It's actually quite easy to do this using standard clojure macro tools, plus a little bit of cljs.analyzer
magic:
For example, here's a macro that explicitly adds metadata to a clojurescript expression (as long as it supports metadata):
(defmacro add-meta [expr]
(let [namespace {:namespace (name cljs.analyzer/*cljs-ns*)}
source-details (meta &form)]
`(with-meta ~expr '~(merge namespace source-details))))
In your clojurescript file, you can use this to extract metadata from a form (as long as it supports metadata), e.g.
(meta (add-meta {:foo 'bar})) => {:namespace my.namespace :line 1 :column 4}
This macro relies on two sources of information:
cljs.analyzer/*cljs-ns*
is a dynamically bound var that contains the current namespace during macro-expansion of clojurescript code.&form
is a special variable available in the body of a macro that gives access to the form that caused the macro to be invoked. This is the best way to get access to metadata about call-site of the macro.