video-dev / hls.js

HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
https://hlsjs.video-dev.org/demo
Other
14.91k stars 2.58k forks source link

Problems with compression code of hls.js using Yahoo compressor (yuicompressor) #633

Closed alexborisyuk closed 8 years ago

alexborisyuk commented 8 years ago

I use uncompressed hls.js in my project. To compress code I use Yahoo compressor (https://github.com/yui/yuicompressor). The source code of this hls.js module is using JS reserved words catch and default this words are indeed marked as reserved https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java#L181-L183 In the result I can not compress hls.js

Steps to reproduce
  1. You need to copy Yahoo compressor and uncompressed hls.js in one folder. (https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.jar)
  2. Run command prompt and launch java -jar yuicompressor-2.4.8.jar hls.js -o myhls-min.js
  3. Observe lot of error-messages from compressor; compressed js-file not created.

To solve this problem I change all the reserved words in hls.js ("default" to "__default" etc.).

Expected behavior

Yahoo compressor works with uncompressed hls.js without errors; compressed js-file creates.

Actual behavior

Lot of Yahoo compressor's errors; compression fails.

Console output
...
[ERROR] 7472:16:missing name after . operator
[ERROR] 7474:1:syntax error
[ERROR] 7497:86:invalid property id
[ERROR] 7551:45:missing name after . operator
[ERROR] 7590:46:missing name after . operator
[ERROR] 7591:20:syntax error
[ERROR] 7592:26:syntax error
[ERROR] 7601:9:missing } after property list
[ERROR] 7601:68:missing ; before statement
...

Is it possible to change names of fields and properties in code of hls.js to do not use the reserved words? Thanks!

mangui commented 8 years ago

Hi @alexborisyuk I digged a little a bit and found out that yuicompressor is complaining about reserved keywords usage, because its parser (Rhino) is not ES5 compliant yet. refer to https://github.com/yui/yuicompressor/issues/98 looks like a yuicompressor issue I would suggest you to use another minifier.