Skip to content

Instantly share code, notes, and snippets.

@yanatan16
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanatan16/dffdad4720e01f9a13b8 to your computer and use it in GitHub Desktop.
Save yanatan16/dffdad4720e01f9a13b8 to your computer and use it in GitHub Desktop.
clojurescript compilation under :optimizations :simple

So this is the compilation I'm getting inside my larger project under :optimizations :simple (cljs 1.7.28)

The real problem is this:

Line 7 of the output code sets $_STAR_format_str_STAR_27199$$ = $_STAR_format_str_STAR_27199$$.indexOf("~") for line 12 in the input code of (let [tilde (.indexOf s \~)] ...).

Now, $_STAR_format_str_STAR_27199$$ seems to be standing in for s in the input code. Why is closure renaming tilde into overwriting s?

Later, at the end of line 9 (output) or line 15 (input), (subs s 1) / cljs.core.subs.call(null, $_STAR_format_str_STAR_27199$$, 1) causes an error because we have tilde, s and *format-str* sharing a variable name.

(def ^:dynamic ^{:private true} *format-str* nil)
...
(binding [*format-str* format-str]
(process-nesting
(first
(consume
(fn [[s offset]]
(if (empty? s)
[nil s]
(let [tilde (.indexOf s \~)]
(cond
(neg? tilde) [(compile-raw-string s offset) ["" (+ offset (.-length s))]]
(zero? tilde) (compile-directive (subs s 1) (inc offset))
true
[(compile-raw-string (subs s 0 tilde) offset) [(subs s tilde) (+ tilde offset)]]))))
[format-str 0]))))
return function($format_str$$) {
var $_STAR_format_str_STAR_27199$$ = cljs.core.nth.call(null, $format_str$$, 0, null);
$format_str$$ = cljs.core.nth.call(null, $format_str$$, 1, null);
if (cljs.core.empty_QMARK_.call(null, $_STAR_format_str_STAR_27199$$)) {
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [null, $_STAR_format_str_STAR_27199$$], null);
}
var $_STAR_format_str_STAR_27199$$ = $_STAR_format_str_STAR_27199$$.indexOf("~");
return 0 > $_STAR_format_str_STAR_27199$$ ? new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.pprint.compile_raw_string.call(null, $_STAR_format_str_STAR_27199$$, $format_str$$), new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["", $format_str$$ + $_STAR_format_str_STAR_27199$$.length], null)], null) : 0 === $_STAR_format_str_STAR_27199$$ ? cljs.pprint.compile_directive.call(null, cljs.core.subs.call(null, $_STAR_format_str_STAR_27199$$,
1), $format_str$$ + 1) : new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.pprint.compile_raw_string.call(null, cljs.core.subs.call(null, $_STAR_format_str_STAR_27199$$, 0, $_STAR_format_str_STAR_27199$$), $format_str$$), new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.subs.call(null, $_STAR_format_str_STAR_27199$$, $_STAR_format_str_STAR_27199$$), $_STAR_format_str_STAR_27199$$ + $format_str$$], null)], null);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment