warn about unreferenced symbols

This commit is contained in:
Mihai Bazon
2012-08-21 11:53:19 +03:00
parent 99456c6156
commit 159333f4c5
2 changed files with 22 additions and 6 deletions

View File

@@ -76,7 +76,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
options = defaults(options, {
undeclared : false,
undeclared : false, // this makes a lot of noise
unreferenced : true,
assign_to_global : true,
eval : true
});
@@ -114,6 +115,16 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
&& node.name == "eval") {
AST_Node.warn("Eval is used [{line},{col}]", node.start);
}
if (options.unreferenced
&& node instanceof AST_SymbolDeclaration
&& node.unreferenced()) {
AST_Node.warn("{type} {name} is declared but not referenced [{line},{col}]", {
type: node instanceof AST_Label ? "Label" : "Symbol",
name: node.name,
line: node.start.line,
col: node.start.col
});
}
});
this.walk(tw);
});
@@ -207,6 +218,14 @@ AST_SymbolDeclaration.DEFMETHOD("mangle", function(){
}
});
AST_SymbolDeclaration.DEFMETHOD("unreferenced", function(){
return this.definition().references.length == 0;
});
AST_SymbolDeclaration.DEFMETHOD("definition", function(){
return this.uniq || this;
});
AST_Toplevel.DEFMETHOD("mangle_names", function(){
var tw = new TreeWalker(function(node){
// We only need to mangle declarations. Special logic wired