log filename in parse errors / compressor warnings
This commit is contained in:
@@ -92,9 +92,6 @@ var output = UglifyJS.OutputStream({
|
|||||||
});
|
});
|
||||||
|
|
||||||
files.forEach(function(file) {
|
files.forEach(function(file) {
|
||||||
if (ARGS.v) {
|
|
||||||
sys.error("Parsing " + file);
|
|
||||||
}
|
|
||||||
var code = read_whole_file(file);
|
var code = read_whole_file(file);
|
||||||
if (ARGS.p != null) {
|
if (ARGS.p != null) {
|
||||||
file = file.replace(/^\/+/, "").split(/\/+/).slice(ARGS.p).join("/");
|
file = file.replace(/^\/+/, "").split(/\/+/).slice(ARGS.p).join("/");
|
||||||
|
|||||||
@@ -437,10 +437,10 @@ function Compressor(options, false_by_default) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function extract_declarations_from_unreachable_code(compressor, stat, target) {
|
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){
|
stat.walk(new TreeWalker(function(node){
|
||||||
if (node instanceof AST_Definitions) {
|
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 = node.clone();
|
||||||
node.remove_initializers();
|
node.remove_initializers();
|
||||||
target.push(node);
|
target.push(node);
|
||||||
@@ -832,13 +832,14 @@ function Compressor(options, false_by_default) {
|
|||||||
if (sym.unreferenced()) {
|
if (sym.unreferenced()) {
|
||||||
var warn = {
|
var warn = {
|
||||||
name: sym.name,
|
name: sym.name,
|
||||||
|
file: sym.start.file,
|
||||||
line: sym.start.line,
|
line: sym.start.line,
|
||||||
col: sym.start.col
|
col: sym.start.col
|
||||||
};
|
};
|
||||||
if (def.value && def.value.has_side_effects()) {
|
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 {
|
} else {
|
||||||
compressor.warn("Dropping unreferenced variable {name} [{line},{col}]", warn);
|
compressor.warn("Dropping unreferenced variable {name} [{file}:{line},{col}]", warn);
|
||||||
a.splice(i, 1);
|
a.splice(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -910,7 +911,7 @@ function Compressor(options, false_by_default) {
|
|||||||
|
|
||||||
AST_SimpleStatement.DEFMETHOD("optimize", function(compressor){
|
AST_SimpleStatement.DEFMETHOD("optimize", function(compressor){
|
||||||
if (!this.body.has_side_effects()) {
|
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 make_node(AST_EmptyStatement, this);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@@ -1047,7 +1048,7 @@ function Compressor(options, false_by_default) {
|
|||||||
self.condition = cond[0];
|
self.condition = cond[0];
|
||||||
if (cond.length == 2) {
|
if (cond.length == 2) {
|
||||||
if (cond[1]) {
|
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")) {
|
if (compressor.option("dead_code")) {
|
||||||
var a = [];
|
var a = [];
|
||||||
if (self.alternative) {
|
if (self.alternative) {
|
||||||
@@ -1057,7 +1058,7 @@ function Compressor(options, false_by_default) {
|
|||||||
return make_node(AST_BlockStatement, self, { body: a });
|
return make_node(AST_BlockStatement, self, { body: a });
|
||||||
}
|
}
|
||||||
} else {
|
} 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")) {
|
if (compressor.option("dead_code")) {
|
||||||
var a = [];
|
var a = [];
|
||||||
extract_declarations_from_unreachable_code(compressor, self.body, 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 (compressor.option("unused_func")) {
|
||||||
if (this.name.unreferenced()
|
if (this.name.unreferenced()
|
||||||
&& !(this.parent_scope instanceof AST_Toplevel)) {
|
&& !(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,
|
name: this.name.name,
|
||||||
|
file: this.start.file,
|
||||||
line: this.start.line,
|
line: this.start.line,
|
||||||
col: this.start.col
|
col: this.start.col
|
||||||
});
|
});
|
||||||
@@ -1419,7 +1421,7 @@ function Compressor(options, false_by_default) {
|
|||||||
case "typeof":
|
case "typeof":
|
||||||
// typeof always returns a non-empty string, thus it's
|
// typeof always returns a non-empty string, thus it's
|
||||||
// always true in booleans
|
// 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);
|
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 ll = this.left.evaluate(compressor), left = ll[0];
|
||||||
var rr = this.right.evaluate(compressor), right = rr[0];
|
var rr = this.right.evaluate(compressor), right = rr[0];
|
||||||
if ((ll.length == 2 && !ll[1]) || (rr.length == 2 && !rr[1])) {
|
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);
|
return make_node(AST_False, this).optimize(compressor);
|
||||||
}
|
}
|
||||||
if (ll.length == 2 && ll[1]) {
|
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 ll = this.left.evaluate(compressor), left = ll[0];
|
||||||
var rr = this.right.evaluate(compressor), right = rr[0];
|
var rr = this.right.evaluate(compressor), right = rr[0];
|
||||||
if ((ll.length == 2 && ll[1]) || (rr.length == 2 && rr[1])) {
|
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);
|
return make_node(AST_True, this).optimize(compressor);
|
||||||
}
|
}
|
||||||
if (ll.length == 2 && !ll[1]) {
|
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];
|
var rr = this.right.evaluate(compressor), right = rr[0];
|
||||||
if ((ll.length == 2 && ll[0] instanceof AST_String && ll[1]) ||
|
if ((ll.length == 2 && ll[0] instanceof AST_String && ll[1]) ||
|
||||||
(rr.length == 2 && rr[0] instanceof AST_String && rr[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);
|
return make_node(AST_True, this).optimize(compressor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1529,9 +1531,10 @@ function Compressor(options, false_by_default) {
|
|||||||
var ll = self.left.evaluate(compressor);
|
var ll = self.left.evaluate(compressor);
|
||||||
var rr = self.right.evaluate(compressor);
|
var rr = self.right.evaluate(compressor);
|
||||||
if (ll.length == 2 && typeof ll[1] == "boolean") {
|
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,
|
operator : self.operator,
|
||||||
value : ll[1],
|
value : ll[1],
|
||||||
|
file : self.start.file,
|
||||||
line : self.start.line,
|
line : self.start.line,
|
||||||
col : self.start.col
|
col : self.start.col
|
||||||
});
|
});
|
||||||
@@ -1540,9 +1543,10 @@ function Compressor(options, false_by_default) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (rr.length == 2 && typeof rr[1] == "boolean") {
|
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,
|
operator : self.operator,
|
||||||
value : rr[1],
|
value : rr[1],
|
||||||
|
file : self.start.file,
|
||||||
line : self.start.line,
|
line : self.start.line,
|
||||||
col : self.start.col
|
col : self.start.col
|
||||||
});
|
});
|
||||||
@@ -1640,10 +1644,10 @@ function Compressor(options, false_by_default) {
|
|||||||
var cond = self.condition.evaluate(compressor);
|
var cond = self.condition.evaluate(compressor);
|
||||||
if (cond.length == 2) {
|
if (cond.length == 2) {
|
||||||
if (cond[1]) {
|
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;
|
return self.consequent;
|
||||||
} else {
|
} else {
|
||||||
compressor.warn("Condition always false [{line},{col}]", self.start);
|
compressor.warn("Condition always false [{file}:{line},{col}]", self.start);
|
||||||
return self.alternative;
|
return self.alternative;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
lib/parse.js
14
lib/parse.js
@@ -254,9 +254,13 @@ JS_Parse_Error.prototype.toString = function() {
|
|||||||
return this.message + " (line: " + this.line + ", col: " + this.col + ", pos: " + this.pos + ")" + "\n\n" + this.stack;
|
return this.message + " (line: " + this.line + ", col: " + this.col + ", pos: " + this.pos + ")" + "\n\n" + this.stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
function js_error(message, line, col, pos) {
|
function js_error(message, filename, line, col, pos) {
|
||||||
console.log("***", message);
|
AST_Node.warn("ERROR: {message} [{file}:{line},{col}]", {
|
||||||
console.log("*** LINE:", line, "COL:", col, "POS:", pos);
|
message: message,
|
||||||
|
file: filename,
|
||||||
|
line: line,
|
||||||
|
col: col
|
||||||
|
});
|
||||||
throw new JS_Parse_Error(message, line, col, pos);
|
throw new JS_Parse_Error(message, line, col, pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -270,6 +274,7 @@ function tokenizer($TEXT, filename) {
|
|||||||
|
|
||||||
var S = {
|
var S = {
|
||||||
text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, ''),
|
text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, ''),
|
||||||
|
filename : filename,
|
||||||
pos : 0,
|
pos : 0,
|
||||||
tokpos : 0,
|
tokpos : 0,
|
||||||
line : 0,
|
line : 0,
|
||||||
@@ -354,7 +359,7 @@ function tokenizer($TEXT, filename) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function parse_error(err) {
|
function parse_error(err) {
|
||||||
js_error(err, S.tokline, S.tokcol, S.tokpos);
|
js_error(err, filename, S.tokline, S.tokcol, S.tokpos);
|
||||||
};
|
};
|
||||||
|
|
||||||
function read_num(prefix) {
|
function read_num(prefix) {
|
||||||
@@ -718,6 +723,7 @@ function parse($TEXT, options) {
|
|||||||
function croak(msg, line, col, pos) {
|
function croak(msg, line, col, pos) {
|
||||||
var ctx = S.input.context();
|
var ctx = S.input.context();
|
||||||
js_error(msg,
|
js_error(msg,
|
||||||
|
ctx.filename,
|
||||||
line != null ? line : ctx.tokline,
|
line != null ? line : ctx.tokline,
|
||||||
col != null ? col : ctx.tokcol,
|
col != null ? col : ctx.tokcol,
|
||||||
pos != null ? pos : ctx.tokpos);
|
pos != null ? pos : ctx.tokpos);
|
||||||
|
|||||||
Reference in New Issue
Block a user