cljs compiler options :closure-defines {:goog.DEBUG false}

1,142 views
Skip to first unread message

Jamie Orchard-Hays

unread,
May 4, 2015, 6:13:12 PM5/4/15
to clojur...@googlegroups.com
Can't figure out what I'm doing wrong here:

project.clj:

{:compiler
:closure-defines {:goog.DEBUG false}...}

But in my app, it evaluates true.

(println "js/goog.DEBUG: " ^boolean js/goog.DEBUG)
=> true

org.clojure/clojurescript "0.0-3126"
lein-cljsbuild "1.0.5"

David Nolen

unread,
May 4, 2015, 6:16:31 PM5/4/15
to clojur...@googlegroups.com
Should be "goog.DEBUG" not :goog.DEBUG.

David


--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Jamie Orchard-Hays

unread,
May 4, 2015, 6:40:40 PM5/4/15
to clojur...@googlegroups.com
Cheers, David. Doubly confused now. The example at https://github.com/clojure/clojurescript/wiki/Compiler-Options has the colon prefix (:goog.DEBUG). In any case, removing the colon had no effect. 

Jamie

Thomas Heller

unread,
May 4, 2015, 6:47:19 PM5/4/15
to clojur...@googlegroups.com
No idea if this is still current but closure defines only used to work in anything but :optimizations :none. Are you testing in :none?

David Nolen

unread,
May 4, 2015, 6:48:58 PM5/4/15
to clojur...@googlegroups.com
Fixed the wiki. :closure-defines currently only work under a compilation mode, i.e. a higher setting than :none.

David

Jamie Orchard-Hays

unread,
May 4, 2015, 8:55:49 PM5/4/15
to clojur...@googlegroups.com
Aha! Thanks to you both, David and Thomas! :optimizations :none

Jamie

Jamie Orchard-Hays

unread,
May 4, 2015, 9:02:15 PM5/4/15
to clojur...@googlegroups.com
WRT wiki: looking at this commit, it looks like a keyword works:


(name key)


Jamie

Mike Thompson

unread,
May 5, 2015, 3:07:35 AM5/5/15
to clojur...@googlegroups.com
On Tuesday, May 5, 2015 at 11:02:15 AM UTC+10, Jamie Orchard-Hays wrote:
> WRT wiki: looking at this commit, it looks like a keyword works:
>
>
> https://github.com/clojure/clojurescript/commit/cb7e97f13ae6a03086f5d96ba58e5f3d5cba7dc3
>
>
> (name key)
>
>
>
>
> Jamie
>
>
> On May 4, 2015, at 8:55 PM, Jamie Orchard-Hays <jami...@gmail.com> wrote:
>
> Aha! Thanks to you both, David and Thomas! :optimizations :none
>
>
> Jamie
>
>
>
> On May 4, 2015, at 6:48 PM, David Nolen <dnolen...@gmail.com> wrote:
>
> Fixed the wiki. :closure-defines currently only work under a compilation mode, i.e. a higher setting than :none.
>
>
> David
>
>
> On Mon, May 4, 2015 at 6:40 PM, Jamie Orchard-Hays <jami...@gmail.com> wrote:
>
> Cheers, David. Doubly confused now. The example at https://github.com/clojure/clojurescript/wiki/Compiler-Options has the colon prefix (:goog.DEBUG). In any case, removing the colon had no effect. 


Our experiments on goog.DEBUG wrt to :optimizations setting showed the following:

- `:none` - your project.clj setting is always ignored and defaults to `true`.
- `:whitespace` - same as :none…ignored.
- `:simple` - defaults to true. But recognises both {:goog.DEBUG false} and {"goog.DEBUG" false} in project.clj
- `:advanced` - same as :simple


BTW, as far as I understand it, (WARNING UNTESTED) you can do your own overrideable compile-time constants, by having a docstring on a def which conforms to the correct Closure Compile form. See @define in https://developers.google.com/closure/compiler/docs/js-for-compiler


;; in a namespace "example.ns"
;; the docstring is a very specific format
(def my-var "@define {boolean}" true)

Then in the project.clj you can add:

{:compiler
:closure-defines {:example.ns.my-var false}...}


But this will work the same way as goog.DEBUG. Ie. you can only override the default value (true) for :simple and :advanced. For the other two, you'll get true no matter what value you supply in project.clj.

(If David agrees on the correctness of these statements) should these notes be added to some Wiki somewhere?


--
Mike



Jamie Orchard-Hays

unread,
May 5, 2015, 8:57:18 AM5/5/15
to clojur...@googlegroups.com
Thanks for elucidation. In my particular case, I was just trying to test that I was using goog.DEBUG correctly from project.clj but in a dev mode which has :none for optimizations. I missed docs that :closure-defines doesn't work in that mode.

I've updated the wiki page to the effect that :clojure-defines is ignored for :none and :whitespace optimizations.

Jamie

Thomas Heller

unread,
May 5, 2015, 10:47:21 AM5/5/15
to clojur...@googlegroups.com
http://dev.clojure.org/jira/browse/CLJS-1014
makes me think that defines should work in :none, not sure why they don't.

If you want to use Closure defines in :none while developing you can put them into your HTML manually before including the javascript (or use shadow-build).

For standard CLJS just do:

<script>var CLOSURE_DEFINES = {"goog.DEBUG":false};</script>
<script src="/js/goog/base.js"></script>
...

David Nolen

unread,
May 5, 2015, 10:59:53 AM5/5/15
to clojur...@googlegroups.com
It works for ClojureScript originated Closure Defines, not Google Closure originated ones. Happy to take a patch that solves the general case.

David

Martin Klepsch

unread,
Aug 3, 2015, 3:31:30 PM8/3/15
to ClojureScript
Just a heads up for future readers (sorry for the noise to the rest):

In releases after 1.7.28 will be a `cljs.core/define` macro that makes a define using `goog.define`.
Defines done with `goog.define` can be overridden at any compilation level.

Related JIRA ticket: http://dev.clojure.org/jira/browse/CLJS-1389

Reply all
Reply to author
Forward
0 new messages