Details
-
Type:
Defect
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:NodeJS 0.6.1
MacOSX Lion
Description
Running the example from http://mmcgrana.github.com/2011/09/clojurescript-nodejs.html. Node fails if using :whitespace optimizations, but works when using :simple. The problem seems to be missing object literals.
The source is:
$ cat src/testing-cljs-node/hello.cljs
(ns testing-cljs-node.hello)
(defn start [& _]
(println "Hello World!"))
(set! *main-cli-fn* start)
Here is the compilation that results in the broken code:
$ cljsc src/testing-cljs-node/hello.cljs '{:optimizations :whitespace :pretty-print true :target :nodejs}' > out/hello.js
$ node out/hello.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot set property 'Unicode' of undefined
at Object.<anonymous> (/Users/ulrik/Source/testing-cljs-node/out/hello.js:487:21)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.0 (module.js:470:10)
at EventEmitter._tickCallback (node.js:192:40)
When changing the optimizations to :simple, however, it works:
$ cljsc src/testing-cljs-node/hello.cljs '{:optimizations :simple :pretty-print true :target :nodejs}' > out/hello.js
$ node out/hello.js
The "sys" module is now called "util". It should have a similar interface.
Hello World!
The offending line 487 in the :whitespace code:
goog.provide("goog.string"); goog.provide("goog.string.Unicode"); goog.string.Unicode = {NBSP:"\u00a0"}; // line 487
In the working :simple code, the corresponding lines looks like this:
goog.string = {};
goog.string.Unicode = {NBSP:"\u00a0"}; // line 367
If I fix that by adding a line that creates the object, I get another error on line 901:
goog.provide("goog.userAgent.jscript"); goog.require("goog.string"); goog.userAgent.jscript.ASSUME_NO_JSCRIPT = false; // line 901
In the working code, it looks like this:
goog.userAgent = {};
goog.userAgent.jscript = {};
goog.userAgent.jscript.ASSUME_NO_JSCRIPT = !1; // line 683
And if I fix that, I get another error on line 975:
goog.provide("goog.debug.Error"); goog.debug.Error = function(opt_msg) { // line 975
The working code:
goog.debug = {};
goog.debug.Error = function(a) { // line 730
etc etc
I'm not sure how to fix this since the implementation of goog.provide has no meaning in Node.js. As a compromise perhaps we should complain if you try to target node with :whitespace optimizations?