Add passes compress option. Fix duplicate compress warnings.
This commit is contained in:
@@ -75,18 +75,36 @@ function Compressor(options, false_by_default) {
|
||||
screw_ie8 : false,
|
||||
drop_console : false,
|
||||
angular : false,
|
||||
|
||||
warnings : true,
|
||||
global_defs : {}
|
||||
global_defs : {},
|
||||
passes : 1,
|
||||
}, true);
|
||||
this.warnings_produced = {};
|
||||
};
|
||||
|
||||
Compressor.prototype = new TreeTransformer;
|
||||
merge(Compressor.prototype, {
|
||||
option: function(key) { return this.options[key] },
|
||||
warn: function() {
|
||||
if (this.options.warnings)
|
||||
AST_Node.warn.apply(AST_Node, arguments);
|
||||
compress: function(node) {
|
||||
var passes = +this.options.passes || 1;
|
||||
for (var pass = 0; pass < passes && pass < 3; ++pass) {
|
||||
if (pass > 0) node.clear_opt_flags();
|
||||
node = node.transform(this);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
warn: function(text, props) {
|
||||
if (this.options.warnings) {
|
||||
// only emit unique warnings
|
||||
var message = string_template(text, props);
|
||||
if (!(message in this.warnings_produced)) {
|
||||
this.warnings_produced[message] = true;
|
||||
AST_Node.warn.apply(AST_Node, arguments);
|
||||
}
|
||||
}
|
||||
},
|
||||
clear_warnings: function() {
|
||||
this.warnings_produced = {};
|
||||
},
|
||||
before: function(node, descend, in_list) {
|
||||
if (node._squeezed) return node;
|
||||
@@ -129,6 +147,15 @@ merge(Compressor.prototype, {
|
||||
return this.print_to_string() == node.print_to_string();
|
||||
});
|
||||
|
||||
AST_Node.DEFMETHOD("clear_opt_flags", function(){
|
||||
this.walk(new TreeWalker(function(node){
|
||||
if (!(node instanceof AST_Directive || node instanceof AST_Constant)) {
|
||||
node._squeezed = false;
|
||||
node._optimized = false;
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
function make_node(ctor, orig, props) {
|
||||
if (!props) props = {};
|
||||
if (orig) {
|
||||
@@ -392,10 +419,7 @@ merge(Compressor.prototype, {
|
||||
var_defs_removed = true;
|
||||
}
|
||||
// Further optimize statement after substitution.
|
||||
stat.walk(new TreeWalker(function(node){
|
||||
delete node._squeezed;
|
||||
delete node._optimized;
|
||||
}));
|
||||
stat.clear_opt_flags();
|
||||
|
||||
compressor.warn("Replacing " + (is_constant ? "constant" : "variable") +
|
||||
" " + var_name + " [{file}:{line},{col}]", node.start);
|
||||
|
||||
Reference in New Issue
Block a user