File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ describe('memoize-one@5.0.0 transform', () => {
125
125
) ;
126
126
} ) ;
127
127
128
- it ( 'should wrap identifiers' , ( ) => {
128
+ it ( 'should wrap function identifiers' , ( ) => {
129
129
const result = applyTransform (
130
130
transformer ,
131
131
format ( `
@@ -161,4 +161,34 @@ describe('memoize-one@5.0.0 transform', () => {
161
161
` ) ,
162
162
) ;
163
163
} ) ;
164
+
165
+ it ( 'should add a comment when an unsupported equality fn is encountered' , ( ) => {
166
+ const result = applyTransform (
167
+ transformer ,
168
+ format ( `
169
+ import memoize from 'memoize-one';
170
+
171
+ function add(a: number, b: number) {
172
+ return a + b;
173
+ }
174
+
175
+ const memoized = memoize(add, {});
176
+ ` ) ,
177
+ { parser : 'tsx' } ,
178
+ ) ;
179
+
180
+ expect ( result ) . toEqual (
181
+ format ( `
182
+ /* TODO: (@codeshift) Unable to migrate memoize-one custom equality function.
183
+ Expected a function or an identifier */
184
+ import memoize from 'memoize-one';
185
+
186
+ function add(a: number, b: number) {
187
+ return a + b;
188
+ }
189
+
190
+ const memoized = memoize(add, {});
191
+ ` ) ,
192
+ ) ;
193
+ } ) ;
164
194
} ) ;
Original file line number Diff line number Diff line change 1
1
import {
2
2
hasImportDeclaration ,
3
3
getDefaultImportSpecifierName ,
4
+ insertCommentToStartOfFile ,
4
5
} from '@codeshift/utils' ;
5
6
import { API , FileInfo , Options } from 'jscodeshift' ;
6
7
@@ -26,7 +27,6 @@ export default function transformer(
26
27
call . value . callee . type === 'Identifier' &&
27
28
call . value . callee . name === importName ,
28
29
)
29
- // .filter(call => call.value.arguments.length === 2)
30
30
. forEach ( call => {
31
31
const equalityFn = call . value . arguments [ 1 ] ;
32
32
// we don't need to do anything for calls without an equality fn
@@ -92,6 +92,12 @@ export default function transformer(
92
92
call . value . arguments [ 1 ] = customEqualityFn ;
93
93
return ;
94
94
}
95
+
96
+ insertCommentToStartOfFile (
97
+ j ,
98
+ source ,
99
+ 'Unable to migrate memoize-one custom equality function.\nExpected a function or an identifier' ,
100
+ ) ;
95
101
} ) ;
96
102
97
103
return source . toSource ( options . printOptions ) ;
You can’t perform that action at this time.
0 commit comments