@@ -3,8 +3,11 @@ import type { Node, Program, VariableDeclaration } from "estree";
3
3
import { CONTINUE , EXIT , visit } from "estree-util-visit" ;
4
4
5
5
/**
6
- * It is a recma plugin which ensure getting React from argument[0]
7
- * It is a work around for the issue
6
+ *
7
+ * It is a recma plugin which ensure getting React from argument[0] in the compiled source
8
+ *
9
+ * It is a work around for the issue https://github.com/vercel/next.js/issues/76395
10
+ *
8
11
*/
9
12
const plugin : Plugin < void [ ] , Program > = ( ) => {
10
13
return ( tree : Node ) => {
@@ -32,18 +35,19 @@ const plugin: Plugin<void[], Program> = () => {
32
35
kind : "const" ,
33
36
} ;
34
37
35
- visit ( tree , ( node , _ , index ) => {
38
+ visit ( tree , ( node , _ , index , ancestors ) => {
36
39
if ( index === undefined ) return ;
37
40
38
- if ( node . type !== "VariableDeclaration" ) return CONTINUE ;
41
+ if ( node . type === "VariableDeclaration" ) {
42
+ const parent = ancestors [ 0 ] as Program ;
39
43
40
- if ( tree . type === "Program" ) {
41
- tree [ "body" ] . splice ( index , 0 , variableDeclaration ) ;
44
+ if ( "body" in parent ) {
45
+ parent [ "body" ] . splice ( index , 0 , variableDeclaration ) ;
42
46
43
- return EXIT ;
47
+ return EXIT ;
48
+ }
44
49
}
45
50
46
- /* istanbul ignore next */
47
51
return CONTINUE ;
48
52
} ) ;
49
53
} ;
0 commit comments