improve warnings (#4247)

closes #4244
This commit is contained in:
Alex Lam S.L
2020-10-27 09:39:33 +00:00
committed by GitHub
parent 607f87c5cd
commit 79e5c3f564
9 changed files with 64 additions and 63 deletions

View File

@@ -192,7 +192,11 @@ merge(Compressor.prototype, {
node.walk(new TreeWalker(function() {
count++;
}));
AST_Node.info("pass " + pass + ": last_count: " + min_count + ", count: " + count);
AST_Node.info("pass {pass}: last_count: {min_count}, count: {count}", {
pass: pass,
min_count: min_count,
count: count,
});
if (count < min_count) {
min_count = count;
stopping = false;
@@ -1340,11 +1344,11 @@ merge(Compressor.prototype, {
replaced++;
}
CHANGED = abort = true;
AST_Node.info("Collapsing {name} [{file}:{line},{col}]", {
name: node.print_to_string(),
AST_Node.info("Collapsing {node} [{file}:{line},{col}]", {
node: node,
file: node.start.file,
line: node.start.line,
col: node.start.col
col: node.start.col,
});
if (candidate instanceof AST_UnaryPostfix) {
if (lhs instanceof AST_SymbolRef) lhs.definition().fixed = false;
@@ -2799,14 +2803,15 @@ merge(Compressor.prototype, {
}
function extract_declarations_from_unreachable_code(compressor, stat, target) {
if (!(stat instanceof AST_Defun)) {
if (!(stat instanceof AST_Definitions || stat instanceof AST_Defun)) {
AST_Node.warn("Dropping unreachable code [{file}:{line},{col}]", stat.start);
}
var block;
stat.walk(new TreeWalker(function(node, descend) {
if (node instanceof AST_Definitions) {
AST_Node.warn("Declarations in unreachable code! [{file}:{line},{col}]", node.start);
node.remove_initializers(compressor);
if (node.remove_initializers(compressor)) {
AST_Node.warn("Dropping initialization in unreachable code [{file}:{line},{col}]", node.start);
}
push(node);
return true;
}
@@ -3273,7 +3278,12 @@ merge(Compressor.prototype, {
}
function warn(node) {
AST_Node.warn("global_defs " + node.print_to_string() + " redefined [{file}:{line},{col}]", node.start);
AST_Node.warn("global_defs {node} redefined [{file}:{line},{col}]", {
node: node,
file: node.start.file,
line: node.start.line,
col: node.start.col,
});
}
AST_Toplevel.DEFMETHOD("resolve_defines", function(compressor) {
@@ -3878,10 +3888,10 @@ merge(Compressor.prototype, {
return val[key].apply(val, args);
} catch (ex) {
AST_Node.warn("Error evaluating {code} [{file}:{line},{col}]", {
code: this.print_to_string(),
code: this,
file: this.start.file,
line: this.start.line,
col: this.start.col
col: this.start.col,
});
} finally {
if (val instanceof RegExp) val.lastIndex = 0;
@@ -4992,7 +5002,7 @@ merge(Compressor.prototype, {
var old_def, var_defs = var_defs_by_id.get(sym.id);
if (!def.value) {
if (var_defs.length > 1) {
AST_Node.warn("Dropping duplicated declaration of variable {name} [{file}:{line},{col}]", template(def.name));
AST_Node.info("Dropping declaration of variable {name} [{file}:{line},{col}]", template(def.name));
remove(var_defs, def);
sym.eliminated++;
} else {
@@ -5226,7 +5236,7 @@ merge(Compressor.prototype, {
name: sym.name,
file: sym.start.file,
line: sym.start.line,
col : sym.start.col
col : sym.start.col,
};
}
@@ -6662,19 +6672,21 @@ merge(Compressor.prototype, {
this.definitions.forEach(function(def) {
def.value = make_node(AST_Undefined, def).optimize(compressor);
});
return true;
});
AST_Let.DEFMETHOD("remove_initializers", function() {
function remove_initializers() {
var CHANGED = false;
this.definitions.forEach(function(def) {
if (!def.value) return;
def.value = null;
CHANGED = true;
});
});
return CHANGED;
}
AST_Var.DEFMETHOD("remove_initializers", function() {
this.definitions.forEach(function(def) {
def.value = null;
});
});
AST_Let.DEFMETHOD("remove_initializers", remove_initializers);
AST_Var.DEFMETHOD("remove_initializers", remove_initializers);
AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
var reduce_vars = compressor.option("reduce_vars");
@@ -6827,7 +6839,7 @@ merge(Compressor.prototype, {
length: length,
file: self.start.file,
line: self.start.line,
col: self.start.col
col: self.start.col,
});
break;
}
@@ -6884,10 +6896,10 @@ merge(Compressor.prototype, {
}));
} catch (ex) {
AST_Node.warn("Error converting {expr} [{file}:{line},{col}]", {
expr: self.print_to_string(),
expr: self,
file: self.start.file,
line: self.start.line,
col: self.start.col
col: self.start.col,
});
}
}
@@ -9302,7 +9314,7 @@ merge(Compressor.prototype, {
prop: self.property,
file: self.start.file,
line: self.start.line,
col: self.start.col
col: self.start.col,
});
}
var parent = compressor.parent();