aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai.bazon@gmail.com>2016-04-12 14:15:14 +0300
committerMihai Bazon <mihai.bazon@gmail.com>2016-04-12 14:17:24 +0300
commitb5a7a231f7e9f09cc00e92c970d304d6071f7ac1 (patch)
treeb543c3c1cb0666df24f90a0a9273800188ad1356
parent3907a5e3b2c40904f2cb333ede23d6d59bb48c13 (diff)
downloadtracifyjs-b5a7a231f7e9f09cc00e92c970d304d6071f7ac1.tar.gz
tracifyjs-b5a7a231f7e9f09cc00e92c970d304d6071f7ac1.zip
Actually limit sequence length.
Fix #1038
-rw-r--r--lib/ast.js7
-rw-r--r--lib/compress.js20
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();