24

I am trying to minify a few files with YUI compressor. However, I seem to be getting an error on 2 lines of code, which prevents compression. The .js file for jcarouselLite contains 1 error, and my own code contains the other.

I have narrowed it down and in both occasions it looks like the the float property used in jQuery is causing this. The line is:

li.css({overflow: "hidden", float: o.vertical ? "none" : "left"}); (jcarousellite)

$("#now-playing .js-kit-rating div:first").css({width: "80px", float: "right"}).addClass("clearing"); (own code)

A working example of the error can be seen by running the jCarouselLite code through the YUI compressor, but basically the error returned is invalid property id.

Has anyone had similar issues with the YUI compressor?

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
user47378
  • 271
  • 2
  • 3
  • 4
  • Sounds like you need to be running Firefox and the Firebug JS debugger, it should catch things like this, maybe. – TravisO Jan 08 '09 at 14:58

5 Answers5

59

It's not YUI per se, it's the jcarouselLite js. "float" is a reserved word. It needs to be put in quotes. EG:

li.css({overflow: "hidden", "float": o.vertical ? "none" : "left"});

Similar issue with your own code. YUI is trying its best to compile that js but will refuse/warn you of code like the one you found. IMO it's doing the right thing.

Crescent Fresh
  • 115,249
  • 25
  • 154
  • 140
  • 3
    to be accurate, float is not a reserved word in javascript, but YUI flags it because it is a "possible future keywords by the ECMAScript specification." – BishopZ Jul 09 '12 at 15:41
  • It took me a while to figure out that `var coordinates = { long: 0, lat: 0 };` was a problem (long reserved word). Thanks. – Pawel Krakowiak May 28 '13 at 13:22
9

I've run into this issue a few times with the word "class". If you're using YUI on the server side, it should spit out the line number it's complaining about.

Here's a list of reserved words that seems pretty comprehensive.

http://mattsnider.com/languages/javascript/reserved-words-in-javascript/

Bob Ralian
  • 1,949
  • 1
  • 20
  • 29
3

The other answers here answer the actual problem (reserved words). But I am using YUI via BundleTransformer and it isn't outputting line numbers, so I was a little lost as to where to look.

To speed up the process of finding the keywords I went looking for another tool.

This online YUI compressor helped me find the problematic property name.

Brad
  • 15,361
  • 6
  • 36
  • 57
0

in my case when YUI was unable to compress my files it was because I had the 'debugger' in the js file. Hope this saves someone else several hours of debugging!

JenniferG
  • 602
  • 1
  • 5
  • 13
0

I have prepared a custom version for update yui compressor

https://github.com/MrD0llaro/yuicompressor and https://github.com/MrD0llaro/yui-compressor-ant-task/ for use it on new Jquery 3.5.1

Gianluca Musa
  • 755
  • 7
  • 22