Fork me on GitHub
#cljs-dev
<
2020-09-03
>
dnolen00:09:22

but did you not observe that?

cfleming00:09:25

That is what I expected.

cfleming00:09:53

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})}

cfleming00:09:07

normal-macro does appear there.

dnolen00:09:37

ok so let me try to reproduce that with really basic analysis - and leave the other parts for later

dnolen00:09:49

I'm not going to use the specific stuff you have, just standard analyze-file

cfleming00:09:00

Sounds good.

cfleming00:09:34

The repro contains a bunch of fiddling required to make helix.dom analyse, related to npm deps.

dnolen00:09:58

(normal-def normal-defn normal-multimethod NormalProtocol normal-method)

dnolen00:09:59

this is the result of analyze-file of the first 8 lines

dnolen00:09:02

the keys of the :defs for that namespace

dnolen00:09:19

I don't see normal-macro in there

dnolen00:09:33

which would have been very surprising because it's behind a reader conditional

cfleming00:09:43

That’s why I was very surprised 🙂

cfleming00:09:02

Let me try just analyze-file on that.

dnolen00:09:24

to be clear this was cljs.analyzer/analyze-file, let me try the api one - which is the right one to use

dnolen00:09:17

same result for api one

cfleming00:09:45

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))))

cfleming00:09:00

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]

cfleming00:09:10

Am I using the API wrong?

dnolen00:09:32

ns-publics is probably what's sending you down the wrong path - let me read over that

dnolen00:09:52

yes I would read over ns-publics 🙂

dnolen00:09:24

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

dnolen00:09:27

just like Clojure

dnolen00:09:50

because for end users, you're going to want to know about defs and macros because these can all be :refered

dnolen00:09:24

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

dnolen00:09:20

if you want the true :defs I would say get those yourself and skip ns-publics

dnolen00:09:05

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

cfleming00:09:05

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?

cfleming00:09:26

Yeah, I think that is reasonable (re; the public API).

dnolen00:09:49

ok so we've sorted out the first half of your problem - on to the next half

dnolen00:09:08

so first question

dnolen00:09:23

I do not understand the last line

dnolen00:09:46

you're using a macro that's only defined in Clojure but you didn't put it behind a reader conditional

cfleming00:09:23

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?

dnolen00:09:40

but you didn't refer the macro

dnolen00:09:53

you cannot just use it because you self-referenced via :require-macros - you need to refer

dnolen00:09:16

or use an aliased reference

cfleming00:09:44

Indeed, (stub-test/gen-stuff) works!

cfleming00:09:58

Great, thank you - that was very enlightening 🙂

dnolen00:09:03

no problem

dominicm21:09:31

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?

lilactown21:09:47

yeah they’re similar to macros

dominicm21:09:19

How can I create a reader which works in clojure and cljs? I should have mentioned my actual question :)

dominicm21:09:25

In Clojure, I return the object.

dominicm21:09:50

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.

lilactown23:09:14

takes in the form after the tag, returns another form for the compiler