-
-
Notifications
You must be signed in to change notification settings - Fork 1
computed JSX member expression #1
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
Comments
We need to emit valid JS(X). I see your point, but it’s handled correctly by MDX. The following content: <a></a>
<a-b></a-b> compiles to this in MDX mode: /*@jsxRuntime automatic*/
/*@jsxImportSource react*/
function _createMdxContent(props) {
return <><a />{"\n"}<a-b /></>;
}
export default function MDXContent(props = {}) {
const {wrapper: MDXLayout} = props.components || ({});
return MDXLayout ? <MDXLayout {...props}><_createMdxContent {...props} /></MDXLayout> : _createMdxContent(props);
} or this in markdown mode (with /*@jsxRuntime automatic*/
/*@jsxImportSource react*/
function _createMdxContent(props) {
const _components = {
a: "a",
"a-b": "a-b",
p: "p",
...props.components
}, _component0 = _components["a-b"];
return <_components.p><_components.a />{"\n"}<_component0 /></_components.p>;
}
export default function MDXContent(props = {}) {
const {wrapper: MDXLayout} = props.components || ({});
return MDXLayout ? <MDXLayout {...props}><_createMdxContent {...props} /></MDXLayout> : _createMdxContent(props);
} I think this shows the solution you’re after. If you want to support a custom lower case JSX tag with a custom component, you need to introduce an intermediate variable. |
Thanks @remcohaszing, I would not test the plugin I've implemented intermediate variables for tag names that contain hypen in MDX mode and when jsx is true in new version of I've just realized also that html raw components are overridable by default in markdown mode via
Anyway, Nevertheless, the proposal for computed JSX member expression is still valid, it will ease the implementation of stringify and will extend the JSX specification.
This is also another issue for future as |
You can override HTML elements and JSX custom elements. In MDX you can write JSX, but not HTML. In markdown you cannot write JSX, but you can write HTML if you use import { Component } from 'module'
<Component /> But there is no markdown equivalent. Since the user has less control over HTML elements, whether it comes from markdown constructs or rehype plugins, it’s useful for users to customize what they look like. Note that this doesn’t just include Some users like to render MDX using methods where imports can’t be resolved. For those use cases it’s useful to allow injecting custom JSX components. But for lower case JSX this is still not relevant: the user can just write the name of their custom component, so they can use for example As the MDX team we need to make these kind of trade-offs and we can never please everyone. Perhaps I changed your opinion, but it’s only human to disagree anyway. I really appreciate that you plugin makes things possible in MDX that aren’t possible by default 😄 As for your proposal to change JSX syntax: Personally I don’t see the need. But if your proposal does get merged into ESTree and supported by other tools, MDX should support it too. |
Thank you for your appreciation, @remcohaszing. I am closing the issue, for now. |
Initial checklist
Problem
JsxMemberExpression
should support computed member expression (with bracket notation) in opening tag names in jsx.I opened an issue in facebook/jsx which explains the issue in specification.
I see that
recma
is super powerful more than I think. I've created arecma
pluginrecma-mdx-html-override
to allow specific html raw elements overridable via mdx components. The only remaining gap is for the tag names with hypen like<custom-tag />
in mdx whenjsx: true
in the mdx options. Since therecma-mdx-html-override
makes the tag callable via<_components.custom-tag />
, actually should be<_components["custom-tag"] />
instead.Current solutions
Currently, the
jsxMemberExpression
is:Proposed solutions
I suppose we need just to extend the
JSXMemberExpression
adding acomputed
property. Then,My intention was to create a custom handler for that, but
compile
of@mdx-js/mdx
doesn't except anyhandler
/orhandlers
option to be passed intorecma-stringfy
hence toestree-util-to-js
.The text was updated successfully, but these errors were encountered: