ClojureScript

Problems with :optimizations :whitespace & :output-wrapper true

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    OS X 10.8.3, Google Chrome 28

Description

When I have both output wrapper and :whitespace optimizations enabled, I get the following error when loading the produced output:

goog.provide("goog.string");
goog.provide("goog.string.Unicode");
goog.string.Unicode = {NBSP:"\u00a0"};
^- Uncaught TypeError: Cannot set property 'Unicode' of undefined

Any ideas on what is going wrong? The error disappears if I use :simple or :advanced optimizations or if I set :output-wrapper to false (combined with any optimization level).

Activity

Hide
Aku Kotkavuo added a comment -

ClojureScript version used is 0.0-1806.

Show
Aku Kotkavuo added a comment - ClojureScript version used is 0.0-1806.
Hide
Aku Kotkavuo added a comment -

I'm also seeing this:

GET http://localhost:7070/deps.js 404 (Not Found)
goog.writeScriptTag_
goog.importScript_
goog.importScript_(goog.basePath + "deps.js")

I have no idea what deps.js is, something related to Google Closure Compiler?

Show
Aku Kotkavuo added a comment - I'm also seeing this: GET http://localhost:7070/deps.js 404 (Not Found) goog.writeScriptTag_ goog.importScript_ goog.importScript_(goog.basePath + "deps.js") I have no idea what deps.js is, something related to Google Closure Compiler?
Hide
David Nolen added a comment -

Is this problem still present? Thanks.

Show
David Nolen added a comment - Is this problem still present? Thanks.
Hide
Immo Heikkinen added a comment -

The problem is still present in clojurescript master. To reproduce, compile https://github.com/clojure/clojurescript/tree/master/samples/hello using

cljsc src {:output-wrapper true :optimizations :whitespace} > hello.js
Show
Immo Heikkinen added a comment - The problem is still present in clojurescript master. To reproduce, compile https://github.com/clojure/clojurescript/tree/master/samples/hello using
cljsc src {:output-wrapper true :optimizations :whitespace} > hello.js
Hide
Herwig Hochleitner added a comment -

I just saw this with [org.clojure/clojurescript "0.0-2371"]

The last line of the following, throws the error, when compiled with :output-wrapper

goog.provide("goog.string");
goog.provide("goog.string.Unicode");
goog.define("goog.string.DETECT_DOUBLE_ESCAPING", false);
goog.string.Unicode = {NBSP:"\u00a0"};

Notice how if fails right after providing goog.string, so it might be a bug with google closure.

Show
Herwig Hochleitner added a comment - I just saw this with [org.clojure/clojurescript "0.0-2371"] The last line of the following, throws the error, when compiled with :output-wrapper
goog.provide("goog.string");
goog.provide("goog.string.Unicode");
goog.define("goog.string.DETECT_DOUBLE_ESCAPING", false);
goog.string.Unicode = {NBSP:"\u00a0"};
Notice how if fails right after providing goog.string, so it might be a bug with google closure.
Hide
Immo Heikkinen added a comment -

I noticed that if you move

var goog = goog || {};

outside the wrapper function, the problem goes away. Looks like tt's some kind of JavaScript scope issue.

Show
Immo Heikkinen added a comment - I noticed that if you move
var goog = goog || {};
outside the wrapper function, the problem goes away. Looks like tt's some kind of JavaScript scope issue.
Hide
David Nolen added a comment -

I suspect that the whitespace and output wrapper combination is not compatible. I'm inclined to close this one as it's a Closure limitation not a ClojureScript one. I would be open to an error when these two options are combined.

Show
David Nolen added a comment - I suspect that the whitespace and output wrapper combination is not compatible. I'm inclined to close this one as it's a Closure limitation not a ClojureScript one. I would be open to an error when these two options are combined.
Hide
Immo Heikkinen added a comment -

Patch for throwing error when :output-wrapper and :optimizations :whitespace are combined

Show
Immo Heikkinen added a comment - Patch for throwing error when :output-wrapper and :optimizations :whitespace are combined
Hide
David Nolen added a comment -

Before proceeding this ticket needs more information. I would like confirmation that it is actually a Closure limitation first. The easiest way to confirm is to use Google Closure directly on some simple JavaScript.

Show
David Nolen added a comment - Before proceeding this ticket needs more information. I would like confirmation that it is actually a Closure limitation first. The easiest way to confirm is to use Google Closure directly on some simple JavaScript.
Hide
Immo Heikkinen added a comment -

With the following JS file:

$ cat hello.js
goog.provide("hello");
goog.require("goog.string");

alert("Hello!");

the following compile command (using the same versions of closure-library and closure-compiler as clojurescript master)

$ java -jar closure-compiler/build/compiler.jar --js closure-library/closure/goog/base.js --js closure-library/closure/goog/string/string.js --js hello.js --compilation_level=WHITESPACE_ONLY --formatting=PRETTY_PRINT --output_wrapper=';(function(){%output%})();' --js_output_file=hello-compiled.js

produces a file the fails in the same way.

If I remove goog.string dependency, the compiled JS file works fine. If I change it to something else (e.g. goog.object), it gives a similar kind of error.

Show
Immo Heikkinen added a comment - With the following JS file:
$ cat hello.js
goog.provide("hello");
goog.require("goog.string");

alert("Hello!");
the following compile command (using the same versions of closure-library and closure-compiler as clojurescript master)
$ java -jar closure-compiler/build/compiler.jar --js closure-library/closure/goog/base.js --js closure-library/closure/goog/string/string.js --js hello.js --compilation_level=WHITESPACE_ONLY --formatting=PRETTY_PRINT --output_wrapper=';(function(){%output%})();' --js_output_file=hello-compiled.js
produces a file the fails in the same way. If I remove goog.string dependency, the compiled JS file works fine. If I change it to something else (e.g. goog.object), it gives a similar kind of error.
Hide
David Nolen added a comment -

Thank you for the confirmation!

Show
David Nolen added a comment - Thank you for the confirmation!

People

Vote (2)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: