@@ -38,24 +38,7 @@ protected boolean visitStatements(List<Statement> stmts) {
38
38
39
39
protected boolean visitStatement (Statement stmt ) {
40
40
if (stmt instanceof ExpressionStatement ) {
41
- Expression e = stripParens (((ExpressionStatement ) stmt ).getExpression ());
42
-
43
- // check whether `e` is an iife; if so, recursively check its body
44
-
45
- // strip off unary operators to handle `!function(){...}()`
46
- if (e instanceof UnaryExpression ) e = ((UnaryExpression ) e ).getArgument ();
47
-
48
- if (e instanceof CallExpression && ((CallExpression ) e ).getArguments ().isEmpty ()) {
49
- Expression callee = stripParens (((CallExpression ) e ).getCallee ());
50
- if (callee instanceof IFunction ) {
51
- Node body = ((IFunction ) callee ).getBody ();
52
- if (body instanceof BlockStatement )
53
- return visitStatements (((BlockStatement ) body ).getBody ());
54
- }
55
- }
56
-
57
- if (visitExpression (e )) return true ;
58
-
41
+ return visitExpression (((ExpressionStatement ) stmt ).getExpression ());
59
42
} else if (stmt instanceof VariableDeclaration ) {
60
43
for (VariableDeclarator decl : ((VariableDeclaration ) stmt ).getDeclarations ()) {
61
44
Expression init = stripParens (decl .getInit ());
@@ -77,17 +60,13 @@ protected boolean visitStatement(Statement stmt) {
77
60
return false ;
78
61
}
79
62
80
- private static Expression stripParens (Expression e ) {
81
- if (e instanceof ParenthesizedExpression )
82
- return stripParens (((ParenthesizedExpression ) e ).getExpression ());
83
- return e ;
84
- }
85
-
86
63
/**
87
64
* Recursively check {@code e} if it's a call or an assignment.
88
65
*/
89
66
protected boolean visitExpression (Expression e ) {
90
- if (e instanceof CallExpression ) {
67
+ if (e instanceof ParenthesizedExpression ) {
68
+ return visitExpression (((ParenthesizedExpression ) e ).getExpression ());
69
+ } else if (e instanceof CallExpression ) {
91
70
CallExpression call = (CallExpression ) e ;
92
71
Expression callee = call .getCallee ();
93
72
// recurse, to handle things like `foo()()`
@@ -102,6 +81,13 @@ protected boolean visitExpression(Expression e) {
102
81
if (!"=" .equals (assgn .getOperator ())) return false ;
103
82
104
83
return visitExpression (assgn .getRight ());
84
+ } else if (e instanceof UnaryExpression ) {
85
+ return visitExpression (((UnaryExpression ) e ).getArgument ());
86
+ } else if (e instanceof IFunction ) {
87
+ Node body = ((IFunction ) e ).getBody ();
88
+ if (body instanceof BlockStatement ) {
89
+ return visitStatement ((BlockStatement ) body );
90
+ }
105
91
}
106
92
return false ;
107
93
}
0 commit comments