File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ module . exports = function ( file , api ) {
2
+ const j = api . jscodeshift
3
+ const firstArgIsArray = p => {
4
+ const [ firstArg ] = p . value . arguments
5
+
6
+ if ( firstArg . type === 'ArrayExpression' ) return true
7
+ if ( firstArg . type !== 'Identifier' ) return false
8
+
9
+ const x = p . scope . lookup ( firstArg . name )
10
+ const decl = j ( x . getBindings ( ) [ firstArg . name ] [ 0 ] ) . closest (
11
+ j . VariableDeclaration
12
+ )
13
+
14
+ return (
15
+ Boolean ( decl . size ( ) ) &&
16
+ decl . nodes ( ) [ 0 ] . declarations [ 0 ] . init . type === 'ArrayExpression'
17
+ )
18
+ }
19
+ return j ( file . source )
20
+ . find ( j . CallExpression , {
21
+ callee : {
22
+ name : 'createSelector'
23
+ }
24
+ } )
25
+ . filter (
26
+ p =>
27
+ p . value . arguments . length > 2 ||
28
+ ( p . value . arguments . length === 2 && ! firstArgIsArray ( p ) )
29
+ )
30
+ . replaceWith ( p =>
31
+ j . callExpression ( j . identifier ( 'createSelector' ) , [
32
+ j . arrayExpression ( p . value . arguments . slice ( 0 , - 1 ) ) ,
33
+ p . value . arguments [ p . value . arguments . length - 1 ]
34
+ ] )
35
+ )
36
+ . toSource ( )
37
+ }
You can’t perform that action at this time.
0 commit comments