11const { elementType, getProp, getPropValue} = require ( 'jsx-ast-utils' )
22
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-
133/*
144Allows custom component to be mapped to an element type.
155When a default is set, all instances of the component will be mapped to the default.
@@ -24,7 +14,13 @@ function getElementType(context, node) {
2414 const polymorphicPropName = settings ?. github ?. polymorphicPropName ?? 'as'
2515 const rawElement = getPropValue ( getProp ( node . attributes , polymorphicPropName ) ) ?? elementType ( node )
2616
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
2824}
2925
3026module . exports = { getElementType}
0 commit comments