mythz/jquip

ClosureCompiler ADVANCED - Errors

Closed this issue · 5 comments

I have been trying to compile jquip using Closure Compiler in Advanced mode simply by compiling jquip.js alone (no other plug-ins). I get a heap of warnings. Am I doing something wrong?

To re-create what I am trying to do go to:

http://closure-compiler.appspot.com/home

Run the closure compiler in ADVANCED & include the link to the raw jquip.js code:

https://raw.github.com/mythz/jquip/master/src/jquip.js

You can simply do this by adding this header to the top:

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @code_url https://raw.github.com/mythz/jquip/master/src/jquip.js
// ==/ClosureCompiler==

You will get a log of warnings like this:

23: java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.
Unexpected variable trimLeft$$inline_78
Node(NAME trimLeft$$inline_78): https://raw.github.com/mythz/jquip/master/src/jquip.js:745:73
: function(text){ return text == null ? "" : text.toString().replace(trimLeft, "").replace(trimRight, ""); };
Parent(CALL): https://raw.github.com/mythz/jquip/master/src/jquip.js:745:49
: function(text){ return text == null ? "" : text.toString().replace(trimLeft, "").replace(trimRight, ""); };

the list of errors / warnings will go on
...

I get the same results with closure.jar

Any help would be appreciated. Thanks for all the efforts you guys are putting into jquip I think it's a great idea.

Just committed 1c20317 which eliminates that error.

Just checked, and the tests don't seem too happy with the closure compiled version. It's going to need some work to get that corrected.

Did some work on making tests pass with closure. https://github.com/mythz/jquip/tree/closure-compat

So far the file size isn't too different from what UglifyJS provides (6.5k gzipped vs 6.6k).

Jason thanks for the help! Looks like jquip.js compiles now using ADVANCED w/ closure compiler.

I combined src/jquip.js & src/jquip.events.js using closure compiler advanced. I then called a $(document).bind() command when compiled I get this error (in a non-compiled version it works fine):

Uncaught TypeError: Object # has no method 'make' line: jquip/src/jquip.js:73 (using source mapping)

I prittified the compiled code to get a better idea of what's going on:

'''javascript
(function(window, undefined) {
var h = void 0, i = !0, j = null, l = !1, aa = window, ba = window;
function m(a, b) {
for (var c, d = 0, e = p.length; d < e; d++)
if (p[d].apply(this, arguments))
return this;
if (!a)
return this;
if (q(a))
return r ? a() : t.push(a), this;
if (v(a))
return this.make(a);
if (a.nodeType || w(a))
return this.make([a]); //<--- Uncaught TypeError: Object # has no method 'make'
if ("body" == a && !b && x.body)
return this.context = a.context, this[0] = x.body, this.length = 1, this.selector = a, this;
if (a.selector !== h)
return this.context = a.context, this.selector = a.selector, this.make(a);
a = y(a) && "<" === a.charAt(0) ? (c = ca.exec(a)) ? [x.createElement(c[1])] : z(a).childNodes : A(this.selector =
a, b);
this.make(a);
B(b) && this.attr(b);
return this;
...
'''

I thought maybe it was because I was combining my code & jquip into an anonymous closure but that doesn't seem to be the cause of the issue; i moved jquip code out of the closure and still got the same error. Any idea what's causing this error?

In your opinion should we use uglifyjs (not closurecompiler) when working on project that include jquip?

The reason for the missing 'make' error is that a good number of the functions are not exported correctly for closure and get optimized away.

I recommend using either uglifyjs or closure with simple optimizations until jquip works again with advanced optimizations.