Skip to content

Commit 0d8c49f

Browse files
committed
adding comment when unsupported case found
1 parent b181468 commit 0d8c49f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

community/memoize-one/src/5.0.0/transform.spec.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('memoize-one@5.0.0 transform', () => {
125125
);
126126
});
127127

128-
it('should wrap identifiers', () => {
128+
it('should wrap function identifiers', () => {
129129
const result = applyTransform(
130130
transformer,
131131
format(`
@@ -161,4 +161,34 @@ describe('memoize-one@5.0.0 transform', () => {
161161
`),
162162
);
163163
});
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+
});
164194
});

community/memoize-one/src/5.0.0/transform.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
hasImportDeclaration,
33
getDefaultImportSpecifierName,
4+
insertCommentToStartOfFile,
45
} from '@codeshift/utils';
56
import { API, FileInfo, Options } from 'jscodeshift';
67

@@ -26,7 +27,6 @@ export default function transformer(
2627
call.value.callee.type === 'Identifier' &&
2728
call.value.callee.name === importName,
2829
)
29-
// .filter(call => call.value.arguments.length === 2)
3030
.forEach(call => {
3131
const equalityFn = call.value.arguments[1];
3232
// we don't need to do anything for calls without an equality fn
@@ -92,6 +92,12 @@ export default function transformer(
9292
call.value.arguments[1] = customEqualityFn;
9393
return;
9494
}
95+
96+
insertCommentToStartOfFile(
97+
j,
98+
source,
99+
'Unable to migrate memoize-one custom equality function.\nExpected a function or an identifier',
100+
);
95101
});
96102

97103
return source.toSource(options.printOptions);

0 commit comments

Comments
 (0)