Closed SevereOverfl0w closed 2 years ago
I haven't put code to this yet but if I'm understanding the issue right:
When we're in the macroexpansion phase of compiling a CLJS file, our tagged values i.e. #js [(use-state 10)]
have already been read and are now an opaque JSValue
type, defined here: https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/tagged_literals.cljc#L68
Thus, we need a way of getting the form that is wrapped in this JSValue in order to continue analyzing.
I can think of two ways of doing this:
JSValue
and access the field (.-val x)
JSValue
to handle the field accessUsing polymorphism for this makes me feel clever, since it would allow outside extension to other reader tags i.e. #hiccup [:div (when true (use-state "hello"))]
.
I am dubious of the times that this will actually be useful, though.
I'm not sure if #hiccup
would apply here, as that's unable to return a special form without extending the ClojureScript compiler. That means #hiccup
has to return a record, list, etc. for the compiler to interpret.
The polymorphic approach was a little annoying because you had to extend it to Object
, nil
, etc.
I think this should be trivial to fix after #86 is merged. Right now, hooks can't be found when they hide inside pesky
#js
tagged literals like so:Both the
find-hooks
andinvalid-hooks-usage
functions in the analyser need updating to know how to descend into a JSValue.