@@ -26,20 +26,20 @@ export default function transformer(
26
26
call . value . callee . type === 'Identifier' &&
27
27
call . value . callee . name === importName ,
28
28
)
29
- // looking for calls with a custom equality function
30
29
// .filter(call => call.value.arguments.length === 2)
31
30
. forEach ( call => {
32
- const [ first , second ] = call . value . arguments ;
33
- if ( second == null ) {
31
+ const equalityFn = call . value . arguments [ 1 ] ;
32
+ // we don't need to do anything for calls without an equality fn
33
+ if ( equalityFn == null ) {
34
34
return ;
35
35
}
36
36
// We are going to wrap the existing customEqualityFn in our new one
37
37
// 4.0.0 EqualityFn → (a, b) => boolean [called for each argument]
38
38
// 5.0.0 EqualityFn → ([newArgs], [lastArgs]) => boolean [called once with all arguments]
39
39
if (
40
- second . type === 'FunctionExpression' ||
41
- second . type === 'ArrowFunctionExpression' ||
42
- second . type === 'Identifier'
40
+ equalityFn . type === 'FunctionExpression' ||
41
+ equalityFn . type === 'ArrowFunctionExpression' ||
42
+ equalityFn . type === 'Identifier'
43
43
) {
44
44
const customEqualityFn = j . arrowFunctionExpression (
45
45
[ j . identifier ( 'newArgs' ) , j . identifier ( 'lastArgs' ) ] ,
@@ -59,7 +59,7 @@ export default function transformer(
59
59
j . blockStatement ( [ j . returnStatement ( j . booleanLiteral ( false ) ) ] ) ,
60
60
) ,
61
61
j . variableDeclaration ( 'const' , [
62
- j . variableDeclarator ( j . identifier ( '__equalityFn' ) , second ) ,
62
+ j . variableDeclarator ( j . identifier ( '__equalityFn' ) , equalityFn ) ,
63
63
] ) ,
64
64
j . returnStatement (
65
65
j . callExpression (
@@ -86,7 +86,7 @@ export default function transformer(
86
86
] ) ,
87
87
) ;
88
88
89
- call . value . arguments = [ first , customEqualityFn ] ;
89
+ call . value . arguments [ 1 ] = customEqualityFn ;
90
90
return ;
91
91
}
92
92
} ) ;
0 commit comments