log filename in parse errors / compressor warnings

This commit is contained in:
Mihai Bazon
2012-09-21 14:38:52 +03:00
parent 5491e1d7b1
commit ec7f895b54
3 changed files with 30 additions and 23 deletions

View File

@@ -437,10 +437,10 @@ function Compressor(options, false_by_default) {
};
function extract_declarations_from_unreachable_code(compressor, stat, target) {
compressor.warn("Dropping unreachable code [{line},{col}]", stat.start);
compressor.warn("Dropping unreachable code [{file}:{line},{col}]", stat.start);
stat.walk(new TreeWalker(function(node){
if (node instanceof AST_Definitions) {
compressor.warn("Declarations in unreachable code! [{line},{col}]", node.start);
compressor.warn("Declarations in unreachable code! [{file}:{line},{col}]", node.start);
node = node.clone();
node.remove_initializers();
target.push(node);
@@ -832,13 +832,14 @@ function Compressor(options, false_by_default) {
if (sym.unreferenced()) {
var warn = {
name: sym.name,
file: sym.start.file,
line: sym.start.line,
col: sym.start.col
};
if (def.value && def.value.has_side_effects()) {
compressor.warn("Side effects in initialization of unreferenced variable {name} [{line},{col}]", warn);
compressor.warn("Side effects in initialization of unreferenced variable {name} [{file}:{line},{col}]", warn);
} else {
compressor.warn("Dropping unreferenced variable {name} [{line},{col}]", warn);
compressor.warn("Dropping unreferenced variable {name} [{file}:{line},{col}]", warn);
a.splice(i, 1);
}
}
@@ -910,7 +911,7 @@ function Compressor(options, false_by_default) {
AST_SimpleStatement.DEFMETHOD("optimize", function(compressor){
if (!this.body.has_side_effects()) {
compressor.warn("Dropping side-effect-free statement [{line},{col}]", this.start);
compressor.warn("Dropping side-effect-free statement [{file}:{line},{col}]", this.start);
return make_node(AST_EmptyStatement, this);
}
return this;
@@ -1047,7 +1048,7 @@ function Compressor(options, false_by_default) {
self.condition = cond[0];
if (cond.length == 2) {
if (cond[1]) {
compressor.warn("Condition always true [{line},{col}]", self.condition.start);
compressor.warn("Condition always true [{file}:{line},{col}]", self.condition.start);
if (compressor.option("dead_code")) {
var a = [];
if (self.alternative) {
@@ -1057,7 +1058,7 @@ function Compressor(options, false_by_default) {
return make_node(AST_BlockStatement, self, { body: a });
}
} else {
compressor.warn("Condition always false [{line},{col}]", self.condition.start);
compressor.warn("Condition always false [{file}:{line},{col}]", self.condition.start);
if (compressor.option("dead_code")) {
var a = [];
extract_declarations_from_unreachable_code(compressor, self.body, a);
@@ -1274,8 +1275,9 @@ function Compressor(options, false_by_default) {
if (compressor.option("unused_func")) {
if (this.name.unreferenced()
&& !(this.parent_scope instanceof AST_Toplevel)) {
compressor.warn("Dropping unused function {name} [{line},{col}]", {
compressor.warn("Dropping unused function {name} [{file}:{line},{col}]", {
name: this.name.name,
file: this.start.file,
line: this.start.line,
col: this.start.col
});
@@ -1419,7 +1421,7 @@ function Compressor(options, false_by_default) {
case "typeof":
// typeof always returns a non-empty string, thus it's
// always true in booleans
compressor.warn("Boolean expression always true [{line},{col}]", self.start);
compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start);
return make_node(AST_True, self).optimize(compressor);
}
}
@@ -1476,7 +1478,7 @@ function Compressor(options, false_by_default) {
var ll = this.left.evaluate(compressor), left = ll[0];
var rr = this.right.evaluate(compressor), right = rr[0];
if ((ll.length == 2 && !ll[1]) || (rr.length == 2 && !rr[1])) {
compressor.warn("Boolean && always false [{line},{col}]", this.start);
compressor.warn("Boolean && always false [{file}:{line},{col}]", this.start);
return make_node(AST_False, this).optimize(compressor);
}
if (ll.length == 2 && ll[1]) {
@@ -1490,7 +1492,7 @@ function Compressor(options, false_by_default) {
var ll = this.left.evaluate(compressor), left = ll[0];
var rr = this.right.evaluate(compressor), right = rr[0];
if ((ll.length == 2 && ll[1]) || (rr.length == 2 && rr[1])) {
compressor.warn("Boolean || always true [{line},{col}]", this.start);
compressor.warn("Boolean || always true [{file}:{line},{col}]", this.start);
return make_node(AST_True, this).optimize(compressor);
}
if (ll.length == 2 && !ll[1]) {
@@ -1505,7 +1507,7 @@ function Compressor(options, false_by_default) {
var rr = this.right.evaluate(compressor), right = rr[0];
if ((ll.length == 2 && ll[0] instanceof AST_String && ll[1]) ||
(rr.length == 2 && rr[0] instanceof AST_String && rr[1])) {
compressor.warn("+ in boolean context always true [{line},{col}]", this.start);
compressor.warn("+ in boolean context always true [{file}:{line},{col}]", this.start);
return make_node(AST_True, this).optimize(compressor);
}
break;
@@ -1529,9 +1531,10 @@ function Compressor(options, false_by_default) {
var ll = self.left.evaluate(compressor);
var rr = self.right.evaluate(compressor);
if (ll.length == 2 && typeof ll[1] == "boolean") {
compressor.warn("Non-strict equality against boolean: {operator} {value} [{line},{col}]", {
compressor.warn("Non-strict equality against boolean: {operator} {value} [{file}:{line},{col}]", {
operator : self.operator,
value : ll[1],
file : self.start.file,
line : self.start.line,
col : self.start.col
});
@@ -1540,9 +1543,10 @@ function Compressor(options, false_by_default) {
});
}
if (rr.length == 2 && typeof rr[1] == "boolean") {
compressor.warn("Non-strict equality against boolean {operator} {value} [{line},{col}]", {
compressor.warn("Non-strict equality against boolean {operator} {value} [{file}:{line},{col}]", {
operator : self.operator,
value : rr[1],
file : self.start.file,
line : self.start.line,
col : self.start.col
});
@@ -1640,10 +1644,10 @@ function Compressor(options, false_by_default) {
var cond = self.condition.evaluate(compressor);
if (cond.length == 2) {
if (cond[1]) {
compressor.warn("Condition always true [{line},{col}]", self.start);
compressor.warn("Condition always true [{file}:{line},{col}]", self.start);
return self.consequent;
} else {
compressor.warn("Condition always false [{line},{col}]", self.start);
compressor.warn("Condition always false [{file}:{line},{col}]", self.start);
return self.alternative;
}
}