This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-10
Channels
- # announcements (2)
- # aws (11)
- # babashka (11)
- # beginners (22)
- # calva (28)
- # cider (1)
- # clj-kondo (3)
- # clojars (14)
- # clojure (41)
- # clojure-europe (45)
- # clojure-norway (1)
- # clojure-uk (2)
- # clojured (31)
- # clojureindia (4)
- # cursive (5)
- # datahike (15)
- # datomic (11)
- # deps-new (11)
- # events (1)
- # holy-lambda (19)
- # introduce-yourself (1)
- # minecraft (17)
- # music (1)
- # nbb (3)
- # off-topic (37)
- # reagent (6)
- # reveal (3)
- # shadow-cljs (46)
- # tools-deps (8)
- # xtdb (22)
Does clojurescript compile modules independent from each other?
I couldn't resolve
qualified symbol inside my macros - it's constantly nil
. (All modules are cljc). Unqualified symbols are resolve properly.
Although namespace of that symbol is mentioned in require section of namespace from which I call macros.
Short snippet for context
(ns cxa.core
(:require [cx.backend.web :as cx]
[cxa.todomvc]
[cxa.counters]))
(defonce root (atom nil))
(cx/def<> app #{example}
[:div
[:div
[cx/for [[key title] [[:counters "counters"]
[:todomvc "todomvc"]]]
[:label
[:input {:name "example"
:type "radio"
:value key
:on/change #(cx/!! (fn [{:keys [key]}]
{:example key}))}]
title]]]
[cx/case example
:counters [cxa.counters/app]
:todomvc [cxa.todomvc/app]
"nothing selected"]])
(defn rebind [old]
(when old (doto old (cx/detach) (cx/dispose)))
(doto (cx/create app)
(cx/attach (.-body js/document) nil)))
(defn main []
(swap! root rebind))
I couldn't resolve particularly cxa.counters/app
and cxa.todomvc/app
inside cx/def<>
macro. Everything works correct only if move all stuff to single namespace.By resolve
i mean literally (clojure.core/resolve sym)
call.
My macro is a compiler of hiccup-like trees doing same stuff as svelte.
I keep a bit of compile-time information about generated components for some checks to ensure they correctly used.
I know that clojure and cljs namespaces are completely isolated, so keep compile-time info in clojure namespace with same names and vars with same symbols as in cljs.
Seems like a tree-shaking eliminates my namespaces for some reason and I even can't stable reproduce it.
Issue with unresolvable symbols arises randomly between restarts of cljs watch
.
Successful build after restart, have added empty lines (!) in one of namespaces, and it blow up. And it could vise versa.
shadow-cljs - config: /mnt/dataf/projects/stuff/shadow-cljs.edn
shadow-cljs - HTTP server available at
shadow-cljs - server version: 2.16.7 running at
shadow-cljs - nREPL server started on port 42155
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build completed. (142 files, 0 compiled, 0 warnings, 2.12s)
[:app] Compiling ...
[:app] Build failure:
------ ERROR -------------------------------------------------------------------
File: /mnt/dataf/projects/stuff/src/cxa/core.cljc:9:1
--------------------------------------------------------------------------------
6 |
7 | (defonce root (atom nil))
8 |
9 | (cx/def<> app #{example}
-------^------------------------------------------------------------------------
An error occurred while generating code for the form.
ExceptionInfo: failed compiling constant: cx.trees.specials.core$reify__28843@19b2a12b; cx.trees.specials.core$reify__28843 is not a valid ClojureScript constant.
cljs.compiler/fn--3374 (compiler.cljc:306)
cljs.compiler/fn--3374 (compiler.cljc:303)
........
cljs.compiler/emit-let/fn--3750 (compiler.cljc:1099)
cljs.compiler/emit-let (compiler.cljc:1085)
cljs.compiler/emit-let (compiler.cljc:1081)
cljs.compiler/fn--3761 (compiler.cljc:1106)
cljs.compiler/fn--3761 (compiler.cljc:1105)
clojure.lang.MultiFn.invoke (MultiFn.java:229)
cljs.compiler/emit (compiler.cljc:204)
cljs.compiler/emit (compiler.cljc:184)
--------------------------------------------------------------------------------
10 | [:div
11 | [:div
12 | [cx/for [[key title] [[:bmi "BMI calc"]
13 | [:counters "counters"]
--------------------------------------------------------------------------------
I keep a comp-time info in atom and have changed def to defonce and a problem have gone :thinking_face: It's strange because this namespace clj-only (not cljc) and I have not expect it would suddenly reload (with erase of previously accumulated info in the atom) without obvious reason like changed code inside of it. In the same time cljs watch doesn't look into required namespaces that haven't change and there is no chances to re-accumulate info again.
means that you can't use the result of a CLJ (reify ..)
call and expect that to produce JS
> I keep a comp-time info in atom and have changed def to defonce and a problem have gon
if you want to you must disable all caching, as otherwise compilation results may be cached
> don't do this
But this works somehow :thinking_face:
Is this wrong assumption that defonce atom inside clojure namespace (not cljs namespace) will be preserved during cljs compilation (and cljs watch
lifetime)?
> cljs.analyzer/resolve-var
I use this one too for translate cljs symbols into qualified ones and using them resurrect a comp-time info generated by my macro.
as I said. you must disable caching if you do this. the cache will not restore whatever is in your atom
quickly looked at documentation and it's surprising but this caching issue mentioned there and even with library example - clara-rules. thank you
what are you storing in the atom? maybe you don't actually need the atom and can just look stuff up in the analyzer data?
a set of slots (https://svelte.dev/tutorial/slots) which component accepts for every previously compiled component. so it's a mapping {ns/sym -> #{slots}}
and then get it from the compiler env in [:cljs.analyzer/namespaces that.ns :defs name-of-something :meta]
is there a way to override a configuration item in shadow-cljs.edn
(e.g., nrepl: false
) with a command line argument to shadow.cljs.devtools.cli
?
@abdusalam no, not currently. there is --config-merge
for overriding build config stuff but not global options like nrepl