yui / yuicompressor

YUI Compressor
http://yui.github.com/yuicompressor/
Other
3.01k stars 661 forks source link

YUI Compressor 2.4.8 failed on jQuery 2.2 #234

Open stepand76 opened 8 years ago

stepand76 commented 8 years ago

When I try to pass original uncompressed jquery-2.2.0.js file to YUI Compressor 2.4.8 I get following output (with jquery-2.1.4.js it works):

[ERROR] in jquery-2.2.0.js
  8239:27:missing name after . operator
[ERROR] in jquery-2.2.0.js
  8240:17:syntax error
[ERROR] in jquery-2.2.0.js
  8259:7:missing ) after argument list
[ERROR] in jquery-2.2.0.js
  8259:8:syntax error
[ERROR] in jquery-2.2.0.js
  8262:9:syntax error
[ERROR] in jquery-2.2.0.js
  8265:15:syntax error
[ERROR] in jquery-2.2.0.js
  8266:7:syntax error
[ERROR] in jquery-2.2.0.js
  8268:15:syntax error
[ERROR] in jquery-2.2.0.js
  8269:7:syntax error
[ERROR] in jquery-2.2.0.js
  8270:8:syntax error
[ERROR] in jquery-2.2.0.js
  8271:11:syntax error
[ERROR] in jquery-2.2.0.js
  8272:10:syntax error
[ERROR] in jquery-2.2.0.js
  8273:15:syntax error
[ERROR] in jquery-2.2.0.js
  8274:9:syntax error
[ERROR] in jquery-2.2.0.js
  8275:15:syntax error
[ERROR] in jquery-2.2.0.js
  8288:11:syntax error
[ERROR] in jquery-2.2.0.js
  8289:8:syntax error
[ERROR] in jquery-2.2.0.js
  8290:9:syntax error
[ERROR] in jquery-2.2.0.js
  8291:9:syntax error
[ERROR] in jquery-2.2.0.js
  8292:8:syntax error
[ERROR] in jquery-2.2.0.js
  8293:9:syntax error
[ERROR] in jquery-2.2.0.js
  8294:4:syntax error
[ERROR] in jquery-2.2.0.js
  8296:12:syntax error
[ERROR] in jquery-2.2.0.js
  8297:8:syntax error
[ERROR] in jquery-2.2.0.js
  8297:11:illegal character
[ERROR] in jquery-2.2.0.js
  8297:16:illegal character
[ERROR] in jquery-2.2.0.js
  8297:16:syntax error
[ERROR] in jquery-2.2.0.js
  8298:9:syntax error
[ERROR] in jquery-2.2.0.js
  8298:12:illegal character
[ERROR] in jquery-2.2.0.js
  8298:18:syntax error
[ERROR] in jquery-2.2.0.js
  8299:9:syntax error
[ERROR] in jquery-2.2.0.js
  8299:12:illegal character
[ERROR] in jquery-2.2.0.js
  8299:18:illegal character
[ERROR] in jquery-2.2.0.js
  8299:18:syntax error
[ERROR] in jquery-2.2.0.js
  8300:4:syntax error
[ERROR] in jquery-2.2.0.js
  8302:18:syntax error
[ERROR] in jquery-2.2.0.js
  8303:8:syntax error
[ERROR] in jquery-2.2.0.js
  8304:9:syntax error
[ERROR] in jquery-2.2.0.js
  8305:9:syntax error
[ERROR] in jquery-2.2.0.js
  8306:4:syntax error
[ERROR] in jquery-2.2.0.js
  8310:14:syntax error
[ERROR] in jquery-2.2.0.js
  8313:13:syntax error
[ERROR] in jquery-2.2.0.js
  8316:16:syntax error
[ERROR] in jquery-2.2.0.js
  8319:16:syntax error
[ERROR] in jquery-2.2.0.js
  8322:15:syntax error
[ERROR] in jquery-2.2.0.js
  8323:4:syntax error
[ERROR] in jquery-2.2.0.js
  8329:15:syntax error
[ERROR] in jquery-2.2.0.js
  8330:8:syntax error
[ERROR] in jquery-2.2.0.js
  8331:12:syntax error
[ERROR] in jquery-2.2.0.js
  8333:2:syntax error
[ERROR] in jquery-2.2.0.js
  8338:12:syntax error
[ERROR] in jquery-2.2.0.js
  8346:2:syntax error
[ERROR] in jquery-2.2.0.js
  8348:16:syntax error
[ERROR] in jquery-2.2.0.js
  8349:16:syntax error
[ERROR] in jquery-2.2.0.js
  8352:7:syntax error
[ERROR] in jquery-2.2.0.js
  8355:34:missing ; before statement
[ERROR] in jquery-2.2.0.js
  8356:13:syntax error
[ERROR] in jquery-2.2.0.js
  8358:3:syntax error
[ERROR] in jquery-2.2.0.js
  8361:12:syntax error
[ERROR] in jquery-2.2.0.js
  8535:10:invalid return
[ERROR] in jquery-2.2.0.js
  8614:10:invalid return
[ERROR] in jquery-2.2.0.js
  8641:11:invalid return
[ERROR] in jquery-2.2.0.js
  8781:9:invalid return
[ERROR] in jquery-2.2.0.js
  8782:2:syntax error
[ERROR] in jquery-2.2.0.js
  8784:10:syntax error
[ERROR] in jquery-2.2.0.js
  8786:2:syntax error
[ERROR] in jquery-2.2.0.js
  8788:12:syntax error
[ERROR] in jquery-2.2.0.js
  8790:2:syntax error
[ERROR] in jquery-2.2.0.js
  8791:3:syntax error
[ERROR] in jquery-2.2.0.js
  9830:7:invalid return
[ERROR] in jquery-2.2.0.js
  9831:1:syntax error
[ERROR] in jquery-2.2.0.js
  1:0:Compilation produced 71 syntax errors.
org.mozilla.javascript.EvaluatorException: Compilation produced 71 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(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)
fiatux commented 8 years ago

same problem here!

stepand76 commented 8 years ago

Any chance that this will be fixed?

mgol commented 8 years ago

This is a bug in YUI Compressor. Could you report it to them?

stepand76 commented 8 years ago

It is reported to the YUI Compressor, isn't it?

mgol commented 8 years ago

I'm sorry, for a moment I thought it was reported against jQuery... I commented too fast, please disregard.

IceReaper commented 8 years ago

Problem: "throws" and several other names are marked as reserved in YUI, while jquery assumes they are not and uses them. Location: https://github.com/yui/yuicompressor/blob/c41a4b504a996b9c2a49b497e2f61ba7998b0408/src/org/mozilla/javascript/TokenStream.java

Step1: Make a list of all wrongly-reserved-names plus proof-link Step2: Remove them and make a PR or fork of YUI and / or jQuery, depending on who violates the JS-RFC. Shouldn't take that much time to do.

If there is already such PR, link it here. Haven't found one.

tml commented 8 years ago

To clarify - "throws" and several other names are marked as reserved in JAVASCRIPT, and YUICompressor is respecting that declaration.

The trick that makes it a bit harder is that YUICompressor isn't tied to a specific version of Java/ECMAScript, and in older versions, these are illegal identifiers. So you have to allow it for ES5+ while not allowing it in ES4 and earlier; while keeping in mind that there's no standardized way for a bit of JavaScript code to declare which version of JS/ES it thinks it wants to be.

If you have ideas for solving all of those problems in the same go, I'd love to hear about them! :)

IceReaper commented 8 years ago

As an ugly workaround it could be possible to do a replacement before / after minification. The replacement-logic could be triggered by a simple --language-version parameter.

bashor commented 8 years ago

Same issue with kotlin.js. Should I report separate issue?

To reproduce download kotlin-compiler-1.0.1.zip and see kotlinc/lib/kotlin-jslib.jar/kotlin.js

stepand76 commented 8 years ago

Well, any chance this to be fixed?

saleehk commented 8 years ago

+1

meyermc commented 8 years ago

I have this same issue with pdf.js, I tried to give them a pull request and they rejected it, pointing out that 'char' is not a reserved word in ES5.1 and that ECMSScript permits reserved words ('catch', 'delete') as property names. So, declaring a reserved word variable or function is illegal but assigning a function literal to a reserved word property is valid.

varun1987shrivastava commented 7 years ago

I think this is related to the keywords that js file uses clash with some in-build keywords of the compressor. you can try using the minified version of the js file to get rid of this issue. this is something i did in my project when using jquery-3.1.0.

LeiZeng commented 7 years ago

A work around by using babel plugins: https://gist.github.com/LeiZeng/535de7c66f1a847c7bf80705098ea517

nueverest commented 7 years ago

Still breaking for jquery is there a reason this is closed?

mgol commented 7 years ago

@nueverest This issue is not closed.

dignityinside commented 7 years ago

+1

timurgen commented 7 years ago

+1

Chris2011 commented 7 years ago

Issue still appears. As you can see it here too: https://github.com/yui/yuicompressor/issues/262 Is this Project still alive?

SuperPat45 commented 6 years ago

+1

NucleaPeon commented 5 years ago

Yuicompressor fails against jquery v3.3.1 too

[ERROR] in jquery-3.3.1.js
  3845:9:missing name after . operator
[ERROR] in jquery-3.3.1.js
  3846:11:syntax error
[ERROR] in jquery-3.3.1.js
  3847:5:missing ; before statement
[ERROR] in jquery-3.3.1.js
  3850:2:missing ) after argument list
[ERROR] in jquery-3.3.1.js
  8783:27:missing name after . operator
[ERROR] in jquery-3.3.1.js
  8784:17:syntax error
[ERROR] in jquery-3.3.1.js
  8800:8:invalid return
[ERROR] in jquery-3.3.1.js
  8800:34:missing ; before statement
[ERROR] in jquery-3.3.1.js
  10363:7:invalid return
[ERROR] in jquery-3.3.1.js
  10364:1:syntax error
[ERROR] in jquery-3.3.1.js
  1:0:Compilation produced 10 syntax errors.
org.mozilla.javascript.EvaluatorException: Compilation produced 10 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:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)
tml commented 5 years ago

That's correct - jquery 3.3.1 is not valid ECMAScript 3 syntax; YUICompressor does not support anything else at this time.

MrD0llaro commented 4 years ago

I have solved with custom methods, i have used a fork https://github.com/MrD0llaro/yuicompressor