This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-03
Channels
- # announcements (11)
- # atom-editor (8)
- # aws (16)
- # babashka (34)
- # beginners (59)
- # calva (32)
- # cider (8)
- # clj-kondo (43)
- # cljs-dev (52)
- # clojure (26)
- # clojure-europe (11)
- # clojure-italy (2)
- # clojure-nl (5)
- # clojure-spec (16)
- # clojure-uk (44)
- # clojurescript (5)
- # core-async (21)
- # cursive (14)
- # datomic (53)
- # figwheel-main (4)
- # fulcro (5)
- # graphql (6)
- # java (3)
- # kaocha (5)
- # leiningen (6)
- # local-first-clojure (1)
- # malli (25)
- # off-topic (40)
- # other-languages (1)
- # pathom (5)
- # pedestal (3)
- # re-frame (4)
- # reitit (2)
- # reveal (8)
- # rum (21)
- # sci (16)
- # shadow-cljs (90)
- # spacemacs (8)
- # tools-deps (10)
- # vrac (6)
- # xtdb (12)
Here’s what comes out:
{:name stub-test,
:publics ({:name normal-def, :type :var}
{:name normal-defn, :arglists ([]), :type :var}
{:name hidden-defmacro2, :arglists ([]), :doc "Doc", :type :macro}
{:name gen-clj-stuff, :arglists ([]), :type :macro}
{:name NormalProtocol, :type :protocol, :members ({:name normal-method, :arglists ([this]), :type :var})}
{:name hidden-defmacro5, :arglists ([foo__2589__auto__]), :type :macro}
{:name gen-stuff, :arglists ([]), :type :macro}
{:name hidden-defmacro6, :arglists ([foo__2589__auto__] [foo__2589__auto__ bar__2590__auto__]), :type :macro}
{:name normal-multimethod, :type :multimethod}
{:name hidden-defmacro4, :arglists ([]), :doc "Moar doc", :type :macro}
{:name normal-method, :arglists ([this]), :type :var}
{:name hidden-defmacro3, :arglists ([]), :type :macro}
{:name hidden-defmacro, :arglists ([]), :type :macro}
{:name normal-macro, :arglists ([]), :type :macro})}
ok so let me try to reproduce that with really basic analysis - and leave the other parts for later
The repro contains a bunch of fiddling required to make helix.dom
analyse, related to npm deps.
to be clear this was cljs.analyzer/analyze-file
, let me try the api one - which is the right one to use
Here’s what I’m using:
(let [state (cljs.env/default-compiler-env)
resource (io/resource "stub_test.cljc")]
(comp/with-core-cljs state nil #(ana/analyze-file state resource nil))
(mapv :name (vals (ana/ns-publics state 'stub-test))))
With that, I get:
[stub-test/normal-def
stub-test/normal-defn
stub-test/hidden-defmacro2
stub-test/gen-clj-stuff
stub-test/NormalProtocol
stub-test/hidden-defmacro5
stub-test/gen-stuff
stub-test/hidden-defmacro6
stub-test/normal-multimethod
stub-test/hidden-defmacro4
stub-test/normal-method
stub-test/hidden-defmacro3
stub-test/hidden-defmacro
stub-test/normal-macro]
so the reasoning behind this behavior is that really for self-referencing files, the defs and the macros are the ns-publics of that file
because for end users, you're going to want to know about defs and macros because these can all be :refer
ed
so doing it this way is more like Clojure, and it would let an autodoc tool get everything at once instead of doing something special to get at the macros provided by a library
as to whether or not we should have a public api for just that - I'm a bit skeptical and honestly I don't see the compiler state representation changing - not worth the hassle
Ok, so I think I understand why the macro problem occurs. I still don’t understand why the elements generated by gen-stuff
are not. Is that because analysis doesn’t actually execute top-level forms?
you're using a macro that's only defined in Clojure but you didn't put it behind a reader conditional
This may be my superficial knowledge of CLJS macros showing. My understanding was that macros were defined in CLJ but used in CLJS. Is that not correct?
you cannot just use it because you self-referenced via :require-macros
- you need to refer
How does data readers work on clojurescript? They seem to be executed in java, which means that objects won't be converted to clojurescript. Should they return a code form?
How can I create a reader which works in clojure and cljs? I should have mentioned my actual question :)
Just peeking at what #uuid does, it seems it creates a java.util.UUID, and then defines https://github.com/clojure/clojurescript/blob/b68f0a0de19384f736ab10912001519249737e56/src/main/clojure/cljs/compiler.cljc#L423-L425 Not sure if that's something user-space should do.
I think this is more illustrative of how to write a tag handler for cljs: https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/tagged_literals.cljc#L21