Skip to content

Commit

Permalink
refactor: [id, componentName]
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Aug 15, 2022
1 parent f7aea66 commit 55414b4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/mdx/lib/plugin/recma-jsx-rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,22 +358,19 @@ export function recmaJsxRewrite(options = {}) {
componentsInit = {type: 'Identifier', name: '_components'}
}

for (const [
_componentsId,
_componentName
] of idToInvalidComponentName) {
for (const [id, componentName] of idToInvalidComponentName) {
// For JSX IDs that can’t be represented as JavaScript IDs (as in,
// those with dashes, such as `custom-element`), generate a
// separate variable that is a valid JS ID (such as `_component0`),
// and takes it from components:
// `const _component0 = _components['custom-element']`
declarations.push({
type: 'VariableDeclarator',
id: {type: 'Identifier', name: _componentName},
id: {type: 'Identifier', name: componentName},
init: {
type: 'MemberExpression',
object: {type: 'Identifier', name: '_components'},
property: {type: 'Literal', value: _componentsId},
property: {type: 'Literal', value: id},
computed: true,
optional: false
}
Expand Down

0 comments on commit 55414b4

Please sign in to comment.