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

macroexpand-1 doesn't work on clojurescript #2099

Open
jiacai2050 opened this Issue Oct 18, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@jiacai2050

jiacai2050 commented Oct 18, 2017

Steps to reproduce the problem

(defproject om-tutorial "0.1.0-SNAPSHOT"
  :description "My first Om program!"
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.8.51"]
                 [org.omcljs/om "1.0.0-beta1"]
                 [com.cemerick/piggieback "0.2.1"]
                 [figwheel-sidecar "0.5.14"]]
  :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
  :clean-targets ^{:protect false} [:target-path "out" "resources/public/js"]
  :plugins [[lein-figwheel "0.5.14"]
            [lein-cljsbuild "1.1.7"]]
  :cljsbuild {:builds [{:id "dev"
                        :figwheel true
                        :source-paths ["src"]
                        :compiler {:main om-tutorial.core
                                   :asset-path "js"
                                   :output-to "resources/public/js/main.js"
                                   :output-dir "resources/public/js"
                                   :verbose true}}] })

With project.clj above, I was able to launch a figwheel repl.
In core.cljs, I have an om component defined like below

(defui HelloWorld
  Object
  (render [this]
          (dom/div nil (get (om/props this) :title))))

When I expand this macro using C-c RET, it didn't expand at all, in *cider-macroexpansion* buffer I got the same thing back, however, if I expand this manually, macroexpand did work.

(macroexpand-1 '(defui HelloWorld
                 Object
                 (render [this]
                         (dom/div nil (get (om/props this) :title)))))
;; this works as expected.

Is there anything I was missing?
Thanks in advance.

Environment & Version information

CIDER version information

;; CIDER 0.15.1 (London)
;; Clojure 1.8.0, java version "1.8.0_144"

Lein/Boot version

Leiningen 2.7.1 on Java 1.8.0_144 Java HotSpot(TM) 64-Bit Server VM

Emacs version

GNU Emacs 25.3.1 (x86_64-apple-darwin16.7.0) of 2017-09-12

Operating system

macOS Sierra 10.12.6

@bbatsov

This comment has been minimized.

Show comment
Hide comment
@bbatsov

bbatsov Dec 31, 2017

Member

See what are the messages exchanged between CIDER and nREPL as described here http://cider.readthedocs.io/en/latest/troubleshooting/

I see we've got an cljs implementation for the macroexpansion, so in theory everything should be working fine.

Member

bbatsov commented Dec 31, 2017

See what are the messages exchanged between CIDER and nREPL as described here http://cider.readthedocs.io/en/latest/troubleshooting/

I see we've got an cljs implementation for the macroexpansion, so in theory everything should be working fine.

@xiongtx

This comment has been minimized.

Show comment
Hide comment
@xiongtx

xiongtx Feb 6, 2018

Member

Through experimentation I've confirmed that the problem goes all the way down to (cljs.analyzer/macroexpand-1 (cljs/grab-cljs-env msg) (reader/read-string code)) not properly macroexpanding the form.

I suspect this has to do with cljs.analyzer/macroexpand-1 behaving differently in a CLJ vs. CLJS context. See Slack discussion.

For posterity (older Slack messages eventually become unavailable):

Evaluating cljs.core/macroexpand-1 for a :clj: / :cljs: project in a :clj: buffer differs from the result in a :cljs: buffer.

E.g. given a file:

(ns om-tutorial.core
  (:require [om.dom :as dom]
            [om.next :as om :refer-macros [defui]]))

(defui HelloWorld
  Object
  (render [this]
          (dom/div nil (get (om/props this) :title))))

Callling cljs.core/macroexpand-1 '(defui ...) in a :clj: buffer does nothing, while calling it from a :cljs: buffer gives:

(do
 (do
  (clojure.core/defn
   HelloWorld
   []
   (cljs.core/this-as
    this__41180__auto__
    (.apply js/React.Component this__41180__auto__ (cljs.core/js-arguments))
...

as expected.

Why is this?

Member

xiongtx commented Feb 6, 2018

Through experimentation I've confirmed that the problem goes all the way down to (cljs.analyzer/macroexpand-1 (cljs/grab-cljs-env msg) (reader/read-string code)) not properly macroexpanding the form.

I suspect this has to do with cljs.analyzer/macroexpand-1 behaving differently in a CLJ vs. CLJS context. See Slack discussion.

For posterity (older Slack messages eventually become unavailable):

Evaluating cljs.core/macroexpand-1 for a :clj: / :cljs: project in a :clj: buffer differs from the result in a :cljs: buffer.

E.g. given a file:

(ns om-tutorial.core
  (:require [om.dom :as dom]
            [om.next :as om :refer-macros [defui]]))

(defui HelloWorld
  Object
  (render [this]
          (dom/div nil (get (om/props this) :title))))

Callling cljs.core/macroexpand-1 '(defui ...) in a :clj: buffer does nothing, while calling it from a :cljs: buffer gives:

(do
 (do
  (clojure.core/defn
   HelloWorld
   []
   (cljs.core/this-as
    this__41180__auto__
    (.apply js/React.Component this__41180__auto__ (cljs.core/js-arguments))
...

as expected.

Why is this?

@xiongtx

This comment has been minimized.

Show comment
Hide comment
@xiongtx

xiongtx Feb 6, 2018

Member

Well, passing (cljs/grab-cljs-env msg) to cljs.analyzer/macroexpand-1 is definitely not the right thing to do. The env needed by cljs.analyzer/macroexpand-1 is not the compiler env.

Member

xiongtx commented Feb 6, 2018

Well, passing (cljs/grab-cljs-env msg) to cljs.analyzer/macroexpand-1 is definitely not the right thing to do. The env needed by cljs.analyzer/macroexpand-1 is not the compiler env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment