File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed
Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -136,11 +136,25 @@ export function recmaJsxRewrite(options = {}) {
136136 const fullId = ids . join ( '.' )
137137 const id = name . name
138138
139+ const isInScope = inScope ( currentScope , id )
140+
139141 if ( ! own . call ( fnScope . references , fullId ) ) {
140- fnScope . references [ fullId ] = { node, component : true }
142+ const parentScope = /** @type {Scope|null } */ (
143+ currentScope . parent
144+ )
145+ if (
146+ ! isInScope ||
147+ // If the parent scope is `_createMdxContent`, then this
148+ // references a component we can add a check statement for.
149+ ( parentScope &&
150+ parentScope . node . type === 'FunctionDeclaration' &&
151+ isNamedFunction ( parentScope . node , '_createMdxContent' ) )
152+ ) {
153+ fnScope . references [ fullId ] = { node, component : true }
154+ }
141155 }
142156
143- if ( ! fnScope . objects . includes ( id ) && ! inScope ( currentScope , id ) ) {
157+ if ( ! fnScope . objects . includes ( id ) && ! isInScope ) {
144158 fnScope . objects . push ( id )
145159 }
146160 }
Original file line number Diff line number Diff line change @@ -504,7 +504,6 @@ test('compile', async () => {
504504 )
505505 }
506506
507- // TODO: this is incorrect behavior, will be fixed in GH-1986
508507 try {
509508 renderToStaticMarkup (
510509 React . createElement (
@@ -521,23 +520,32 @@ test('compile', async () => {
521520 )
522521 }
523522
524- // TODO: this is incorrect behavior, will be fixed in GH-1986
525523 try {
526524 renderToStaticMarkup (
527525 React . createElement (
528- await run ( compileSync ( '<a render={(x ) => <x.y />} />' ) )
526+ await run ( compileSync ( '<a render={() => <x.y />} />' ) )
529527 )
530528 )
531529 assert . unreachable ( )
532530 } catch ( /** @type {unknown } */ error ) {
533531 const exception = /** @type {Error } */ ( error )
534532 assert . match (
535533 exception . message ,
536- / x i s n o t d e f i n e d / ,
534+ / E x p e c t e d o b j e c t ` x ` t o b e d e f i n e d / ,
537535 'should throw if a used member is not defined locally (JSX in a function)'
538536 )
539537 }
540538
539+ assert . equal (
540+ renderToStaticMarkup (
541+ React . createElement (
542+ await run ( compileSync ( '<a render={(x) => <x.y />} />' ) )
543+ )
544+ ) ,
545+ '<a></a>' ,
546+ 'should render if a used member is defined locally (JSX in a function)'
547+ )
548+
541549 try {
542550 renderToStaticMarkup (
543551 React . createElement ( await run ( compileSync ( '<X />' , { development : true } ) ) )
You can’t perform that action at this time.
0 commit comments