@@ -214,28 +214,22 @@ module.exports = {
214
214
* @returns {boolean }
215
215
*/
216
216
function isRequireStatement ( node ) {
217
- if ( ! node ) return false ;
218
- switch ( node . type ) {
219
- case 'CallExpression' :
220
- if ( node . callee . type === 'Identifier' ) {
221
- return node . callee . name === 'require' ;
222
- }
223
- break ;
224
-
225
- case 'MemberExpression' :
226
- if ( node . object . type === 'Super' ) return false ;
227
- return isRequireStatement ( node . object ) ;
228
-
229
- default :
230
- break ;
217
+ if ( node . type === 'CallExpression' ) {
218
+ if ( node . callee . type === 'Identifier' ) {
219
+ return node . callee . name === 'require' ;
220
+ }
221
+ } else if ( node . type === 'MemberExpression' ) {
222
+ return isRequireStatement ( node . object ) ;
231
223
}
224
+
225
+ return false ;
232
226
}
233
227
234
228
/**
235
229
* Gets the name of the given JSX element. Supports nested
236
230
* JSXMemeberExpressions. ie `<Namesapce.Component.SubComponent />`
237
231
* @param {ASTNode } node
238
- * @returns {(string | undefined)[] }
232
+ * @returns {(string | undefined)[] | undefined }
239
233
*/
240
234
function getJSXElementName ( node ) {
241
235
if ( node . openingElement . name . type === 'JSXIdentifier' ) {
@@ -255,7 +249,6 @@ module.exports = {
255
249
}
256
250
257
251
current = current . object ;
258
- if ( ! current ) break ;
259
252
}
260
253
261
254
if ( current . type === 'JSXIdentifier' ) {
@@ -275,8 +268,6 @@ module.exports = {
275
268
}
276
269
}
277
270
}
278
-
279
- return [ undefined , undefined ] ;
280
271
}
281
272
282
273
/**
@@ -377,15 +368,18 @@ module.exports = {
377
368
for ( const ancestor of allAncestorElements ) {
378
369
const isClosestJSXAncestor = ancestor === allAncestorElements [ 0 ] ;
379
370
380
- const [ ancestorName , compoundAncestorName ] = getJSXElementName ( ancestor ) ;
381
- if ( ancestorName ) {
382
- const ancestorConfig = compoundAncestorName
383
- ? config . elementOverrides [ compoundAncestorName ] || config . elementOverrides [ ancestorName ]
384
- : config . elementOverrides [ ancestorName ] ;
385
-
386
- if ( ancestorConfig ) {
387
- if ( isClosestJSXAncestor || ancestorConfig . applyToNestedElements ) {
388
- return ancestorConfig ;
371
+ const elementNames = getJSXElementName ( ancestor ) ;
372
+ if ( elementNames && Array . isArray ( elementNames ) && elementNames . length === 2 ) {
373
+ const [ ancestorName , compoundAncestorName ] = elementNames ;
374
+ if ( ancestorName ) {
375
+ const ancestorConfig = compoundAncestorName
376
+ ? config . elementOverrides [ compoundAncestorName ] || config . elementOverrides [ ancestorName ]
377
+ : config . elementOverrides [ ancestorName ] ;
378
+
379
+ if ( ancestorConfig ) {
380
+ if ( isClosestJSXAncestor || ancestorConfig . applyToNestedElements ) {
381
+ return ancestorConfig ;
382
+ }
389
383
}
390
384
}
391
385
}
0 commit comments