minor
This commit is contained in:
@@ -166,6 +166,7 @@ function Compressor(options, false_by_default) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function extract_declarations_from_unreachable_code(compressor, stat, target) {
|
function extract_declarations_from_unreachable_code(compressor, stat, target) {
|
||||||
|
warn_dead_code(stat);
|
||||||
stat.walk(new TreeWalker(function(node){
|
stat.walk(new TreeWalker(function(node){
|
||||||
if (node instanceof AST_Definitions || node instanceof AST_Defun) {
|
if (node instanceof AST_Definitions || node instanceof AST_Defun) {
|
||||||
compressor.warn("Declarations in unreachable code! [{line},{col}]", node.start);
|
compressor.warn("Declarations in unreachable code! [{line},{col}]", node.start);
|
||||||
@@ -579,11 +580,12 @@ function Compressor(options, false_by_default) {
|
|||||||
});
|
});
|
||||||
} else if (self instanceof AST_While) {
|
} else if (self instanceof AST_While) {
|
||||||
if (compressor.option("dead_code")) {
|
if (compressor.option("dead_code")) {
|
||||||
warn_dead_code(self);
|
|
||||||
var a = [];
|
var a = [];
|
||||||
extract_declarations_from_unreachable_code(compressor, self.body, a);
|
extract_declarations_from_unreachable_code(compressor, self.body, a);
|
||||||
return make_node(AST_BlockStatement, self, { body: a });
|
return make_node(AST_BlockStatement, self, { body: a });
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return self.body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@@ -605,20 +607,20 @@ function Compressor(options, false_by_default) {
|
|||||||
this.condition = cond[0];
|
this.condition = cond[0];
|
||||||
}
|
}
|
||||||
if (!compressor.option("loops")) return this;
|
if (!compressor.option("loops")) return this;
|
||||||
if (this.condition) {
|
if (cond) {
|
||||||
var cond = this.condition.evaluate(compressor);
|
|
||||||
if (cond.length == 2 && !cond[1]) {
|
if (cond.length == 2 && !cond[1]) {
|
||||||
if (compressor.option("dead_code")) {
|
if (compressor.option("dead_code")) {
|
||||||
warn_dead_code(this.body);
|
|
||||||
var a = [];
|
var a = [];
|
||||||
if (this.init instanceof AST_Statement) a.push(this.init);
|
if (this.init instanceof AST_Statement) {
|
||||||
else if (this.init) a.push(make_node(AST_SimpleStatement, this.init, {
|
a.push(this.init);
|
||||||
|
}
|
||||||
|
else if (this.init) {
|
||||||
|
a.push(make_node(AST_SimpleStatement, this.init, {
|
||||||
body: this.init
|
body: this.init
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
extract_declarations_from_unreachable_code(compressor, this.body, a);
|
extract_declarations_from_unreachable_code(compressor, this.body, a);
|
||||||
return make_node(AST_BlockStatement, this, {
|
return make_node(AST_BlockStatement, this, { body: a });
|
||||||
body: a
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -675,7 +677,6 @@ function Compressor(options, false_by_default) {
|
|||||||
if (compressor.option("dead_code")) {
|
if (compressor.option("dead_code")) {
|
||||||
var a = [];
|
var a = [];
|
||||||
if (self.alternative) {
|
if (self.alternative) {
|
||||||
warn_dead_code(self.alternative);
|
|
||||||
extract_declarations_from_unreachable_code(compressor, self.alternative, a);
|
extract_declarations_from_unreachable_code(compressor, self.alternative, a);
|
||||||
}
|
}
|
||||||
a.push(self.body);
|
a.push(self.body);
|
||||||
@@ -684,7 +685,6 @@ function Compressor(options, false_by_default) {
|
|||||||
} else {
|
} else {
|
||||||
AST_Node.warn("Condition always false [{line},{col}]", self.condition.start);
|
AST_Node.warn("Condition always false [{line},{col}]", self.condition.start);
|
||||||
if (compressor.option("dead_code")) {
|
if (compressor.option("dead_code")) {
|
||||||
warn_dead_code(self.body);
|
|
||||||
var a = [];
|
var a = [];
|
||||||
extract_declarations_from_unreachable_code(compressor, self.body, a);
|
extract_declarations_from_unreachable_code(compressor, self.body, a);
|
||||||
if (self.alternative) a.push(self.alternative);
|
if (self.alternative) a.push(self.alternative);
|
||||||
|
|||||||
Reference in New Issue
Block a user