diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-08-25 10:10:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-25 10:10:56 +0800 |
commit | 1caf7c7bd2160a5f249066bf62292f3589ceebb1 (patch) | |
tree | f3c2c7acbfe4655f94718d425c9641f5d4a3ca04 | |
parent | 0eb0c9b388a17fbadd9f74a15effe7477695d5e6 (diff) | |
download | tracifyjs-1caf7c7bd2160a5f249066bf62292f3589ceebb1.tar.gz tracifyjs-1caf7c7bd2160a5f249066bf62292f3589ceebb1.zip |
minor clean up (#4069)
-rw-r--r-- | lib/compress.js | 8 | ||||
-rw-r--r-- | lib/output.js | 16 | ||||
-rw-r--r-- | lib/utils.js | 52 |
3 files changed, 24 insertions, 52 deletions
diff --git a/lib/compress.js b/lib/compress.js index acc85021..4de587ae 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7185,11 +7185,11 @@ merge(Compressor.prototype, { var parent = compressor.parent(); if (compressor.option("comparisons") && self.is_boolean(compressor)) { if (!(parent instanceof AST_Binary) || parent instanceof AST_Assign) { - var negated = make_node(AST_UnaryPrefix, self, { + var negated = best_of(compressor, self, make_node(AST_UnaryPrefix, self, { operator: "!", expression: self.negate(compressor, first_in_statement(compressor)) - }); - self = best_of(compressor, self, negated); + })); + if (negated !== self) return negated; } switch (self.operator) { case ">": reverse("<"); break; @@ -7659,7 +7659,7 @@ merge(Compressor.prototype, { } function is_indexFn(node) { - return node instanceof AST_Call + return node.TYPE == "Call" && node.expression instanceof AST_Dot && indexFns[node.expression.property]; } diff --git a/lib/output.js b/lib/output.js index 82610fb6..cf05e261 100644 --- a/lib/output.js +++ b/lib/output.js @@ -100,7 +100,7 @@ function OutputStream(options) { } } - var indentation = 0; + var indentation = options.indent_start; var current_col = 0; var current_line = 1; var current_pos = 0; @@ -191,10 +191,6 @@ function OutputStream(options) { return name; } - function make_indent(back) { - return repeat_string(" ", options.indent_start + indentation - back * options.indent_level); - } - /* -----[ beautification/minification ]----- */ var has_parens = false; @@ -345,9 +341,7 @@ function OutputStream(options) { }; var indent = options.beautify ? function(half) { - if (options.beautify) { - print(make_indent(half ? 0.5 : 0)); - } + print(repeat_string(" ", half ? indentation - (options.indent_level >> 1) : indentation)); } : noop; var with_indent = options.beautify ? function(col, cont) { @@ -575,9 +569,9 @@ function OutputStream(options) { get : get, toString : get, indent : indent, - indentation : function() { return indentation }, - current_width : function() { return current_col - indentation }, - should_break : function() { return options.width && this.current_width() >= options.width }, + should_break : readonly ? noop : function() { + return options.width && current_col - indentation >= options.width; + }, has_parens : function() { return has_parens }, newline : newline, print : print, diff --git a/lib/utils.js b/lib/utils.js index 8ae17304..2f5a4866 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -112,51 +112,29 @@ function return_this() { return this; } function return_null() { return null; } var List = (function() { - function List(a, f, backwards) { - var ret = [], top = [], i; - function doit() { + function List(a, f) { + var ret = []; + for (var i = 0; i < a.length; i++) { var val = f(a[i], i); - var is_last = val instanceof Last; - if (is_last) val = val.v; - if (val instanceof AtTop) { - val = val.v; - if (val instanceof Splice) { - top.push.apply(top, backwards ? val.v.slice().reverse() : val.v); - } else { - top.push(val); - } - } else if (val !== skip) { - if (val instanceof Splice) { - ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v); - } else { - ret.push(val); - } - } - return is_last; - } - if (Array.isArray(a)) { - if (backwards) { - for (i = a.length; --i >= 0;) if (doit()) break; - ret.reverse(); - top.reverse(); + if (val === skip) continue; + if (val instanceof Splice) { + ret.push.apply(ret, val.v); } else { - for (i = 0; i < a.length; ++i) if (doit()) break; + ret.push(val); } - } else { - for (i in a) if (HOP(a, i)) if (doit()) break; } - return top.concat(ret); + return ret; } List.is_op = function(val) { - return val === skip || val instanceof AtTop || val instanceof Last || val instanceof Splice; + return val === skip || val instanceof Splice; + }; + List.splice = function(val) { + return new Splice(val); }; - List.at_top = function(val) { return new AtTop(val); }; - List.splice = function(val) { return new Splice(val); }; - List.last = function(val) { return new Last(val); }; var skip = List.skip = {}; - function AtTop(val) { this.v = val; } - function Splice(val) { this.v = val; } - function Last(val) { this.v = val; } + function Splice(val) { + this.v = val; + } return List; })(); |