Skip to content

Commit 61a2d19

Browse files
1:1 mapping
1 parent de463b3 commit 61a2d19

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

lib/utils/get-element-type.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
const {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
/*
144
Allows custom component to be mapped to an element type.
155
When 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

3026
module.exports = {getElementType}

tests/utils/get-element-type.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,4 @@ describe('getElementType', function () {
7878
const node = mockJSXOpeningElement('Link', [mockJSXAttribute('as', 'Button')])
7979
expect(getElementType(setting, node)).to.equal('button')
8080
})
81-
82-
it('if rendered as another component check its default type', function () {
83-
const setting = mockSetting({
84-
Link: 'Button',
85-
Button: 'button',
86-
})
87-
88-
const node = mockJSXOpeningElement('Link')
89-
expect(getElementType(setting, node)).to.equal('button')
90-
})
9181
})

0 commit comments

Comments
 (0)