-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle JSX member expressions #953
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export const Foo = () => ( | ||
export const Foobar = () => ( | ||
<div> | ||
<Button /> | ||
</div> | ||
) | ||
|
||
# Hello, world! | ||
|
||
<Foo /> | ||
<Foobar /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,21 @@ const MDXCreateElement = forwardRef((props, ref) => { | |
|
||
const components = useMDXComponents(propComponents) | ||
const type = mdxType | ||
|
||
const getMemberExpressionElement = () => { | ||
if (!type.includes('.')) { | ||
return | ||
} | ||
|
||
const [objName, propName] = type.split('.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this not handle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It won't. This is mostly a temporary monkey patch that will be better addressed in the v2 branch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we wanted this to be more fully supported we could copy/pasta lodash's |
||
const component = (components[objName] || {})[propName] | ||
return component | ||
} | ||
|
||
const Component = | ||
components[`${parentName}.${type}`] || | ||
components[type] || | ||
getMemberExpressionElement() || | ||
DEFAULTS[type] || | ||
originalType | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would also need to be checked if we swapped to something more full featured in the
getMemberExpression
call. Perhaps we should add a warning if there are too many nested objects.