add --lint and display {file} in scope_warnings
This commit is contained in:
@@ -47,6 +47,7 @@ because of dead code removal or cascading statements into sequences.")
|
|||||||
.describe("wrap", "Embed everything in a big function, making the “exports” and “global” variables available. \
|
.describe("wrap", "Embed everything in a big function, making the “exports” and “global” variables available. \
|
||||||
You need to pass an argument to this option to specify the name that your module will take when included in, say, a browser.")
|
You need to pass an argument to this option to specify the name that your module will take when included in, say, a browser.")
|
||||||
.describe("export-all", "Only used when --wrap, this tells UglifyJS to add code to automatically export all globals.")
|
.describe("export-all", "Only used when --wrap, this tells UglifyJS to add code to automatically export all globals.")
|
||||||
|
.describe("lint", "Display some scope warnings")
|
||||||
.describe("v", "Verbose")
|
.describe("v", "Verbose")
|
||||||
|
|
||||||
.alias("p", "prefix")
|
.alias("p", "prefix")
|
||||||
@@ -72,6 +73,7 @@ You need to pass an argument to this option to specify the name that your module
|
|||||||
.boolean("stats")
|
.boolean("stats")
|
||||||
.boolean("acorn")
|
.boolean("acorn")
|
||||||
.boolean("spidermonkey")
|
.boolean("spidermonkey")
|
||||||
|
.boolean("lint")
|
||||||
|
|
||||||
.wrap(80)
|
.wrap(80)
|
||||||
|
|
||||||
@@ -229,11 +231,14 @@ if (ARGS.wrap) {
|
|||||||
TOPLEVEL = TOPLEVEL.wrap_commonjs(ARGS.wrap, ARGS.export_all);
|
TOPLEVEL = TOPLEVEL.wrap_commonjs(ARGS.wrap, ARGS.export_all);
|
||||||
}
|
}
|
||||||
|
|
||||||
var SCOPE_IS_NEEDED = COMPRESS || MANGLE;
|
var SCOPE_IS_NEEDED = COMPRESS || MANGLE || ARGS.lint;
|
||||||
|
|
||||||
if (SCOPE_IS_NEEDED) {
|
if (SCOPE_IS_NEEDED) {
|
||||||
time_it("scope", function(){
|
time_it("scope", function(){
|
||||||
TOPLEVEL.figure_out_scope();
|
TOPLEVEL.figure_out_scope();
|
||||||
|
if (ARGS.lint) {
|
||||||
|
TOPLEVEL.scope_warnings();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
18
lib/scope.js
18
lib/scope.js
@@ -500,8 +500,9 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
|
|||||||
// XXX: this also warns about JS standard names,
|
// XXX: this also warns about JS standard names,
|
||||||
// i.e. Object, Array, parseInt etc. Should add a list of
|
// i.e. Object, Array, parseInt etc. Should add a list of
|
||||||
// exceptions.
|
// exceptions.
|
||||||
AST_Node.warn("Undeclared symbol: {name} [{line},{col}]", {
|
AST_Node.warn("Undeclared symbol: {name} [{file}:{line},{col}]", {
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
file: node.start.file,
|
||||||
line: node.start.line,
|
line: node.start.line,
|
||||||
col: node.start.col
|
col: node.start.col
|
||||||
});
|
});
|
||||||
@@ -516,9 +517,10 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
|
|||||||
if (sym
|
if (sym
|
||||||
&& (sym.undeclared()
|
&& (sym.undeclared()
|
||||||
|| (sym.global() && sym.scope !== sym.definition().scope))) {
|
|| (sym.global() && sym.scope !== sym.definition().scope))) {
|
||||||
AST_Node.warn("{msg}: {name} [{line},{col}]", {
|
AST_Node.warn("{msg}: {name} [{file}:{line},{col}]", {
|
||||||
msg: sym.undeclared() ? "Accidental global?" : "Assignment to global",
|
msg: sym.undeclared() ? "Accidental global?" : "Assignment to global",
|
||||||
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
|
||||||
});
|
});
|
||||||
@@ -528,14 +530,15 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
|
|||||||
&& node instanceof AST_SymbolRef
|
&& node instanceof AST_SymbolRef
|
||||||
&& node.undeclared()
|
&& node.undeclared()
|
||||||
&& node.name == "eval") {
|
&& node.name == "eval") {
|
||||||
AST_Node.warn("Eval is used [{line},{col}]", node.start);
|
AST_Node.warn("Eval is used [{file}:{line},{col}]", node.start);
|
||||||
}
|
}
|
||||||
if (options.unreferenced
|
if (options.unreferenced
|
||||||
&& node instanceof AST_SymbolDeclaration
|
&& node instanceof AST_SymbolDeclaration
|
||||||
&& node.unreferenced()) {
|
&& node.unreferenced()) {
|
||||||
AST_Node.warn("{type} {name} is declared but not referenced [{line},{col}]", {
|
AST_Node.warn("{type} {name} is declared but not referenced [{file}:{line},{col}]", {
|
||||||
type: node instanceof AST_Label ? "Label" : "Symbol",
|
type: node instanceof AST_Label ? "Label" : "Symbol",
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
file: node.start.file,
|
||||||
line: node.start.line,
|
line: node.start.line,
|
||||||
col: node.start.col
|
col: node.start.col
|
||||||
});
|
});
|
||||||
@@ -543,8 +546,9 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
|
|||||||
if (options.func_arguments
|
if (options.func_arguments
|
||||||
&& node instanceof AST_Lambda
|
&& node instanceof AST_Lambda
|
||||||
&& node.uses_arguments) {
|
&& node.uses_arguments) {
|
||||||
AST_Node.warn("arguments used in function {name} [{line},{col}]", {
|
AST_Node.warn("arguments used in function {name} [{file}:{line},{col}]", {
|
||||||
name: node.name ? node.name.name : "anonymous",
|
name: node.name ? node.name.name : "anonymous",
|
||||||
|
file: node.start.file,
|
||||||
line: node.start.line,
|
line: node.start.line,
|
||||||
col: node.start.col
|
col: node.start.col
|
||||||
});
|
});
|
||||||
@@ -552,8 +556,10 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
|
|||||||
if (options.nested_defuns
|
if (options.nested_defuns
|
||||||
&& node instanceof AST_Defun
|
&& node instanceof AST_Defun
|
||||||
&& !(tw.parent() instanceof AST_Scope)) {
|
&& !(tw.parent() instanceof AST_Scope)) {
|
||||||
AST_Node.warn("Function {name} declared in nested statement [{line},{col}]", {
|
AST_Node.warn("Function {name} declared in nested statement \"{type}\" [{file}:{line},{col}]", {
|
||||||
name: node.name.name,
|
name: node.name.name,
|
||||||
|
type: tw.parent().TYPE,
|
||||||
|
file: node.start.file,
|
||||||
line: node.start.line,
|
line: node.start.line,
|
||||||
col: node.start.col
|
col: node.start.col
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user