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 30, 2022
1 parent 0df684b commit a7ab79f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 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
20 changes: 6 additions & 14 deletions packages/mdx/test/compile.js
Expand Up @@ -504,7 +504,6 @@ test('compile', async () => {
)
}

// TODO: this is incorrect behavior, will be fixed in GH-1986
try {
renderToStaticMarkup(
React.createElement(
Expand All @@ -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('<a render={(x) => <x.y />} />'))
)
)
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)'
)
}
),
'<a></a>',
'should render if a used member is defined locally (JSX in a function)'
)

try {
renderToStaticMarkup(
Expand Down

0 comments on commit a7ab79f

Please sign in to comment.