optimized clojurescript->js file throws exception but debug version does not?

174 views
Skip to first unread message

Andrew

unread,
Oct 4, 2012, 12:40:05 PM10/4/12
to clo...@googlegroups.com
Please see https://github.com/achengs/subpar/issues/1 which links to two demo pages. One page uses the debug (non-optimized non-munged) js version and seems to work fine. The other uses the optimized version and throws an exception. Details are in the github issues page and on the demo pages themselves. I'm wondering why they behave differently. Thanks in advance for any help!

David Nolen

unread,
Oct 4, 2012, 1:01:32 PM10/4/12
to clo...@googlegroups.com
On Thu, Oct 4, 2012 at 12:40 PM, Andrew <ach...@gmail.com> wrote:
Please see https://github.com/achengs/subpar/issues/1 which links to two demo pages. One page uses the debug (non-optimized non-munged) js version and seems to work fine. The other uses the optimized version and throws an exception. Details are in the github issues page and on the demo pages themselves. I'm wondering why they behave differently. Thanks in advance for any help!

There is too much context here. Can you isolate the problem and create a minimal case? If you can it would be extremely helpful if you could create an issue in JIRA w/ this information.

Thanks!

David 

Andrew

unread,
Oct 5, 2012, 2:37:50 AM10/5/12
to clo...@googlegroups.com
Ok, I've made *some* progress in ripping out code unrelated to this issue. So far it seems if I remove any more the issue disappears. See https://github.com/achengs/subparissue1

It's a mystery to me why ...

Andrew

unread,
Oct 5, 2012, 8:16:03 AM10/5/12
to clo...@googlegroups.com
Oh. I'm pretty sure it's because in the broken case I use two blobs of js which were minified at separate times thus allowing for name conflicts. 

David Nolen

unread,
Oct 5, 2012, 8:20:36 AM10/5/12
to clo...@googlegroups.com
On Fri, Oct 5, 2012 at 8:16 AM, Andrew <ach...@gmail.com> wrote:
Oh. I'm pretty sure it's because in the broken case I use two blobs of js which were minified at separate times thus allowing for name conflicts. 

Yes Closure assumes whole program optimization. You can't use two separately advanced compiled pieces of JS code together.

So is this the actual issue?

David 

Andrew

unread,
Oct 5, 2012, 8:38:40 AM10/5/12
to clo...@googlegroups.com
How do I tell Closure to include Codemirror.js and other js files when it optimizes?

My project.clj file has this:


  :cljsbuild {

              :builds {
                       :prod
                       {:source-path "src-cljs"
                        :compiler {:output-to "resources/public/js/subpar.core.js"
                                   :optimizations :advanced
                                   :pretty-print false}}}

David Nolen

unread,
Oct 5, 2012, 8:51:24 AM10/5/12
to clo...@googlegroups.com
On Fri, Oct 5, 2012 at 8:38 AM, Andrew <ach...@gmail.com> wrote:
How do I tell Closure to include Codemirror.js and other js files when it optimizes?

My project.clj file has this:


  :cljsbuild {

              :builds {
                       :prod
                       {:source-path "src-cljs"
                        :compiler {:output-to "resources/public/js/subpar.core.js"
                                   :optimizations :advanced
                                   :pretty-print false}}}

You might find this helpful: http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html

I believe you can use the same options you give to ClojureScript compiler so you should be good.

David

Andrew

unread,
Oct 5, 2012, 2:37:21 PM10/5/12
to clo...@googlegroups.com
After I read the link you provided and another page, I discovered that wrapping my compiled stuff in an anonymous function keeps Google Closure's output symbols from colliding with other existing stuff such as CodeMirror's minified variables.

That link points out that it's best to have the compiler do the wrapping for you with  --output_wrapper. Is there a way to specify this for cljsbuild? lein-cljsbuild issue #117 says cljsbuild is just a wrapper for the ClojureScript compiler and if we want it we should open a ticket for ClojureScript. I looked and did not immediately see a ticket or the wrapper option. So maybe I'll open that ticket?

By the way, I'm not sure compiling CodeMirror and my stuff in one go is the right approach, because I don't know whether CodeMirror is compatible with Google Closure's advanced compilation. (I see that CodeMirror 1's compression page had Google Closure advanced optimization as an option but it disappeared for CodeMirror 2.) I think doing so would require me to hand-edit CodeMirror to add a goog.provide call.

David Nolen

unread,
Oct 5, 2012, 2:38:54 PM10/5/12
to clo...@googlegroups.com
On Fri, Oct 5, 2012 at 2:37 PM, Andrew <ach...@gmail.com> wrote:
After I read the link you provided and another page, I discovered that wrapping my compiled stuff in an anonymous function keeps Google Closure's output symbols from colliding with other existing stuff such as CodeMirror's minified variables.

That link points out that it's best to have the compiler do the wrapping for you with  --output_wrapper. Is there a way to specify this for cljsbuild? lein-cljsbuild issue #117 says cljsbuild is just a wrapper for the ClojureScript compiler and if we want it we should open a ticket for ClojureScript. I looked and did not immediately see a ticket or the wrapper option. So maybe I'll open that ticket?

By the way, I'm not sure compiling CodeMirror and my stuff in one go is the right approach, because I don't know whether CodeMirror is compatible with Google Closure's advanced compilation. (I see that CodeMirror 1's compression page had Google Closure advanced optimization as an option but it disappeared for CodeMirror 2.) I think doing so would require me to hand-edit CodeMirror to add a goog.provide call.

You don't need to do that. That's what the :foreign-libs option is for which is described at the end of blog post.

David 

Andrew

unread,
Oct 6, 2012, 11:14:54 PM10/6/12
to clo...@googlegroups.com
What about the --output_wrapper part? 

My clojurescript js never calls the minified foreign library directly: What I have is [1] some plain non-optimized javascript that calls [2] CodeMirror for the code and position, then calls [3] my clojurescript js to find out how to do the requested paredit thing, and then calls [2] CodeMirror again to do it. 

So [3] never calls [2]

[2] and [3] export stuff so that [1] can call them. 

And my problem is that [2] isn't wrapped in an anonymous function. How do I get cljsbuild to tell Closure to use --output_wrapper? (Also, I guess there's a good reason why it doesn't always wrap its output?) 

David Nolen

unread,
Oct 7, 2012, 6:55:32 PM10/7/12
to clo...@googlegroups.com
On Sat, Oct 6, 2012 at 11:14 PM, Andrew <ach...@gmail.com> wrote:
What about the --output_wrapper part? 

My clojurescript js never calls the minified foreign library directly: What I have is [1] some plain non-optimized javascript that calls [2] CodeMirror for the code and position, then calls [3] my clojurescript js to find out how to do the requested paredit thing, and then calls [2] CodeMirror again to do it. 

So [3] never calls [2]

[2] and [3] export stuff so that [1] can call them. 

And my problem is that [2] isn't wrapped in an anonymous function. How do I get cljsbuild to tell Closure to use --output_wrapper? (Also, I guess there's a good reason why it doesn't always wrap its output?) 

Seems like a simple useful option we should expose. 


David
Reply all
Reply to author
Forward
0 new messages