Skip to content

Commit 87a0e9f

Browse files
committed
Fix bug
1 parent ca7a3c3 commit 87a0e9f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lib/utils/get-element-type.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ function getElementType(context, node, lazyElementCheck = false) {
1616

1717
// check if the node contains a polymorphic prop
1818
const polymorphicPropName = settings?.github?.polymorphicPropName ?? 'as'
19-
const rawElement = getLiteralPropValue(getProp(node.attributes, polymorphicPropName)) ?? elementType(node)
2019

21-
// if a component configuration does not exists, return the raw element
22-
if (!settings?.github?.components?.[rawElement]) return rawElement
20+
const rawElement = elementType(node)
2321

24-
const defaultComponent = settings.github.components[rawElement]
25-
26-
// check if the default component is also defined in the configuration
27-
return defaultComponent ? defaultComponent : defaultComponent
22+
if (getProp(node.attributes, polymorphicPropName)) {
23+
return getLiteralPropValue(getProp(node.attributes, polymorphicPropName)) ?? rawElement
24+
} else if (settings?.github?.components?.[rawElement]) {
25+
return settings.github.components[rawElement]
26+
} else {
27+
return rawElement
28+
}
2829
}
2930

3031
module.exports = {getElementType}

tests/utils/get-element-type.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@ describe('getElementType', function () {
6464
expect(getElementType({}, node)).to.equal('Box')
6565
})
6666

67-
it('returns raw type when polymorphic prop is set to component, and not the mapped value', function () {
67+
it('returns raw type when polymorphic prop is set to com, and not the mapped value', function () {
6868
// <Box as={Link} />
6969
const setting = mockSetting({
7070
Box: 'div',
7171
})
7272

7373
// eslint-disable-next-line no-undef
74-
const node = mockJSXOpeningElement('Box', [mockJSXAttribute('as', Link)])
74+
const node = mockJSXOpeningElement('Box', [
75+
mockJSXConditionalAttribute('as', 'isNavigationOpen', 'generic', 'navigation'),
76+
])
7577
expect(getElementType(setting, node)).to.equal('Box')
7678
})
7779
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy