log filename in parse errors / compressor warnings
This commit is contained in:
@@ -92,9 +92,6 @@ var output = UglifyJS.OutputStream({
|
||||
});
|
||||
|
||||
files.forEach(function(file) {
|
||||
if (ARGS.v) {
|
||||
sys.error("Parsing " + file);
|
||||
}
|
||||
var code = read_whole_file(file);
|
||||
if (ARGS.p != null) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
function js_error(message, line, col, pos) {
|
||||
console.log("***", message);
|
||||
console.log("*** LINE:", line, "COL:", col, "POS:", pos);
|
||||
function js_error(message, filename, line, col, pos) {
|
||||
AST_Node.warn("ERROR: {message} [{file}:{line},{col}]", {
|
||||
message: message,
|
||||
file: filename,
|
||||
line: line,
|
||||
col: col
|
||||
});
|
||||
throw new JS_Parse_Error(message, line, col, pos);
|
||||
};
|
||||
|
||||
@@ -270,6 +274,7 @@ function tokenizer($TEXT, filename) {
|
||||
|
||||
var S = {
|
||||
text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, ''),
|
||||
filename : filename,
|
||||
pos : 0,
|
||||
tokpos : 0,
|
||||
line : 0,
|
||||
@@ -354,7 +359,7 @@ function tokenizer($TEXT, filename) {
|
||||
};
|
||||
|
||||
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) {
|
||||
@@ -718,6 +723,7 @@ function parse($TEXT, options) {
|
||||
function croak(msg, line, col, pos) {
|
||||
var ctx = S.input.context();
|
||||
js_error(msg,
|
||||
ctx.filename,
|
||||
line != null ? line : ctx.tokline,
|
||||
col != null ? col : ctx.tokcol,
|
||||
pos != null ? pos : ctx.tokpos);
|
||||
|
||||
Reference in New Issue
Block a user