Latest post 07-14-2008 7:35 by admin. 2 replies.
  • 07-02-2008 22:08

    modified packer code

    I have a modification to the packer so that it can "fix function".  In BLOCKED SCRIPT

    var a = function () {

    }

    Should really be:

    var a = function () {

    };

    this is because you are setting a to an unnamed function.  So I came up with this code:

    function_fix: function (script) {
            var list=[];
            script.replace(/(=function)/g, function (rep, Something, place, str, s) {
                str = str + '';
                var b=0,c;
                for(var a = place;a<str.length;) {
                    var op = str.indexOf('{', a);
                    var cl = str.indexOf('}', a);
                    if(cl < 0){ throw "Not Balanced"; return;}
                    if(op < cl && op > -1) { // open is next
                        c = true;
                        b++;
                        a = op+1;
                    }else{
                        b--;
                        a = cl+1;
                    }
                    if(b == 0 && c == true) break;
                }
                a--;
                if(script[a+1] != ";" && script[a+1] != ",") // fix for: var a=function () {}, b=function(){};
                    list.push(a+list.length);
                return str;
            });
            while(list.length) {
                var a = list.shift();
                var befor = script.substring(0, a+1), after = script.substring(a+1);
                script = befor + ";" + after;
            }
           
            return script;
        },

     

    Just add it after the pack function in Packer.js and change

    script = this.minify(script + " ");
    script = this.function_fix(script);
    if (shrink) script = this._shrinkVariables(script);

    The code will fix function and reduces the number of time that I see a missing ; error when I have packed my code

  • 07-07-2008 9:05 In reply to

    Re: modified packer code

    Hi Matthew, it would be great to avoid the required ";" for functions. I've contacted the author of the algorithm (Dean Edwards) and we might add it to javascriptcompressor.com shortly!


    Thanks for your contribution!

  • 07-14-2008 7:35 In reply to

    • admin
    • Top 10 Contributor
    • Joined on 06-23-2008
    • Posts 5

    Re: modified packer code

    Hi again Matthew, I've received an email from the algo author. He is currently working on version 3.1 soon to be released. He will take a look at your code at see if he can implement it. He says its a difficult task to fix the "function" issue - it would be amazing if you have fixed it :)

Page 1 of 1 (3 items) | RSS