diff --git a/packages/mdx/lib/plugin/recma-jsx-rewrite.js b/packages/mdx/lib/plugin/recma-jsx-rewrite.js index 0858a0be5..1ff7ad0ed 100644 --- a/packages/mdx/lib/plugin/recma-jsx-rewrite.js +++ b/packages/mdx/lib/plugin/recma-jsx-rewrite.js @@ -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) + } } } // ``. diff --git a/packages/mdx/test/compile.js b/packages/mdx/test/compile.js index b98cf6c16..79ef013da 100644 --- a/packages/mdx/test/compile.js +++ b/packages/mdx/test/compile.js @@ -504,7 +504,6 @@ test('compile', async () => { ) } - // TODO: this is incorrect behavior, will be fixed in GH-1986 try { renderToStaticMarkup( React.createElement( @@ -516,27 +515,20 @@ test('compile', async () => { const exception = /** @type {Error} */ (error) assert.match( exception.message, - /Expected component `a.b` to be defined/, + /^Element type is invalid: .+ undefined/, 'should throw if a used member is not defined locally' ) } - // TODO: this is incorrect behavior, will be fixed in GH-1986 - try { + assert.equal( renderToStaticMarkup( React.createElement( await run(compileSync(' } />')) ) - ) - assert.unreachable() - } catch (/** @type {unknown} */ error) { - const exception = /** @type {Error} */ (error) - assert.match( - exception.message, - /x is not defined/, - 'should throw if a used member is not defined locally (JSX in a function)' - ) - } + ), + '', + 'should render if a used member is defined locally (JSX in a function)' + ) try { renderToStaticMarkup(