11import * as t from '@babel/types' ;
22
33export const component = ( componentName : string , contentStatement : t . Statement [ ] = [ ] ) => {
4- return t . exportNamedDeclaration (
5- t . variableDeclaration ( 'const' , [
6- t . variableDeclarator (
7- t . identifier ( componentName ) ,
8- t . arrowFunctionExpression (
9- [ t . identifier ( 'props' ) ] ,
10- t . blockStatement ( [
11- ...contentStatement ,
12- t . returnStatement (
13- t . jsxElement (
14- t . jsxOpeningElement ( t . jsxIdentifier ( 'div' ) , [ ] , false ) ,
15- t . jsxClosingElement ( t . jsxIdentifier ( 'div' ) ) ,
16- [ ] ,
17- null
18- )
19- ) ,
20- ] )
21- )
22- ) ,
23- ] )
24- ) ;
4+ return t . variableDeclaration ( 'const' , [
5+ t . variableDeclarator (
6+ t . identifier ( componentName ) ,
7+ t . arrowFunctionExpression (
8+ [ t . identifier ( 'props' ) ] ,
9+ t . blockStatement ( [
10+ ...contentStatement ,
11+ t . returnStatement (
12+ t . jsxElement (
13+ t . jsxOpeningElement ( t . jsxIdentifier ( 'div' ) , [ ] , false ) ,
14+ t . jsxClosingElement ( t . jsxIdentifier ( 'div' ) ) ,
15+ [ ]
16+ )
17+ ) ,
18+ ] )
19+ )
20+ ) ,
21+ ] ) ;
2522} ;
2623
2724export const test = ( componentName : string ) => {
@@ -30,94 +27,67 @@ export const test = (componentName: string) => {
3027 t . stringLiteral ( componentName ) ,
3128 t . arrowFunctionExpression (
3229 [ ] ,
33- t . blockStatement (
34- [
35- t . expressionStatement (
36- t . callExpression ( t . identifier ( 'it' ) , [
37- t . stringLiteral ( 'should render without crashing' ) ,
38- t . arrowFunctionExpression (
39- [ ] ,
40- t . blockStatement (
41- [
42- t . variableDeclaration ( 'const' , [
43- t . variableDeclarator (
44- t . identifier ( 'component' ) ,
45- t . callExpression ( t . identifier ( 'render' ) , [
46- t . jsxElement (
47- t . jsxOpeningElement ( t . jsxIdentifier ( componentName ) , [ ] , true ) ,
48- null ,
49- [ ] ,
50- false
51- ) ,
52- ] )
30+ t . blockStatement ( [
31+ t . expressionStatement (
32+ t . callExpression ( t . identifier ( 'it' ) , [
33+ t . stringLiteral ( 'should render without crashing' ) ,
34+ t . arrowFunctionExpression (
35+ [ ] ,
36+ t . blockStatement ( [
37+ t . variableDeclaration ( 'const' , [
38+ t . variableDeclarator (
39+ t . identifier ( 'component' ) ,
40+ t . callExpression ( t . identifier ( 'render' ) , [
41+ t . jsxElement (
42+ t . jsxOpeningElement ( t . jsxIdentifier ( componentName ) , [ ] , true ) ,
43+ null ,
44+ [ ]
5345 ) ,
54- ] ) ,
55- ] ,
56- [ ]
57- ) ,
58- false
59- ) ,
60- ] )
61- ) ,
62- ] ,
63- [ ]
64- ) ,
65- false
46+ ] )
47+ ) ,
48+ ] ) ,
49+ ] )
50+ ) ,
51+ ] )
52+ ) ,
53+ ] )
6654 ) ,
6755 ] )
6856 ) ;
6957} ;
7058
7159export const hoc = ( hocName : string , contentStatement : t . Statement [ ] = [ ] ) => {
72- return t . exportNamedDeclaration (
73- t . functionDeclaration (
74- t . identifier ( hocName ) ,
75- [ t . identifier ( 'WrappedComponent' ) ] ,
76- t . blockStatement (
77- [
78- t . returnStatement (
79- t . arrowFunctionExpression (
80- [ t . identifier ( 'props' ) ] ,
81- t . blockStatement (
82- [
83- ...contentStatement ,
84- t . returnStatement (
85- t . jsxElement (
86- t . jsxOpeningElement (
87- t . jsxIdentifier ( 'WrappedComponent' ) ,
88- [ t . jsxSpreadAttribute ( t . identifier ( 'props' ) ) ] ,
89- true
90- ) ,
91- null ,
92- [ ] ,
93- false
94- )
95- ) ,
96- ] ,
60+ return t . functionDeclaration (
61+ t . identifier ( hocName ) ,
62+ [ t . identifier ( 'WrappedComponent' ) ] ,
63+ t . blockStatement ( [
64+ t . returnStatement (
65+ t . arrowFunctionExpression (
66+ [ t . identifier ( 'props' ) ] ,
67+ t . blockStatement ( [
68+ ...contentStatement ,
69+ t . returnStatement (
70+ t . jsxElement (
71+ t . jsxOpeningElement (
72+ t . jsxIdentifier ( 'WrappedComponent' ) ,
73+ [ t . jsxSpreadAttribute ( t . identifier ( 'props' ) ) ] ,
74+ true
75+ ) ,
76+ null ,
9777 [ ]
98- ) ,
99- false
100- )
101- ) ,
102- ] ,
103- [ ]
78+ )
79+ ) ,
80+ ] )
81+ )
10482 ) ,
105- false ,
106- false
107- ) ,
108- [ ] ,
109- null
83+ ] )
11084 ) ;
11185} ;
11286
11387export const hook = ( hookName : string , contentStatement : t . Statement [ ] = [ ] ) => {
114- return t . exportNamedDeclaration (
115- t . functionDeclaration (
116- t . identifier ( hookName ) ,
117- [ ] ,
118- t . blockStatement ( [ ...contentStatement , t . returnStatement ( t . nullLiteral ( ) ) ] , [ ] ) ,
119- false ,
120- false
121- )
88+ return t . functionDeclaration (
89+ t . identifier ( hookName ) ,
90+ [ ] ,
91+ t . blockStatement ( [ ...contentStatement , t . returnStatement ( t . nullLiteral ( ) ) ] )
12292 ) ;
12393} ;
0 commit comments