3

YUI Compressor, in its (not very extensive) documentation states this as an option:

--disable-optimizations
    Disable all the built-in micro optimizations.

Does anyone know what this means?
What will this turn on/off?
I haven't found any documentation about it.

Thanks!

Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243

1 Answers1

10

Looking at the source of JavaScriptCompressor:

lines 548-

    if (!disableOptimizations) {
        optimizeObjectMemberAccess(this.tokens);
        optimizeObjLitMemberDecl(this.tokens);
    }

lines 467 -

/*
* Transforms obj["foo"] into obj.foo whenever possible, saving 3 bytes.
*/
private static void optimizeObjectMemberAccess(ArrayList tokens) {

lines 497 -

/*
 * Transforms 'foo': ... into foo: ... whenever possible, saving 2 bytes.
 */
private static void optimizeObjLitMemberDecl(ArrayList tokens) {

So it's converting use of constant strings in foo['bar'] to foo.bar and {'bar':x} to {bar:x}.

Pete Kirkham
  • 48,893
  • 5
  • 92
  • 171
  • Thanks! I'm definitely disabling those. For some reason, they make me feel a bit weird about YUI doing that to my code. – Daniel Magliola Mar 24 '09 at 15:51
  • Why wouldn't you want YUI doing that to your code? In JavaScript, `window.location` and `window['location']` mean **exactly** the same thing. – Matthew Nov 04 '10 at 01:02
  • 2
    @Matthew use @ to address the reply, or I see the message, not Daniel – Pete Kirkham Nov 04 '10 at 13:16
  • might be problematic in some cases, e.g. if you doo foo.delete, IE8 will think its a reserved js keyword (delete) and throw an error, so foo["delete"] is necesarry in IE8. – Björn Jun 11 '13 at 09:17
  • 1
    @Marcel delete is added to the list of reserved words, so won't get replaced https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java#L184 – Pete Kirkham Jun 11 '13 at 10:16