lautis / uglifier

Ruby wrapper for UglifyJS JavaScript compressor.
http://www.rubydoc.info/gems/uglifier
MIT License
613 stars 82 forks source link

ES6 for-of is not parsed correctly #126

Closed runlevel5 closed 6 years ago

runlevel5 commented 6 years ago

It seems to me ES6 for-of is not correctly parsed.

Uglifier.new.compile("for (var value of myArray) { console.log(value) }")
# => Uglifier::Error: Unexpected token name «of», expected punc «;»

Wondering if others experience same issue.

lautis commented 6 years ago

ES6 support in uglifyjs is still more or less experimental and not enabled by default in Uglifier. Uglifier.new(harmony: true).compile("for (var value of myArray) { console.log(value) }") works.

jtara commented 6 years ago

Any thoughts about supporting uglify-es? I have not come across a Gem that wraps it yet...

lautis commented 6 years ago

Yes, you can use uglify-es. The option is named harmony, which is slightly inconvenient. At least I wasn't aware at the time that there would be a long-running separate package with name uglify-js at the time when that was added to Uglifier.

This should work:

Uglifier.new(harmony: true).compile("for (var value of myArray) { console.log(value) }")