File tree 2 files changed +28
-6
lines changed
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 = {}) {
136
136
const fullId = ids . join ( '.' )
137
137
const id = name . name
138
138
139
+ const isInScope = inScope ( currentScope , id )
140
+
139
141
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
+ }
141
155
}
142
156
143
- if ( ! fnScope . objects . includes ( id ) && ! inScope ( currentScope , id ) ) {
157
+ if ( ! fnScope . objects . includes ( id ) && ! isInScope ) {
144
158
fnScope . objects . push ( id )
145
159
}
146
160
}
Original file line number Diff line number Diff line change @@ -504,7 +504,6 @@ test('compile', async () => {
504
504
)
505
505
}
506
506
507
- // TODO: this is incorrect behavior, will be fixed in GH-1986
508
507
try {
509
508
renderToStaticMarkup (
510
509
React . createElement (
@@ -521,23 +520,32 @@ test('compile', async () => {
521
520
)
522
521
}
523
522
524
- // TODO: this is incorrect behavior, will be fixed in GH-1986
525
523
try {
526
524
renderToStaticMarkup (
527
525
React . createElement (
528
- await run ( compileSync ( '<a render={(x ) => <x.y />} />' ) )
526
+ await run ( compileSync ( '<a render={() => <x.y />} />' ) )
529
527
)
530
528
)
531
529
assert . unreachable ( )
532
530
} catch ( /** @type {unknown } */ error ) {
533
531
const exception = /** @type {Error } */ ( error )
534
532
assert . match (
535
533
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 / ,
537
535
'should throw if a used member is not defined locally (JSX in a function)'
538
536
)
539
537
}
540
538
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
+
541
549
try {
542
550
renderToStaticMarkup (
543
551
React . createElement ( await run ( compileSync ( '<X />' , { development : true } ) ) )
You can’t perform that action at this time.
1 commit comments
vercel[bot] commentedon Mar 31, 2022
Successfully deployed to the following URLs: