1
1
/* eslint-disable node/no-extraneous-import */
2
2
/* eslint-disable node/no-unsupported-features/es-syntax */
3
3
import type { ExpressionKind , SpreadElementKind } from 'ast-types/gen/kinds' ;
4
- import type { JSCodeshift , ObjectExpression , ObjectProperty , Transform } from 'jscodeshift' ;
4
+ import type {
5
+ CallExpression ,
6
+ JSCodeshift ,
7
+ ObjectExpression ,
8
+ ObjectProperty ,
9
+ Transform ,
10
+ } from 'jscodeshift' ;
5
11
12
+ function creatorCall ( j : JSCodeshift , type : 'reducer' , reducer : ExpressionKind ) : CallExpression ;
13
+ // eslint-disable-next-line no-redeclare
14
+ function creatorCall (
15
+ j : JSCodeshift ,
16
+ type : 'preparedReducer' ,
17
+ prepare : ExpressionKind ,
18
+ reducer : ExpressionKind
19
+ ) : CallExpression ;
20
+ // eslint-disable-next-line no-redeclare
6
21
function creatorCall (
7
22
j : JSCodeshift ,
8
23
type : 'reducer' | 'preparedReducer' ,
9
- argumentsParam : Array < ExpressionKind | SpreadElementKind >
24
+ ... rest : Array < ExpressionKind | SpreadElementKind >
10
25
) {
11
- return j . callExpression (
12
- j . memberExpression ( j . identifier ( 'create' ) , j . identifier ( type ) ) ,
13
- argumentsParam
14
- ) ;
26
+ return j . callExpression ( j . memberExpression ( j . identifier ( 'create' ) , j . identifier ( type ) ) , rest ) ;
15
27
}
16
28
17
29
export function reducerPropsToBuilderExpression ( j : JSCodeshift , defNode : ObjectExpression ) {
@@ -23,7 +35,7 @@ export function reducerPropsToBuilderExpression(j: JSCodeshift, defNode: ObjectE
23
35
const { key, params, body } = property ;
24
36
finalProp = j . objectProperty (
25
37
key ,
26
- creatorCall ( j , 'reducer' , [ j . arrowFunctionExpression ( params , body ) ] )
38
+ creatorCall ( j , 'reducer' , j . arrowFunctionExpression ( params , body ) )
27
39
) ;
28
40
break ;
29
41
}
@@ -76,15 +88,17 @@ export function reducerPropsToBuilderExpression(j: JSCodeshift, defNode: ObjectE
76
88
if ( preparedReducerParams . prepare && preparedReducerParams . reducer ) {
77
89
finalProp = j . objectProperty (
78
90
key ,
79
- creatorCall ( j , 'preparedReducer' , [
91
+ creatorCall (
92
+ j ,
93
+ 'preparedReducer' ,
80
94
preparedReducerParams . prepare ,
81
- preparedReducerParams . reducer ,
82
- ] )
95
+ preparedReducerParams . reducer
96
+ )
83
97
) ;
84
98
} else if ( preparedReducerParams . reducer ) {
85
99
finalProp = j . objectProperty (
86
100
key ,
87
- creatorCall ( j , 'reducer' , [ preparedReducerParams . reducer ] )
101
+ creatorCall ( j , 'reducer' , preparedReducerParams . reducer )
88
102
) ;
89
103
}
90
104
break ;
@@ -95,7 +109,7 @@ export function reducerPropsToBuilderExpression(j: JSCodeshift, defNode: ObjectE
95
109
case 'MemberExpression' :
96
110
case 'CallExpression' : {
97
111
const { value } = property ;
98
- finalProp = j . objectProperty ( key , creatorCall ( j , 'reducer' , [ value ] ) ) ;
112
+ finalProp = j . objectProperty ( key , creatorCall ( j , 'reducer' , value ) ) ;
99
113
break ;
100
114
}
101
115
}
0 commit comments