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

0 votes
in ClojureScript by

Related discussion:
- https://github.com/clojure-emacs/cider/issues/2099#issuecomment-661940099

(ns user
  (:require [cljs.analyzer :as analyzer]))

(let [ns-env (assoc-in (analyzer/empty-env) [:ns [:name]] 'cljs.user)]
  (analyzer/macroexpand-1 ns-env `(defn ~'foo [~'x] ~'x)))
;; (clojure.core/defn foo [x] x)

(macroexpand-1 `(defn ~'foo [~'x] ~'x))
;; (def foo (clojure.core/fn ([x] x)))

1 Answer

0 votes
selected by
Best answer

You need to have the cljs.env/*compiler* binding bound (eg. via cljs.env/with-compiler-env) and the relevant namespaces already analyzed (eg. cljs.core).

I don't know the exact sequence of things you need to do but in essence you are just missing the compiler env (which is not the same as the env passed into the macroexpand call itself).

Thanks for your reply. I will try dig more about this issue