简单JS代码压缩器

2019-06-03 18:43:24于海丽

       var codeArr        = new Array();
       var word_index    = 0;
       var htmlTxt        = new Array();

       if(this.isCompress){
           this._deleteComment = true;
       }


       //得到分割字符数组(分词)
       for (var i = 0; i < this._codetxt.length; i++) {       
           if (this._wordDelimiters.indexOf(this._codetxt.charAt(i)) == -1) {        //找不到关键字
               if (codeArr[word_index] == null || typeof(codeArr[word_index]) == 'undefined') {
                   codeArr[word_index] = "";
               }
               codeArr[word_index] += this._codetxt.charAt(i);
           } else {
               if (typeof(codeArr[word_index]) != 'undefined' && codeArr[word_index].length > 0)
                   word_index++;
               codeArr[word_index++] = this._codetxt.charAt(i);                
           } 
       }


       var quote_opened                = false;    //引用标记
       var slash_star_comment_opened   = false;    //多行注释标记
       var slash_slash_comment_opened  = false;    //单行注释标记
       var line_num                    = 1;        //行号