@@ -77,35 +77,39 @@ export default babel => {
77
77
return {
78
78
inherits : syntaxJsx ,
79
79
visitor : {
80
- ExportDefaultDeclaration : {
81
- exit ( path ) {
82
- if ( ! t . isArrowFunctionExpression ( path . node . declaration ) || ! hasJSX ( t , path ) ) {
83
- return
84
- }
80
+ Program ( p ) {
81
+ p . traverse ( {
82
+ ExportDefaultDeclaration : {
83
+ exit ( path ) {
84
+ if ( ! t . isArrowFunctionExpression ( path . node . declaration ) || ! hasJSX ( t , path ) ) {
85
+ return
86
+ }
85
87
86
- convertFunctionalComponent ( t , path . get ( 'declaration' ) )
87
- } ,
88
- } ,
89
- VariableDeclaration : {
90
- exit ( path ) {
91
- if (
92
- path . node . declarations . length !== 1 ||
93
- ! t . isVariableDeclarator ( path . node . declarations [ 0 ] ) ||
94
- ! t . isArrowFunctionExpression ( path . node . declarations [ 0 ] . init )
95
- ) {
96
- return
97
- }
88
+ convertFunctionalComponent ( t , path . get ( 'declaration' ) )
89
+ } ,
90
+ } ,
91
+ VariableDeclaration : {
92
+ exit ( path ) {
93
+ if (
94
+ path . node . declarations . length !== 1 ||
95
+ ! t . isVariableDeclarator ( path . node . declarations [ 0 ] ) ||
96
+ ! t . isArrowFunctionExpression ( path . node . declarations [ 0 ] . init )
97
+ ) {
98
+ return
99
+ }
98
100
99
- const declarator = path . get ( 'declarations' ) [ 0 ]
101
+ const declarator = path . get ( 'declarations' ) [ 0 ]
100
102
101
- if ( ! isFunctionalComponentDeclarator ( t , declarator ) ) {
102
- return
103
- }
103
+ if ( ! isFunctionalComponentDeclarator ( t , declarator ) ) {
104
+ return
105
+ }
104
106
105
- const name = path . node . declarations [ 0 ] . id . name
106
- convertFunctionalComponent ( t , path . get ( 'declarations' ) [ 0 ] . get ( 'init' ) , name )
107
- } ,
108
- } ,
107
+ const name = path . node . declarations [ 0 ] . id . name
108
+ convertFunctionalComponent ( t , path . get ( 'declarations' ) [ 0 ] . get ( 'init' ) , name )
109
+ } ,
110
+ } ,
111
+ } )
112
+ }
109
113
} ,
110
114
}
111
115
}
0 commit comments