I found there's :closure-configurators compiler option in shadow for injecting custom Closure compiler passes, but it doesn't work when declared in shadow-cljs.edn
would be great if that worked
what would you do with that?
this https://github.com/pitch-io/uix/pull/213/files a custom compiler pass to post process library specific code
In this specific case I'd normally do it via constants table in cljs, but since in shadow it's implemented as closure compiler pass, I had to implement my own as well
you never answered what the point of the constants table is? I just do not get what this is doing?
ah right, so this is for UIx, React wrapper. The idea is to find compile time constant elements in UI components and hoist them to global scope. Basically deduplicating and caching elements across the codebase. Now I'm thinking that it actually might be doable from a macro
ah, I think you want analyze-top 😛
https://ask.clojure.org/index.php/8879/cljs-should-macros-support-lifting-vars-to-the-ns-level
basically the ability of a macro to inject something before the current top level form
yeah something like that, it should be doable already
(defmacro defui [name args & body]
`(do
~inject-here
(defn ~name ~args ~@body)))
and then have a global registry to deduplicate injected stuff, but then how do I clean the registry after every compilation (when running shadow in watch mode)?yeah if its a just a top level def already you do not need any special magic because the def can just do it already
and I think you might be overvaluing the de-duping. I mean how likely is it to get the extact same element multiple times?
the important bit is that the structure stays identical, not a singular node in that structure
no idea, just want to see if it's possible to dedupe at compile time as well
I experimented quite a bit in that area and my results were that deduping was pointless
basically only ended up removing dumb blank :div elements
regardless. I'm open to opening access to :closure-configurators but since it currently requires a secondary option to specify which compile phase to add this in how would this look?
.addCustomPass closure-opts CustomPassExecutionTime/BEFORE_CHECKS that second argument I mean
I guess it could be metadata and the build config just taking a qualified symbol
:closure-configurators [uix.optimize/thing] or so
oh nvm. you do that in the function anyway
so just this :closure-configurators [uix.optimize/thing] would be enough
Yep 👍
technically you can already do this in a build hook
it gets full access to the build and you can do it in :optimize-prepare stage
because thats runs after the setup fn you are currently hacking
so :build-hooks [(uix.optimize/inject)] or so
:shadow.build.closure/compiler-options in the build state holds the closure compiler options object
:shadow.build.closure/compiler the closure compiler instance
Oh right, good point
https://shadow-cljs.github.io/docs/UsersGuide.html#build-hooks