sstephenson / ruby-yui-compressor

A Ruby interface to YUI Compressor for minifying JavaScript and CSS assets.
217 stars 57 forks source link

YUI Compressor fails with files it used to handle #35

Closed lilith closed 10 years ago

lilith commented 10 years ago
[ERROR] in /var/folders/lw/wpjq02b95n9db2xb8p07y8f40000gn/T/yui_compress20131125-6885-1lt7iyc
  1:8784:invalid property id
[ERROR] in /var/folders/lw/wpjq02b95n9db2xb8p07y8f40000gn/T/yui_compress20131125-6885-1lt7iyc
  1:0:Compilation produced 1 syntax errors.
org.mozilla.javascript.EvaluatorException: Compilation produced 1 syntax errors.
    at com.yahoo.platform.yui.compressor.YUICompressor$1.runtimeError(YUICompressor.java:172)
    at org.mozilla.javascript.Parser.parse(Parser.java:396)
    at org.mozilla.javascript.Parser.parse(Parser.java:340)
    at com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompressor.java:315)
    at com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScriptCompressor.java:536)
    at com.yahoo.platform.yui.compressor.YUICompressor.main(YUICompressor.java:147)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)
YUI::Compressor::RuntimeError - Command 'java -jar /Users/nathanael/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/yui-compressor-0.12.0/lib/yui/../yuicompressor-2.4.8.jar --type js --charset utf-8 --nomunge /var/folders/lw/wpjq02b95n9db2xb8p07y8f40000gn/T/yui_compress20131125-6885-1lt7iyc' returned non-zero exit status:
    /Users/nathanael/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:106:in `block in compress'
    /Users/nathanael/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:141:in `streamify'
    /Users/nathanael/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:86:in `compress'
    /Users/nathanael/Documents/njcom/resizer-web/site.rb:142:in `block (2 levels) in <class:Site>'
    /Users/nathanael/Documents/njcom/resizer-web/site.rb:133:in `map'
    /Users/nathanael/Documents/njcom/resizer-web/site.rb:133:in `block in <class:Site>'
    /Users/nathanael/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sinatra-1.4.4/lib/sinatra/base.rb:1592:in `call'
stevecrozz- commented 10 years ago

Thanks for the report. I suspect there was an issue in compressing your particular javascript. Can you do a little research to rule that out, or post the JavaScript you're trying to compress?

lilith commented 10 years ago

Oh, it's very likely a javascript bug - I just thought I remembered the error handling being different under 1.9.3. I had some trouble reproducing it locally since I couldn't get a detailed ruby error on the server.

lilith commented 10 years ago

Is there a way I can get the syntax error message from within the RuntimeException object?

skatkov commented 10 years ago

I'm having this issue with 1.9.3, so it's not related to 2.0

lilith commented 10 years ago

Yeah - turns out YUI Compressor broke backwards compatibility somehow. A particular version of highlight.pack.js was at fault, but had previously worked fine.

skatkov commented 10 years ago

Thanks for a tip, Nathanael.

I locked yui-compressor version in gemfile like this: gem 'yui-compressor', '~> 0.11.0'

and it seems to be working for me.

stevecrozz commented 10 years ago

In the yui-compressor gem v0.12.0, we upgraded from YUI Compressor 2.4.7 to 2.4.8. Are you thinking there was a regression in YUI Compressor 2.4.8? I'd like to see an example of a file that exhibits this problem. If anyone can point me to such a file, I'd be happy to have a look.

As a side note, many people use this gem by first concatenating many JavaScript files into one stream before passing them off to YUI Compressor. In this typical case, even if YUI Compressor could give you more details, it's already too late if you want to be pointed to the original source file with the problem. I recommend using something like https://github.com/jshint/jshint or https://github.com/douglascrockford/JSLint if possible to identify errors before compression.

skatkov commented 10 years ago

@stevecrozz I've sent you a file.

lilith commented 10 years ago

Mine is http://imageresizing.net/js/highlight/highlight.pack.js As far as I can tell, JSLint just complains about an missing implicit semicolon. I really don't care too much; I was incorrectly re-compressing pre-compressed javascript anyway - fixing that avoided the problem.

Easier error logging/debugging would be great - I was originally confused into believing it was a 1.9.3/2.0.0 bug since that was the 'only' change (other than updating this gem). Seeing the error as a SyntaxError instead of RuntimeError would probably have been enough to clarify.

stevecrozz commented 10 years ago

nathanieljones: Your issue underlying problem seems to be caused by using the keyword let as an object property name in highlight.pack.js. For example, var i = {let:1}; compresses fine with YUI Compressor 2.4.7 but not 2.4.8. Interestingly, this is allowed under ES5, but support for it isn't universal among browser vendors (http://kangax.github.io/es5-compat-table/#Reserved_words_as_property_names). Regardless, it does seem like a YUICompressor bug, so it should probably be reported upstream.

skatkov: Your issue is from this use of IE conditional comments which you're using for browser detection. Here's an example of script that compiles in YUI Compressor 2.4.7 but not 2.4.8. function () { /*@cc_on*/ return; } This looks like perfectly valid JavaScript to me and so I think this is also a YUICompressor bug that should be raised with the YUI Compressor project.

Maybe we can submit these failing test cases upstream.

As far as this project goes, I tried increasing the verbosity level in the call to YUI Compressor and the extra output was not helpful, so we probably shouldn't do that. Since the command runs in a separate java process, there's not much else we can do besides check the exit status and raise a generic exception if the status is non-zero. But I'm open to suggestions if there are any.