Skip to content

Commit

Permalink
feat: serialize custom element component keys
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Aug 11, 2022
1 parent 11b96d3 commit 1c86a45
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/mdx/lib/plugin/recma-jsx-rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
toJsxIdOrMemberExpression
} from '../util/estree-util-to-id-or-member-expression.js'
import {toBinaryAddition} from '../util/estree-util-to-binary-addition.js'
import {toValidIdentifierName} from '../util/to-valid-identifier-name.js'

const own = {}.hasOwnProperty

Expand Down Expand Up @@ -188,20 +189,21 @@ export function recmaJsxRewrite(options = {}) {
// but not for `<h1>heading</h1>`.
} else {
const id = name.name
const validId = toValidIdentifierName(id)

if (!fnScope.tags.includes(id)) {
fnScope.tags.push(id)
}

node.openingElement.name = toJsxIdOrMemberExpression([
'_components',
id
validId
])

if (node.closingElement) {
node.closingElement.name = toJsxIdOrMemberExpression([
'_components',
id
validId
])
}
}
Expand Down Expand Up @@ -236,9 +238,7 @@ export function recmaJsxRewrite(options = {}) {
defaults.push({
type: 'Property',
kind: 'init',
key: isIdentifierName(name)
? {type: 'Identifier', name}
: {type: 'Literal', value: name},
key: {type: 'Identifier', name: toValidIdentifierName(name)},
value: {type: 'Literal', value: name},
method: false,
shorthand: false,
Expand Down

0 comments on commit 1c86a45

Please sign in to comment.