Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

This patch turns the } boolean into a goog.define and also checks } at runtime (instead of only at compile-time).

The closure define option allows the closure compiler to eliminate asserts in :advanced, while :none builds can keep the asserts. This is one of the few remaining issues that prevent :advanced builds to re-use :none compiled (cached) files.

:elide-asserts is unaffected to keep this as simple as possible, but could be built on top of the goog.define instead of actually affecting the compiled output.

3 Answers

0 votes

Comment made by: mfikes

Patch no longer applies, probably owing to CLJS-970.

0 votes

Comment made by: thheller

There was one more issue I discovered with my approach. My goal was to enable the Closure Compiler to eliminate the asserts when using :advanced compilation. This works perfectly fine with using a {{goog.define}} for * } but the compiler will complain if you try to adjust the define later since {{goog.define}} vars are not allowed to be adjusted at runtime.

(binding [*assert* false] (something-that-asserts))

This works in CLJ but not in CLJS since * } is only checked at compile time. If compiled with {{:elide-asserts true}} you can't bind assert to true either since the code no longer exists.

So some compromise must be made either way, the best solution IMHO would be to have a goog.define which lets the compiler decide whether to eliminate the asserts or not, independent from the * } and then moving the assert check itself into js instead of the compiler.

Happy to write the patch if interested.

0 votes
Reference: https://clojure.atlassian.net/browse/CLJS-1494 (reported by thheller)
Welcome to Clojure Q&A, where you can ask questions and receive answers from members of the Clojure community.