Skip to content

computed JSX member expression #1

Closed as not planned
Closed as not planned
@talatkuyuk

Description

@talatkuyuk

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 a recma plugin recma-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 when jsx: true in the mdx options. Since the recma-mdx-html-override makes the tag callable via <_components.custom-tag />, actually should be <_components["custom-tag"] /> instead.

Current solutions

Currently, the jsxMemberExpression is:

function jsxMemberExpression(node, state) {
  this[node.object.type](node.object, state)
  state.write('.')
  this[node.property.type](node.property, state)
}

Proposed solutions

I suppose we need just to extend the JSXMemberExpression adding a computed property. Then,

function jsxMemberExpression(node, state) {
  this[node.object.type](node.object, state)
  if (!node.computed) state.write('.')
  if (node.computed) state.write('[')
  this[node.property.type](node.property, state)
  if (node.computed) state.write(']')
}

My intention was to create a custom handler for that, but compile of @mdx-js/mdx doesn't except any handler /or handlers option to be passed into recma-stringfy hence to estree-util-to-js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    👎 phase/noPost cannot or will not be acted on🤷 no/invalidThis cannot be acted upon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions