Skip to content

Commit c75f1c2

Browse files
committed
only warn if error in try block
1 parent 0985b66 commit c75f1c2

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

lib/buildDeps.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,12 @@ function addModule(depTree, context, modu, options, reason, finalCallback) {
348348
// create or get the module for each require
349349
addModule(depTree, path.dirname(filename), moduleName, options, reason, function(err, moduleId) {
350350
if(err) {
351-
depTree.errors.push("Cannot find module '" + moduleName + "'\n " + err +
351+
var error = false;
352+
requires[moduleName].forEach(function(requireItem) {
353+
if(!requireItem.inTry)
354+
error = true;
355+
});
356+
(error ? depTree.errors : depTree.warnings).push("Cannot find module '" + moduleName + "'\n " + err +
352357
"\n @ " + filename + " (line " + requires[moduleName][0].line + ", column " + requires[moduleName][0].column + ")");
353358
} else {
354359
requires[moduleName].forEach(function(requireItem) {

lib/parse.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ function walkStatement(options, context, statement) {
4444
walkExpression(options, context, statement.argument);
4545
break;
4646
case "TryStatement":
47+
var oldInTry = context.inTry;
48+
context.inTry = true;
4749
walkStatement(options, context, statement.block);
50+
context.inTry = oldInTry;
4851
walkCatchClauses(options, context, statement.handlers);
4952
if(statement.finalizer)
5053
walkStatement(options, context, statement.finalizer);
@@ -81,12 +84,15 @@ function walkStatement(options, context, statement) {
8184
if(options.overwrites.hasOwnProperty(statement.name)) {
8285
context.overwrite.push(statement.name);
8386
}
87+
var oldInTry = context.inTry;
88+
context.inTry = false;
8489
var old = addOverwrites(options, context, statement.params);
8590
if(statement.body.type === "BlockStatement")
8691
walkStatement(options, context, statement.body);
8792
else
8893
walkExpression(options, context, statement.body);
8994
context.overwrite.length = old;
95+
context.inTry = oldInTry;
9096
break;
9197
case "VariableDeclaration":
9298
if(statement.declarations)
@@ -144,12 +150,15 @@ function walkExpression(options, context, expression) {
144150
});
145151
break;
146152
case "FunctionExpression":
153+
var oldInTry = context.inTry;
154+
context.inTry = false;
147155
var old = addOverwrites(options, context, expression.params);
148156
if(expression.body.type === "BlockStatement")
149157
walkStatement(options, context, expression.body);
150158
else
151159
walkExpression(options, context, expression.body);
152160
context.overwrite.length = old;
161+
context.inTry = oldInTry;
153162
break;
154163
case "SequenceExpression":
155164
if(expression.expressions)
@@ -198,7 +207,8 @@ function walkExpression(options, context, expression) {
198207
name: paramItem.value,
199208
expressionRange: paramItem.range,
200209
line: elements[idx].loc.start.line,
201-
column: elements[idx].loc.start.column
210+
column: elements[idx].loc.start.column,
211+
inTry: context.inTry
202212
});
203213
});
204214
} else if(param.code) {
@@ -233,7 +243,8 @@ function walkExpression(options, context, expression) {
233243
requireFunction: true,
234244
expressionRange: elements[idx].range,
235245
line: elements[idx].loc.start.line,
236-
column: elements[idx].loc.start.column
246+
column: elements[idx].loc.start.column,
247+
inTry: context.inTry
237248
});
238249
} else {
239250
// normal require
@@ -242,7 +253,8 @@ function walkExpression(options, context, expression) {
242253
name: param.value,
243254
expressionRange: elements[idx].range,
244255
line: elements[idx].loc.start.line,
245-
column: elements[idx].loc.start.column
256+
column: elements[idx].loc.start.column,
257+
inTry: context.inTry
246258
});
247259
}
248260
});
@@ -386,7 +398,8 @@ function walkExpression(options, context, expression) {
386398
name: paramItem.value,
387399
valueRange: paramItem.range,
388400
line: expression.loc.start.line,
389-
column: expression.loc.start.column
401+
column: expression.loc.start.column,
402+
inTry: context.inTry
390403
});
391404
});
392405
} else if(param.code) {
@@ -424,7 +437,8 @@ function walkExpression(options, context, expression) {
424437
idOnly: true,
425438
expressionRange: expression.arguments[0].range,
426439
line: expression.loc.start.line,
427-
column: expression.loc.start.column
440+
column: expression.loc.start.column,
441+
inTry: context.inTry
428442
});
429443
}
430444
noCallee = true;

0 commit comments

Comments
 (0)