lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
624 stars 52 forks source link

add ^js/React.Context hint #109

Closed shaunlebron closed 1 year ago

shaunlebron commented 1 year ago

Fixes #103 and #104

Hi @lilactown, this is the only change needed for the above issues. Thank you! 🙏

aiba commented 1 year ago

💙

lilactown commented 1 year ago

thanks @shaunlebron ! I haven't been following the full conversation in slack; did you find out that this comment is in fact not true, and we can use the ^js syntax inside of a syntax quote when emitting CLJS code?

shaunlebron commented 1 year ago

@lilactown No, ^js in a syntax-quote becomes ^<macro-ns>/js, but this PR uses the explicit type ^js/React.Context to pass symbol resolution.

If you’d like to verify that the typehint generates an extern, here’s a rough trace through the reader, macro evaluation, and cljs analyzer:

^js/React.Context ~context =>

  1. reader translates to => (clojure.core/with-meta context {:tag (clojure.core/quote js/React.Context)})
  2. macro evaluates to => the context macro arg (i.e. symbol or list), attached with metadata {:tag js/React.Context}
  3. analyzes creates a => var/invoke CLJS AST node for the symbol/list, using its :tag metadata as a typehint
  4. analyzer writes => externs when encountering a dot form on an AST node with a js typehint
lilactown commented 1 year ago

ohhhh interesting. Nice!