From b5a7a231f7e9f09cc00e92c970d304d6071f7ac1 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Tue, 12 Apr 2016 14:15:14 +0300 Subject: [PATCH] Actually limit sequence length. Fix #1038 --- lib/ast.js | 7 +++++++ lib/compress.js | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) 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(); -- 2.34.1