From: Mihai Bazon Date: Tue, 12 Apr 2016 11:15:14 +0000 (+0300) Subject: Actually limit sequence length. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b5a7a231f7e9f09cc00e92c970d304d6071f7ac1;p=UglifyJS.git Actually limit sequence length. Fix #1038 --- diff --git a/lib/ast.js b/lib/ast.js index 2a461834..42506cb2 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -633,6 +633,13 @@ var AST_Seq = DEFNODE("Seq", "car cdr", { p = p.cdr; } }, + len: function() { + if (this.cdr instanceof AST_Seq) { + return this.cdr.len() + 1; + } else { + return 2; + } + }, _walk: function(visitor) { return visitor._visit(this, function(){ this.car._walk(visitor); diff --git a/lib/compress.js b/lib/compress.js index e47be97b..153e70fb 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -673,8 +673,12 @@ merge(Compressor.prototype, { seq = []; }; statements.forEach(function(stat){ - if (stat instanceof AST_SimpleStatement && seq.length < 2000) seq.push(stat.body); - else push_seq(), ret.push(stat); + if (stat instanceof AST_SimpleStatement && seqLength(seq) < 2000) { + seq.push(stat.body); + } else { + push_seq(); + ret.push(stat); + } }); push_seq(); ret = sequencesize_2(ret, compressor); @@ -682,6 +686,18 @@ merge(Compressor.prototype, { return ret; }; + function seqLength(a) { + for (var len = 0, i = 0; i < a.length; ++i) { + var stat = a[i]; + if (stat instanceof AST_Seq) { + len += stat.len(); + } else { + len++; + } + } + return len; + }; + function sequencesize_2(statements, compressor) { function cons_seq(right) { ret.pop();