Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes mocha.js YUI-compressible #1035

Conversation

ArnaudBrousseau
Copy link
Contributor

Before this diff, trying to compress mocha.js with YUI compressor would result in the following output

=> java -jar yuicompressor-2.4.8.jar mocha.js
[ERROR] in mocha.js
  1733:19:missing name after . operator
[ERROR] in mocha.js
  1734:16:identifier is a reserved word
[ERROR] in mocha.js
  1735:9:missing ; before statement
[ERROR] in mocha.js
  1736:17:identifier is a reserved word
[ERROR] in mocha.js
  1738:2:missing ) after argument list
[ERROR] in mocha.js
  1787:15:missing ( before function parameters.
[ERROR] in mocha.js
  1787:15:missing } after function body
[ERROR] in mocha.js
  1788:22:missing ; before statement
[ERROR] in mocha.js
  1789:22:invalid return
[ERROR] in mocha.js
  1790:22:invalid return
[ERROR] in mocha.js
  1791:22:invalid return
[ERROR] in mocha.js
  1792:9:invalid return
[ERROR] in mocha.js
  1793:1:syntax error
[ERROR] in mocha.js
  1803:14:identifier is a reserved word
[ERROR] in mocha.js
  1809:1:syntax error
[ERROR] in mocha.js
  1815:30:missing ; before statement
[ERROR] in mocha.js
  1816:21:missing ; before statement
[ERROR] in mocha.js
  1817:27:invalid return
[ERROR] in mocha.js
  1818:9:invalid return
[ERROR] in mocha.js
  1819:1:syntax error
[ERROR] in mocha.js
  1821:2:syntax error
[ERROR] in mocha.js
  5600:1:syntax error
[ERROR] in mocha.js
  1:0:Compilation produced 22 syntax errors.
org.mozilla.javascript.EvaluatorException: Compilation produced 22 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:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)

After this change, mocha.js compresses as you would expect, without errors.

The reason why YUI failed to compress mocha.js: it uses of long and short as identifiers. They are reserved word in ECMAScript since ECMAScript v2:
reserved_words

Cheers,
Arnaud.

@ArnaudBrousseau
Copy link
Contributor Author

While long isn't reserved in ECMAScript 5.1 anymore (my bad for not catching that, I should've said so in my original message), backward-compatibility with older JS engines impose that we shouldn't name vars or functions with any of the reserved keywords ever put in a spec.
Set of reserved words in JS = union of all the reserved words for all specs. See http://mathiasbynens.be/notes/reserved-keywords

I believe this MDN article is out of date. I'll update.

@ArnaudBrousseau
Copy link
Contributor Author

@travisjeffery Updated MDN with all FutureReservedWords across ECMA specs. Looking at YUI it seems they're actually missing a few of them ;)

travisjeffery added a commit that referenced this pull request Nov 25, 2013
@travisjeffery
Copy link
Contributor

ok made the change. didn't merge your commit tho since you made the change in the generated file and i didn't like the function names.

@ArnaudBrousseau
Copy link
Contributor Author

@travisjeffery Thanks a lot! New function names lg2m. And sorry for modifying the wrong file. TIL :)

@campaul
Copy link

campaul commented Aug 25, 2014

This wasn't fully fixed. Having options.long still causes YUI to fail.

boneskull pushed a commit to boneskull/mocha that referenced this pull request Aug 26, 2014
@boneskull
Copy link
Contributor

@campaul should be fixed now in master

tandrewnichols pushed a commit to tandrewnichols/mocha that referenced this pull request Dec 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants