Open History to see the last commit
1module.exports = (file, api) => {
2 const jscodeshift = api.jscodeshift
3 const root = jscodeshift(file.source)
4β
5 const baseRenameLogic = (kind, from, to) => {
6 root
7 .find(kind, (node) => {
8 return (
9 node.computed === false &&
10 (node.key?.name === from || node.key?.value === from)
11 )
12 })
13 .replaceWith(({ node: mutableNode }) => {
14 if (mutableNode.key.name !== undefined) {
15 mutableNode.key.name = to
16 }
17β
18 if (mutableNode.key.value !== undefined) {
19 mutableNode.key.value = to
20 }
21β
22 return mutableNode
23 })
24 }
25β
26 const renameObjectProperty = (from, to) => {
27 baseRenameLogic(jscodeshift.ObjectProperty, from, to)
28 }
29β
30 const renameTypeScriptPropertySignature = (from, to) => {
31 baseRenameLogic(jscodeshift.TSPropertySignature, from, to)
32 }
33β
34 renameObjectProperty('cacheTime', 'gcTime')
35 renameObjectProperty('useErrorBoundary', 'throwOnError')
36β
37 renameTypeScriptPropertySignature('cacheTime', 'gcTime')
38 renameTypeScriptPropertySignature('useErrorBoundary', 'throwOnError')
39β
40 return root.toSource({ quote: 'single', lineTerminator: '\n' })
41}