Julian Jelfs’ Blog

Digging into YUICompressor – fo sho!

Posted in Javascript by julianjelfs on April 8, 2009

I was looking into using the YUI Compressor code to compress and combine my javascript files and specifically at the ready made msbuild task that comes with it. I wandered why the “ObfuscateJavascript” parameter appeared not to work using the following build script fragment:

<CompressorTask
            JavaScriptFiles="@(JavaScriptFiles)"
            ObfuscateJavaScript="True"
            PreserveAllSemicolons="False"
            DisableOptimizations="False"
            EncodingType="Default"
            DeleteJavaScriptFiles="False"
            LineBreakPosition="-1"
            JavaScriptOutputFile="$(UserInterfaceReleaseDir)\include\ControlScripts\ArmControlContainer.js"
            LoggingType="ALittleBit"
            ThreadCulture="en-gb" />

Digging into the code a little I can see this:

_obfuscateJavaScript = !string.IsNullOrEmpty(ObfuscateJavaScript)
    && ParseSillyTrueFalseValue(ObfuscateJavaScript.ToUpperInvariant());

ParseSillyTrueFalseValue? Well it looks like this:

private static bool ParseSillyTrueFalseValue(string value)
{
    bool result;

    if (string.IsNullOrEmpty(value))
    {
        throw new ArgumentNullException("value");
    }

    switch (value)
    {
        case "yes":
        case "y":
        case "yep":
        case "yeah":
        case "true":
        case "fosho":
        case "fo sho":
            result = true;
            break;
        default:
            result = false;
            break;
    }

    return result;
}

How bizarre? And also notice that the input is always being converted to upper case, but the switch statement only checks lower case values so it always returns false.

I’m sure that the compression code itself is a lot more solid but I think I might write my own msbuild task….

Advertisements
Tagged with:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: