Details
-
Type:
Enhancement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Patch:Code
Description
The Closure compiler has "--define" which allows you to set some library values at compile time. The settable values are annotated with "@define": https://code.google.com/closure/compiler/docs/js-for-compiler.html
The particular values I was interested in were goog.dom.ASSUME_{QUIRKS,STANDARDS}_MODE because it would save some code and runtime computation if the rendering mode is known at compile time. (It turns out to be very minor for my tiny test program, but probably more substantial for things that use more of the Closure library.) goog.DEBUG also seems useful to tweak.
The attached patch supports a new compile option :define, along with a map from keys/strings to values. The Closure compiler takes a -define option like: "-define='goog.DEBUG=false'". In ClojureScript, this would be {:define {"goog.DEBUG" false}} or {:define {:goog.DEBUG false}}.
Benefits:
Better support for mobile (Android, iOS, iPad) development in ClojureScript.
Problem:
Please add support for passing "--define" option to compiler.jar.
With this we can optimize code performance where only mobile browsers are our target.
Resources:
goog.userAgent global props: http://closure-library.googlecode.com/svn/docs/closure_goog_useragent_useragent.js.html
goog.userAgent.product global props: http://closure-library.googlecode.com/svn/docs/closure_goog_useragent_product.js.html
"java -jar compiler.jar --help" for all available options
Google Closure Definitive Guide at Google Books: http://books.google.pl/books?id=p7uyWPcVGZsC
clojurescript/src/clj/cljs/closure.clj: functions "make-options" and "set-options"
"TODO: Add any other options that we would like to support."
(defn set-options
"TODO: Add any other options that we would like to support."
[opts ^CompilerOptions compiler-options]
(when (contains? opts :pretty-print)
(set! (.prettyPrint compiler-options) (:pretty-print opts)))
(when (contains? opts :print-input-delimiter)
(set! (.printInputDelimiter compiler-options)
(:print-input-delimiter opts))))
(defn make-options
"Create a CompilerOptions object and set options from opts map."
[opts]
(let [level (case (:optimizations opts)
:advanced CompilationLevel/ADVANCED_OPTIMIZATIONS
:whitespace CompilationLevel/WHITESPACE_ONLY
:simple CompilationLevel/SIMPLE_OPTIMIZATIONS)
compiler-options (doto (CompilerOptions.)
(.setCodingConvention (ClosureCodingConvention.)))]
(do (.setOptionsForCompilationLevel level compiler-options)
(set-options opts compiler-options)
compiler-options)))