Skip to content

Instantly share code, notes, and snippets.

@vincent-dm
Last active April 11, 2016 19:38
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 vincent-dm/30701e1dbd5d13beb30b8e5e856e6fda to your computer and use it in GitHub Desktop.
Save vincent-dm/30701e1dbd5d13beb30b8e5e856e6fda to your computer and use it in GitHub Desktop.
Closure compiler does not eliminate dead branches based on branching the goog.LOCALE setting. (File paths are converted to underscores in the file names)
(require 'cljs.build.api)
(cljs.build.api/build "src"
{:output-to "out/main.js"
:optimizations :advanced
:pretty-print true
:closure-defines {
'goog.DEBUG false
'goog.LOCALE "nl"}})
(System/exit 0)
// 20471 lines of javascript omitted
var i18n = {fr:{}};
i18n.fr.message = "French";
i18n.nl = {};
i18n.nl.message = "Dutch";
i18n.translate = {};
cljs.core.enable_console_print_BANG_.call(null);
i18n.translate.translation = function() {
var a = cljs.core.identical_QMARK_, b = goog.LOCALE;
return cljs.core.truth_(a.call(null, "nl", b)) ? i18n.nl.message : cljs.core.truth_(a.call(null, "fr", b)) ? i18n.fr.message : "unknown";
}();
cljs.core.println.call(null, "goog.LOCALE ", goog.LOCALE, " leads to translated text: ", i18n.translate.translation);
// I only included line 5364 of the 5406-line output
}(), Ee = x(za.a ? za.a("nl", "nl") : za.call(null, "nl", "nl")) ? "Dutch" : x(za.a ? za.a("fr", "nl") : za.call(null, "fr", "nl")) ? "French" : "unknown", Ge = fc(["goog.LOCALE ", "nl", " leads to translated text: ", Ee], 0), He = kc.g(qa(), ua, !1), Ie, Je;
(ns i18n.fr)
(def message "French")
(ns i18n.nl)
(def message "Dutch")
(ns i18n.translate
(:require [i18n.nl]
[i18n.fr]))
(enable-console-print!)
(def translation (condp identical? js/goog.LOCALE
"nl" i18n.nl/message
"fr" i18n.fr/message
"unknown"))
(println "goog.LOCALE " js/goog.LOCALE " leads to translated text: " translation)
;; both the word "Dutch" from "src/i18n/nl.cljs" and the word
;; "French" from "src/i18n/fr.cljs" are present in the output.
;;
@vincent-dm
Copy link
Author

The output is different when I use a case in the translate.cljs file, but the issue of having all the branches in the output remains:

(def translation (case js/goog.LOCALE
                  "nl" i18n.nl/message
                  "fr" i18n.fr/message
                  "unknown"))
De = ec(["goog.LOCALE ", "nl", " leads to translated text: ", function() {
  switch("nl") {
    case "nl":
      return "Dutch";
    case "fr":
      return "French";
    default:
      return "unknown";
  }
}()]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment