@@ -142,8 +142,13 @@ function normalizeConfig(config, handleElementOverrides) {
142
142
normalizedConfig . elementOverrides = fromEntries (
143
143
reduce (
144
144
iterFrom ( entries ( config . elementOverrides ) ) ,
145
- ( acc , [ key , value ] ) => {
145
+ ( acc , entry ) => {
146
+ const key = entry [ 0 ] ;
147
+ const value = entry [ 1 ] ;
148
+
149
+ if ( ! ( key && value ) ) return acc ;
146
150
if ( ! reOverridableElement . test ( key ) ) return acc ;
151
+
147
152
acc . push ( [
148
153
key ,
149
154
Object . assign ( normalizeConfig ( value , false ) , {
@@ -241,12 +246,15 @@ module.exports = {
241
246
* Gets the name of the given JSX element. Supports nested
242
247
* JSXMemeberExpressions. ie `<Namesapce.Component.SubComponent />`
243
248
* @param {ASTNode } node
244
- * @returns {( string | undefined)[] | undefined }
249
+ * @returns {{ name: string; compoundName: string | undefined } | undefined }
245
250
*/
246
251
function getJSXElementName ( node ) {
247
252
if ( node . openingElement . name . type === 'JSXIdentifier' ) {
248
253
const name = node . openingElement . name . name ;
249
- return [ renamedImportMap . get ( name ) || name , undefined ] ;
254
+ return {
255
+ name : renamedImportMap . get ( name ) || name ,
256
+ compoundName : undefined ,
257
+ }
250
258
}
251
259
252
260
/** @type {string[] } */
@@ -276,7 +284,10 @@ module.exports = {
276
284
277
285
const nameFragment = nameFragments [ nameFragments . length - 1 ] ;
278
286
if ( nameFragment ) {
279
- return [ nameFragment , nameFragments . join ( '.' ) ] ;
287
+ return {
288
+ name : nameFragment ,
289
+ compoundName : nameFragments . join ( '.' ) ,
290
+ }
280
291
}
281
292
}
282
293
}
@@ -377,16 +388,15 @@ module.exports = {
377
388
const allAncestorElements = getJSXElementAncestors ( node ) ;
378
389
if ( ! allAncestorElements . length ) return ;
379
390
380
- for ( const ancestor of allAncestorElements ) {
381
- const isClosestJSXAncestor = ancestor === allAncestorElements [ 0 ] ;
391
+ for ( const ancestorElement of allAncestorElements ) {
392
+ const isClosestJSXAncestor = ancestorElement === allAncestorElements [ 0 ] ;
382
393
383
- const elementNames = getJSXElementName ( ancestor ) ;
384
- if ( elementNames && Array . isArray ( elementNames ) && elementNames . length === 2 ) {
385
- const [ ancestorName , compoundAncestorName ] = elementNames ;
386
- if ( ancestorName ) {
387
- const ancestorConfig = compoundAncestorName
388
- ? config . elementOverrides [ compoundAncestorName ] || config . elementOverrides [ ancestorName ]
389
- : config . elementOverrides [ ancestorName ] ;
394
+ const ancestor = getJSXElementName ( ancestorElement ) ;
395
+ if ( ancestor ) {
396
+ if ( ancestor . name ) {
397
+ const ancestorConfig = ancestor . compoundName
398
+ ? config . elementOverrides [ ancestor . compoundName ] || config . elementOverrides [ ancestor . name ]
399
+ : config . elementOverrides [ ancestor . name ] ;
390
400
391
401
if ( ancestorConfig ) {
392
402
if ( isClosestJSXAncestor || ancestorConfig . applyToNestedElements ) {
0 commit comments