Skip to content

Commit

Permalink
Don't add _missingMdxReference when an object is in scope
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-zhukov committed Mar 25, 2022
1 parent b8a76c9 commit 82afc90
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/mdx/lib/plugin/recma-jsx-rewrite.js
Expand Up @@ -136,12 +136,14 @@ export function recmaJsxRewrite(options = {}) {
const fullId = ids.join('.')
const id = name.name

if (!own.call(fnScope.references, fullId)) {
fnScope.references[fullId] = {node, component: true}
}
if (!inScope(currentScope, id)) {
if (!own.call(fnScope.references, fullId)) {
fnScope.references[fullId] = {node, component: true}
}

if (!fnScope.objects.includes(id) && !inScope(currentScope, id)) {
fnScope.objects.push(id)
if (!fnScope.objects.includes(id)) {
fnScope.objects.push(id)
}
}
}
// `<xml:thing>`.
Expand Down
36 changes: 36 additions & 0 deletions packages/mdx/test/compile.js
Expand Up @@ -791,6 +791,42 @@ test('jsx', async () => {
'should serialize fragments, namespaces, members'
)

assert.equal(
String(
compileSync(
[
'Hello, world!',
'{(() => {',
' const x = { y: () => <>x.y</> };',
' return <x.y />;',
'})()}'
].join('\n'),
{jsx: true}
)
),
[
'/*@jsxRuntime automatic @jsxImportSource react*/',
'function MDXContent(props = {}) {',
' const {wrapper: MDXLayout} = props.components || ({});',
' return MDXLayout ? <MDXLayout {...props}><_createMdxContent /></MDXLayout> : _createMdxContent();',
' function _createMdxContent() {',
' const _components = Object.assign({',
' p: "p"',
' }, props.components);',
' return <><_components.p>{"Hello, world!"}</_components.p>{"\\n"}{(() => {',
' const x = {',
' y: () => <>x.y</>',
' };',
' return <x.y />;',
' })()}</>;',
' }',
'}',
'export default MDXContent;',
''
].join('\n'),
'should serialize members, expressions'
)

assert.equal(
String(compileSync('<>a {/* 1 */} b</>', {jsx: true})),
[
Expand Down

0 comments on commit 82afc90

Please sign in to comment.