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

0 votes
in ClojureScript by
The {{cljs.core/exists?}} macro will check each individual "segment" of a given namespace to avoid property-access errors. This however doesn't translate well into {{:advanced}} optimizations where this will cause unnecessary variables to remain that would otherwise be removed. A very common use of this is {{defonce}} which exhibits as the following:


(defonce PROTOCOL_SENTINEL #js {})


Expands to


if((typeof cljs !== 'undefined') && (typeof cljs.core !== 'undefined') && (typeof cljs.core.PROTOCOL_SENTINEL !== 'undefined')){
} else {
cljs.core.PROTOCOL_SENTINEL = ({});
}


After optimizations


// with pseudo-names
var $cljs$$ = {}, $cljs$core$$ = {};
if ("undefined" === typeof $cljs$$ || "undefined" === typeof $cljs$core$$ || "undefined" === typeof $cljs$core$PROTOCOL_SENTINEL$$) {
  var $cljs$core$PROTOCOL_SENTINEL$$ = {};
}

// without pseudo-names
var E={},F={};if("undefined"===typeof E||"undefined"===typeof F||"undefined"===typeof G)var G={};


Note the additional {{var $cljs$$ = {}, $cljs$core$$ = {};}}. Since Closure collapses all namespaces into a flat var structure these will never be used for anything other than the checks done by {{cljs.core/exists?}}.

Might be worth cleaning up some day.

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-3055 (reported by thheller)
...