minor clean up (#4069)
This commit is contained in:
@@ -7185,11 +7185,11 @@ merge(Compressor.prototype, {
|
|||||||
var parent = compressor.parent();
|
var parent = compressor.parent();
|
||||||
if (compressor.option("comparisons") && self.is_boolean(compressor)) {
|
if (compressor.option("comparisons") && self.is_boolean(compressor)) {
|
||||||
if (!(parent instanceof AST_Binary) || parent instanceof AST_Assign) {
|
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: "!",
|
operator: "!",
|
||||||
expression: self.negate(compressor, first_in_statement(compressor))
|
expression: self.negate(compressor, first_in_statement(compressor))
|
||||||
});
|
}));
|
||||||
self = best_of(compressor, self, negated);
|
if (negated !== self) return negated;
|
||||||
}
|
}
|
||||||
switch (self.operator) {
|
switch (self.operator) {
|
||||||
case ">": reverse("<"); break;
|
case ">": reverse("<"); break;
|
||||||
@@ -7659,7 +7659,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function is_indexFn(node) {
|
function is_indexFn(node) {
|
||||||
return node instanceof AST_Call
|
return node.TYPE == "Call"
|
||||||
&& node.expression instanceof AST_Dot
|
&& node.expression instanceof AST_Dot
|
||||||
&& indexFns[node.expression.property];
|
&& indexFns[node.expression.property];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var indentation = 0;
|
var indentation = options.indent_start;
|
||||||
var current_col = 0;
|
var current_col = 0;
|
||||||
var current_line = 1;
|
var current_line = 1;
|
||||||
var current_pos = 0;
|
var current_pos = 0;
|
||||||
@@ -191,10 +191,6 @@ function OutputStream(options) {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function make_indent(back) {
|
|
||||||
return repeat_string(" ", options.indent_start + indentation - back * options.indent_level);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----[ beautification/minification ]----- */
|
/* -----[ beautification/minification ]----- */
|
||||||
|
|
||||||
var has_parens = false;
|
var has_parens = false;
|
||||||
@@ -345,9 +341,7 @@ function OutputStream(options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var indent = options.beautify ? function(half) {
|
var indent = options.beautify ? function(half) {
|
||||||
if (options.beautify) {
|
print(repeat_string(" ", half ? indentation - (options.indent_level >> 1) : indentation));
|
||||||
print(make_indent(half ? 0.5 : 0));
|
|
||||||
}
|
|
||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
var with_indent = options.beautify ? function(col, cont) {
|
var with_indent = options.beautify ? function(col, cont) {
|
||||||
@@ -575,9 +569,9 @@ function OutputStream(options) {
|
|||||||
get : get,
|
get : get,
|
||||||
toString : get,
|
toString : get,
|
||||||
indent : indent,
|
indent : indent,
|
||||||
indentation : function() { return indentation },
|
should_break : readonly ? noop : function() {
|
||||||
current_width : function() { return current_col - indentation },
|
return options.width && current_col - indentation >= options.width;
|
||||||
should_break : function() { return options.width && this.current_width() >= options.width },
|
},
|
||||||
has_parens : function() { return has_parens },
|
has_parens : function() { return has_parens },
|
||||||
newline : newline,
|
newline : newline,
|
||||||
print : print,
|
print : print,
|
||||||
|
|||||||
48
lib/utils.js
48
lib/utils.js
@@ -112,51 +112,29 @@ function return_this() { return this; }
|
|||||||
function return_null() { return null; }
|
function return_null() { return null; }
|
||||||
|
|
||||||
var List = (function() {
|
var List = (function() {
|
||||||
function List(a, f, backwards) {
|
function List(a, f) {
|
||||||
var ret = [], top = [], i;
|
var ret = [];
|
||||||
function doit() {
|
for (var i = 0; i < a.length; i++) {
|
||||||
var val = f(a[i], i);
|
var val = f(a[i], i);
|
||||||
var is_last = val instanceof Last;
|
if (val === skip) continue;
|
||||||
if (is_last) val = val.v;
|
|
||||||
if (val instanceof AtTop) {
|
|
||||||
val = val.v;
|
|
||||||
if (val instanceof Splice) {
|
if (val instanceof Splice) {
|
||||||
top.push.apply(top, backwards ? val.v.slice().reverse() : val.v);
|
ret.push.apply(ret, 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 {
|
} else {
|
||||||
ret.push(val);
|
ret.push(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return is_last;
|
return ret;
|
||||||
}
|
|
||||||
if (Array.isArray(a)) {
|
|
||||||
if (backwards) {
|
|
||||||
for (i = a.length; --i >= 0;) if (doit()) break;
|
|
||||||
ret.reverse();
|
|
||||||
top.reverse();
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < a.length; ++i) if (doit()) break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (i in a) if (HOP(a, i)) if (doit()) break;
|
|
||||||
}
|
|
||||||
return top.concat(ret);
|
|
||||||
}
|
}
|
||||||
List.is_op = function(val) {
|
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 = {};
|
var skip = List.skip = {};
|
||||||
function AtTop(val) { this.v = val; }
|
function Splice(val) {
|
||||||
function Splice(val) { this.v = val; }
|
this.v = val;
|
||||||
function Last(val) { this.v = val; }
|
}
|
||||||
return List;
|
return List;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user