lambdaisland / ornament

Clojure Styled Components
Mozilla Public License 2.0
121 stars 13 forks source link

Error while macroexpanding cljs/cljc #2

Closed oxalorg closed 2 years ago

oxalorg commented 3 years ago

Some times during building cljs/c code, the cljs compiler isn't able to expand defstyled properly.

I've noticed this behaviour to be a bit random, and mostly goes away when a JS runtime gets connected.

------ ERROR -------------------------------------------------------------------
 File: /home/runner/work/does/does/does-library/src/co/gaiwan/does_library/views/common.cljc:36:1
--------------------------------------------------------------------------------
  33 |    [:iframe {:src "https://members.itrevolution.com/elements/login-button"
  34 |              :scrolling "no"}]))
  35 | 
  36 | (defstyled header :header
-------^------------------------------------------------------------------------
Encountered error when macroexpanding lambdaisland.ornament/defstyled.
Error in phase :compile-syntax-check
RuntimeException: Unable to resolve symbol: header-iframe-login in this context
    clojure.lang.Util.runtimeException (Util.java:221)
    clojure.lang.Compiler.resolveIn (Compiler.java:7418)
    clojure.lang.Compiler.resolve (Compiler.java:7362)
    clojure.lang.Compiler.analyzeSymbol (Compiler.java:7323)
    clojure.lang.Compiler.analyze (Compiler.java:6772)
    clojure.lang.Compiler.analyze (Compiler.java:6749)
    clojure.lang.Compiler$VectorExpr.parse (Compiler.java:3264)
    clojure.lang.Compiler.analyze (Compiler.java:6795)
    clojure.lang.Compiler.analyze (Compiler.java:6749)
    clojure.lang.Compiler$VectorExpr.parse (Compiler.java:3264)
    clojure.lang.Compiler.analyze (Compiler.java:6795)
    clojure.lang.Compiler.analyze (Compiler.java:6749)
    clojure.lang.Compiler$VectorExpr.parse (Compiler.java:3264)
    clojure.lang.Compiler.analyze (Compiler.java:6795)
    clojure.lang.Compiler.analyze (Compiler.java:6749)
    clojure.lang.Compiler$VectorExpr.parse (Compiler.java:3264)
    clojure.lang.Compiler.analyze (Compiler.java:6795)
    clojure.lang.Compiler.analyze (Compiler.java:6749)
    clojure.lang.Compiler$BodyExpr$Parser.parse (Compiler.java:6124)
    clojure.lang.Compiler$FnMethod.parse (Compiler.java:5471)
    clojure.lang.Compiler$FnExpr.parse (Compiler.java:4033)
    clojure.lang.Compiler.analyzeSeq (Compiler.java:7109)
    clojure.lang.Compiler.analyze (Compiler.java:6793)
    clojure.lang.Compiler.analyzeSeq (Compiler.java:7099)
    clojure.lang.Compiler.analyze (Compiler.java:6793)
    clojure.lang.Compiler.analyze (Compiler.java:6749)
    clojure.lang.Compiler$InvokeExpr.parse (Compiler.java:3892)
    clojure.lang.Compiler.analyzeSeq (Compiler.java:7113)
    clojure.lang.Compiler.analyze (Compiler.java:6793)
    clojure.lang.Compiler.analyze (Compiler.java:6749)
    clojure.lang.Compiler$BodyExpr$Parser.parse (Compiler.java:6124)
    clojure.lang.Compiler$FnMethod.parse (Compiler.java:5471)
    clojure.lang.Compiler$FnExpr.parse (Compiler.java:4033)
    clojure.lang.Compiler.analyzeSeq (Compiler.java:7109)
    clojure.lang.Compiler.analyze (Compiler.java:6793)
    clojure.lang.Compiler.eval (Compiler.java:7178)
    clojure.lang.Compiler.eval (Compiler.java:7136)
    clojure.core/eval (core.clj:3202)
    clojure.core/eval (core.clj:3198)
    lambdaisland.ornament/defstyled/fn--28961 (ornament.cljc:473)
    clojure.lang.Atom.swap (Atom.java:37)
    clojure.core/swap! (core.clj:2356)
    clojure.core/swap! (core.clj:2349)
    lambdaisland.ornament/defstyled (ornament.cljc:458)
    lambdaisland.ornament/defstyled (ornament.cljc:439)
    clojure.core/apply (core.clj:671)
    clojure.core/apply (core.clj:662)
    cljs.analyzer/macroexpand-1*/fn--2705 (analyzer.cljc:3888)
    cljs.analyzer/macroexpand-1* (analyzer.cljc:3886)
    cljs.analyzer/macroexpand-1* (analyzer.cljc:3873)
    cljs.analyzer/macroexpand-1 (analyzer.cljc:3937)
    cljs.analyzer/macroexpand-1 (analyzer.cljc:3933)
    cljs.analyzer/analyze-seq (analyzer.cljc:3970)
    cljs.analyzer/analyze-seq (analyzer.cljc:3950)
    cljs.analyzer/analyze-form (analyzer.cljc:4159)
    cljs.analyzer/analyze-form (analyzer.cljc:4156)
    cljs.analyzer/analyze* (analyzer.cljc:4212)
    cljs.analyzer/analyze* (analyzer.cljc:4204)
    shadow.build.compiler/analyze/fn--14631 (compiler.clj:264)
    shadow.build.compiler/analyze (compiler.clj:252)
    shadow.build.compiler/analyze (compiler.clj:211)
    shadow.build.compiler/analyze (compiler.clj:213)
    shadow.build.compiler/analyze (compiler.clj:211)
    shadow.build.compiler/default-analyze-cljs (compiler.clj:389)
    shadow.build.compiler/default-analyze-cljs (compiler.clj:378)
    clojure.core/partial/fn--5857 (core.clj:2629)
    shadow.build.compiler/do-analyze-cljs-string (compiler.clj:320)
    shadow.build.compiler/do-analyze-cljs-string (compiler.clj:278)
    shadow.build.compiler/analyze-cljs-string/fn--14711 (compiler.clj:490)
    shadow.build.compiler/analyze-cljs-string (compiler.clj:489)
    shadow.build.compiler/analyze-cljs-string (compiler.clj:487)
    shadow.build.compiler/do-compile-cljs-resource/fn--14739 (compiler.clj:604)
    shadow.build.compiler/do-compile-cljs-resource (compiler.clj:586)
    shadow.build.compiler/do-compile-cljs-resource (compiler.clj:544)
    shadow.build.compiler/maybe-compile-cljs/fn--14842 (compiler.clj:935)
    shadow.build.compiler/maybe-compile-cljs (compiler.clj:934)
    shadow.build.compiler/maybe-compile-cljs (compiler.clj:910)
    shadow.build.compiler/par-compile-one (compiler.clj:1043)
    shadow.build.compiler/par-compile-one (compiler.clj:998)
    shadow.build.compiler/par-compile-cljs-sources/fn--14878/iter--14900--14904/fn--14905/fn--14906/fn--14907 (compiler.clj:1116)

--------------------------------------------------------------------------------
  37 |   :bg-black
  38 |   [:>nav :max-w-7xl :mx-auto :px-4 :sm:px-6 :lg:px-8
  39 |    [:>.small
  40 |     :py-4 :flex :flex-wrap :lg:hidden
--------------------------------------------------------------------------------

I still need to reproduce this (and I don't think I've faced this on the latest commit as of now). Opening this issue to track updates on this.

Some comments from Arne:

this is a particular thing to look out for, because the macro emits both clojure and clojurescript code. This means that in the style rules section you can't reference clojurescript vars because that section is only handled on the backend. We have some logic in there to allow referencing other defstyleds, but that's it. The function body otoh should be able to reference clojurescript vars, including once emitted by previous defstyled macros

I would expect this to just work, but clojurescript macroexpansion is messy and happens in multiple places/passes so it's possible that it doesn't work in some or all cases.

plexus commented 3 years ago

That stack trace is not from the latest version.

oxalorg commented 2 years ago

Closing this as I think this was fixed somehow. If I ever come across it again I'll reopen.