@@ -90,6 +90,12 @@ function isModuleIdentifier(obj) {
9090 return obj . type && obj . type === 'Identifier' && obj . name === 'module' ;
9191}
9292
93+ function isFunctionLike ( node ) {
94+ if ( ! node ) return false ;
95+
96+ return node . type === 'FunctionExpression' || node . type === 'ArrowFunctionExpression' ;
97+ }
98+
9399// module.exports.foo
94100function isModuleExportsAttach ( node ) {
95101 if ( ! node . object || ! node . object . object || ! node . object . property ) return false ;
@@ -139,7 +145,7 @@ module.exports.isNamedForm = function(node) {
139145 return args && args . length === 3 &&
140146 ( args [ 0 ] . type === 'Literal' || args [ 0 ] . type === 'StringLiteral' ) &&
141147 args [ 1 ] . type === 'ArrayExpression' &&
142- args [ 2 ] . type === 'FunctionExpression' ;
148+ isFunctionLike ( args [ 2 ] ) ;
143149} ;
144150
145151// define([deps], func)
@@ -150,7 +156,7 @@ module.exports.isDependencyForm = function(node) {
150156
151157 return args && args . length === 2 &&
152158 args [ 0 ] . type === 'ArrayExpression' &&
153- args [ 1 ] . type === 'FunctionExpression' ;
159+ isFunctionLike ( args [ 1 ] ) ;
154160} ;
155161
156162// define(func(require))
@@ -162,7 +168,7 @@ module.exports.isFactoryForm = function(node) {
162168
163169 // Node should have a function whose first param is 'require'
164170 return args && args . length === 1 &&
165- args [ 0 ] . type === 'FunctionExpression' &&
171+ isFunctionLike ( args [ 0 ] ) &&
166172 firstParamNode && firstParamNode . type === 'Identifier' &&
167173 firstParamNode . name === 'require' ;
168174} ;
@@ -183,7 +189,7 @@ module.exports.isREMForm = function(node) {
183189 const args = node . arguments ;
184190 const params = args . length > 0 ? args [ 0 ] . params : null ;
185191
186- if ( ! args || args . length === 0 || args [ 0 ] . type !== 'FunctionExpression' || params . length !== 3 ) {
192+ if ( ! args || args . length === 0 || ! isFunctionLike ( args [ 0 ] ) || params . length !== 3 ) {
187193 return false ;
188194 }
189195
0 commit comments