1
1
const { elementType, getProp, getPropValue} = require ( 'jsx-ast-utils' )
2
2
3
- function getConfigurationDefaultIfExists ( settings , rawElement ) {
4
- // if a component configuration does not exists, return the raw element
5
- if ( ! settings ?. github ?. components ?. [ rawElement ] ) return rawElement
6
-
7
- const defaultComponent = settings . github . components [ rawElement ]
8
-
9
- // check if the default component is also defined in the configuration
10
- return defaultComponent ? getConfigurationDefaultIfExists ( settings , defaultComponent ) : defaultComponent
11
- }
12
-
13
3
/*
14
4
Allows custom component to be mapped to an element type.
15
5
When a default is set, all instances of the component will be mapped to the default.
@@ -24,7 +14,13 @@ function getElementType(context, node) {
24
14
const polymorphicPropName = settings ?. github ?. polymorphicPropName ?? 'as'
25
15
const rawElement = getPropValue ( getProp ( node . attributes , polymorphicPropName ) ) ?? elementType ( node )
26
16
27
- return getConfigurationDefaultIfExists ( settings , rawElement )
17
+ // if a component configuration does not exists, return the raw element
18
+ if ( ! settings ?. github ?. components ?. [ rawElement ] ) return rawElement
19
+
20
+ const defaultComponent = settings . github . components [ rawElement ]
21
+
22
+ // check if the default component is also defined in the configuration
23
+ return defaultComponent ? defaultComponent : defaultComponent
28
24
}
29
25
30
26
module . exports = { getElementType}
0 commit comments