@@ -18,32 +18,30 @@ class Checker {
1818 node . arguments . every ( this . checkSafeExpression )
1919 ) ;
2020 }
21- if ( allowMethods ) {
22- if ( node . callee . type === 'MemberExpression' ) {
23- const object = node . callee . object ;
24- const property = node . callee . property as Identifier ;
25- // If we're only referring to identifiers, we don't need to check deeply.
26- if ( object . type === 'Identifier' && property . type === 'Identifier' ) {
27- return (
28- isMethodWhitelisted ( object . name , property . name ) &&
29- node . arguments . every ( this . checkSafeExpression )
30- ) ;
31- } else if (
32- ( object . type === 'NewExpression' ||
33- object . type === 'CallExpression' ) &&
34- object . callee . type === 'Identifier'
35- ) {
36- const callee = object . callee ;
37- return (
38- isMethodWhitelisted ( callee . name , property . name ) &&
39- node . arguments . every ( this . checkSafeExpression )
40- ) ;
41- } else {
42- return (
43- this . checkSafeExpression ( object ) &&
44- node . arguments . every ( this . checkSafeExpression )
45- ) ;
46- }
21+ if ( allowMethods && node . callee . type === 'MemberExpression' ) {
22+ const object = node . callee . object ;
23+ const property = node . callee . property as Identifier ;
24+ // If we're only referring to identifiers, we don't need to check deeply.
25+ if ( object . type === 'Identifier' && property . type === 'Identifier' ) {
26+ return (
27+ isMethodWhitelisted ( object . name , property . name ) &&
28+ node . arguments . every ( this . checkSafeExpression )
29+ ) ;
30+ } else if (
31+ ( object . type === 'NewExpression' ||
32+ object . type === 'CallExpression' ) &&
33+ object . callee . type === 'Identifier'
34+ ) {
35+ const callee = object . callee ;
36+ return (
37+ isMethodWhitelisted ( callee . name , property . name ) &&
38+ node . arguments . every ( this . checkSafeExpression )
39+ ) ;
40+ } else {
41+ return (
42+ this . checkSafeExpression ( object ) &&
43+ node . arguments . every ( this . checkSafeExpression )
44+ ) ;
4745 }
4846 }
4947 return false ;
@@ -106,11 +104,13 @@ class Checker {
106104}
107105
108106export const checkTree = ( node : Node , options : Options ) => {
109- if ( node . type === 'Program' ) {
110- if ( node . body . length === 1 && node . body [ 0 ] . type === 'ExpressionStatement' ) {
111- const checker = new Checker ( options ) ;
112- return checker . checkSafeExpression ( node . body [ 0 ] . expression ) ;
113- }
107+ if (
108+ node . type === 'Program' &&
109+ node . body . length === 1 &&
110+ node . body [ 0 ] . type === 'ExpressionStatement'
111+ ) {
112+ const checker = new Checker ( options ) ;
113+ return checker . checkSafeExpression ( node . body [ 0 ] . expression ) ;
114114 }
115115 return false ;
116116} ;
0 commit comments