flow-upgrade 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/Styled.js +0 -2
- package/dist/Types.js +1 -8
- package/dist/bin/runSpecificCodemod.js +21 -38
- package/dist/bin/upgrade.js +8 -15
- package/dist/codemodUtils/getClassMemberName.js +1 -8
- package/dist/codemodUtils/replaceMethodWithArrowProp.js +6 -14
- package/dist/codemods/collapseObjectInitialization.js +6 -19
- package/dist/codemods/convertImplicitInexactObjectTypes.js +3 -13
- package/dist/codemods/convertLegacyUtilityTypes.js +69 -0
- package/dist/codemods/convertShapeToPartial.js +3 -13
- package/dist/codemods/eliminateAbstractComponent.js +72 -0
- package/dist/codemods/removeAnnotationsInDestructuring.js +3 -13
- package/dist/codemods/removeDuplicateClassProperties.js +12 -29
- package/dist/codemods/removeExplicitlyExactObjectTypeSyntax.js +3 -13
- package/dist/codemods/renamePartial.js +3 -13
- package/dist/codemods/replaceReactDollarUtilityTypes.js +8 -21
- package/dist/codemods/replaceTemporaryTypes.js +9 -21
- package/dist/codemods/typeCastToAsExpression.js +5 -15
- package/dist/codemods/typeParameterBoundExactEmptyObjectToInexact.js +5 -16
- package/dist/findFlowFiles.js +15 -32
- package/dist/runCodemods.js +14 -17
- package/dist/upgrade.js +30 -48
- package/dist/upgrades/0.170.0/index.js +4 -15
- package/dist/upgrades/0.176.0/index.js +4 -15
- package/dist/upgrades/0.201.0/index.js +4 -15
- package/dist/upgrades/0.84.0/index.js +4 -15
- package/dist/upgrades/index.js +5 -19
- package/dist/utils/redirectConsole.js +3 -16
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -105,3 +105,24 @@ Converts:
|
|
|
105
105
|
- `$TEMPORARY$array<T>` to `$ReadOnlyArray<T>`
|
|
106
106
|
- `$TEMPORARY$number<42>` annotations to `number`
|
|
107
107
|
- `$TEMPORARY$string<"foo">` annotations to `string`
|
|
108
|
+
|
|
109
|
+
### Replace `React.AbstractComponent<...>` types
|
|
110
|
+
Converts:
|
|
111
|
+
|
|
112
|
+
- `React.AbstractComponent<Props>` to `React.ComponentType<Props>`
|
|
113
|
+
- `React.ElementConfig<React.AbstractComponent<Props, Instance>>` to `Props`
|
|
114
|
+
- `React.ElementRef<React.AbstractComponent<Props, Instance>>` to `Instance`
|
|
115
|
+
- `React.ElementRef<React.AbstractComponent<Props>` to `mixed`
|
|
116
|
+
|
|
117
|
+
### Convert legacy Flow utility types to modern equivalents
|
|
118
|
+
Converts legacy Flow utility types to TypeScript-compatible equivalents:
|
|
119
|
+
- `$NonMaybeType<T>` to `NonNullable<T>`
|
|
120
|
+
- `$ReadOnly<T>` to `Readonly<T>`
|
|
121
|
+
- `$ReadOnlyArray<T>` to `ReadonlyArray<T>`
|
|
122
|
+
- `$ReadOnlyMap<K, V>` to `ReadonlyMap<K, V>`
|
|
123
|
+
- `$ReadOnlySet<T>` to `ReadonlySet<T>`
|
|
124
|
+
- `$Keys<T>` to `keyof T`
|
|
125
|
+
- `$Values<T>` to `Values<T>`
|
|
126
|
+
- `mixed` to `unknown`
|
|
127
|
+
|
|
128
|
+
Run with `yarn run flow-codemod convertLegacyUtilityTypes`.
|
package/dist/Styled.js
CHANGED
package/dist/Types.js
CHANGED
|
@@ -1,36 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
|
-
var _findFlowFiles = require("../findFlowFiles");
|
|
15
|
-
|
|
16
|
-
var _runCodemods = _interopRequireDefault(require("../runCodemods"));
|
|
17
|
-
|
|
18
|
-
var _Styled = _interopRequireDefault(require("../Styled"));
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
-
|
|
24
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
-
|
|
26
|
-
const CODEMOD_DIR = _path.default.resolve(__dirname, '..', 'codemods');
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import yargsImport from 'yargs/yargs';
|
|
5
|
+
import upgrade from '../upgrade';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { findFlowFilesWithSpinner } from '../findFlowFiles';
|
|
8
|
+
import runCodemods from '../runCodemods';
|
|
9
|
+
import Styled from '../Styled';
|
|
10
|
+
const CODEMOD_DIR = path.resolve(__dirname, '..', 'codemods');
|
|
27
11
|
|
|
28
12
|
async function main(args) {
|
|
29
|
-
const codemodNames =
|
|
13
|
+
const codemodNames = fs.readdirSync(CODEMOD_DIR, {
|
|
30
14
|
withFileTypes: false
|
|
31
|
-
}).map(f =>
|
|
32
|
-
|
|
33
|
-
const yargs = (0, _yargs.default)(args).usage('Usage: flow-upgrade-codemod <codemod name>').positional('codemod name', {
|
|
15
|
+
}).map(f => path.parse(f).name);
|
|
16
|
+
const yargs = yargsImport(args).usage('Usage: flow-upgrade-codemod <codemod name>').positional('codemod name', {
|
|
34
17
|
describe: 'Your current flow version',
|
|
35
18
|
choices: codemodNames
|
|
36
19
|
}).options({
|
|
@@ -57,7 +40,7 @@ async function main(args) {
|
|
|
57
40
|
return {};
|
|
58
41
|
}
|
|
59
42
|
|
|
60
|
-
return
|
|
43
|
+
return fs.readJSON(yargs.prettierrc);
|
|
61
44
|
})();
|
|
62
45
|
const options = {
|
|
63
46
|
all: !!yargs.all,
|
|
@@ -69,36 +52,36 @@ async function main(args) {
|
|
|
69
52
|
const directory = process.cwd();
|
|
70
53
|
|
|
71
54
|
try {
|
|
72
|
-
const filePaths = await
|
|
55
|
+
const filePaths = await findFlowFilesWithSpinner(directory, options);
|
|
73
56
|
const {
|
|
74
57
|
default: upgrade
|
|
75
|
-
} = await
|
|
58
|
+
} = await import(`${CODEMOD_DIR}/${codemodName}.js`);
|
|
76
59
|
|
|
77
60
|
if (!options.silent) {
|
|
78
|
-
console.log(
|
|
61
|
+
console.log(Styled.sectionHeader('Codemods'));
|
|
79
62
|
console.log();
|
|
80
63
|
console.log('We are now going to run the following codemods:');
|
|
81
64
|
console.log();
|
|
82
|
-
console.log(
|
|
65
|
+
console.log(Styled.upgradeTitle(upgrade.title, 1));
|
|
83
66
|
console.log();
|
|
84
67
|
console.log(upgrade.describe);
|
|
85
68
|
console.log();
|
|
86
|
-
console.log(
|
|
69
|
+
console.log(Styled.divider());
|
|
87
70
|
console.log();
|
|
88
|
-
console.log(`Running ${
|
|
71
|
+
console.log(`Running ${chalk.bold.cyan(1)} codemod...`);
|
|
89
72
|
console.log();
|
|
90
73
|
}
|
|
91
74
|
|
|
92
75
|
switch (upgrade.kind) {
|
|
93
76
|
case 'codemod':
|
|
94
|
-
await (
|
|
77
|
+
await runCodemods([upgrade], filePaths, options);
|
|
95
78
|
break;
|
|
96
79
|
|
|
97
80
|
default:
|
|
98
81
|
throw new Error(`Unexpected upgrade kind: '${upgrade.kind}'`);
|
|
99
82
|
}
|
|
100
83
|
} catch (error) {
|
|
101
|
-
console.error(
|
|
84
|
+
console.error(chalk.red(error ? error.stack || error : error));
|
|
102
85
|
}
|
|
103
86
|
}
|
|
104
87
|
|
package/dist/bin/upgrade.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
7
|
-
|
|
8
|
-
var _yargs = _interopRequireDefault(require("yargs/yargs"));
|
|
9
|
-
|
|
10
|
-
var _upgrade = _interopRequireDefault(require("../upgrade"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import yargsImport from 'yargs/yargs';
|
|
5
|
+
import upgrade from '../upgrade';
|
|
13
6
|
|
|
14
7
|
async function main(args) {
|
|
15
|
-
const yargs = (
|
|
8
|
+
const yargs = yargsImport(args).usage('Usage: flow-upgrade <current version> <target version>').positional('current version', {
|
|
16
9
|
describe: 'Your current flow version'
|
|
17
10
|
}).positional('target version', {
|
|
18
11
|
describe: 'The flow version you are upgrading to'
|
|
@@ -40,7 +33,7 @@ async function main(args) {
|
|
|
40
33
|
return {};
|
|
41
34
|
}
|
|
42
35
|
|
|
43
|
-
return
|
|
36
|
+
return fs.readJSON(yargs.prettierrc);
|
|
44
37
|
})();
|
|
45
38
|
const options = {
|
|
46
39
|
all: !!yargs.all,
|
|
@@ -52,9 +45,9 @@ async function main(args) {
|
|
|
52
45
|
const toVersion = yargs._[1];
|
|
53
46
|
|
|
54
47
|
try {
|
|
55
|
-
await (
|
|
48
|
+
await upgrade(process.cwd(), fromVersion, toVersion, options);
|
|
56
49
|
} catch (error) {
|
|
57
|
-
console.error(
|
|
50
|
+
console.error(chalk.red(error ? error.stack || error : error));
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
53
|
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getClassMemberName = getClassMemberName;
|
|
7
|
-
|
|
8
|
-
function getClassMemberName(member) {
|
|
1
|
+
export function getClassMemberName(member) {
|
|
9
2
|
if (member.key.type === 'PrivateIdentifier') {
|
|
10
3
|
return `#${member.key.name}`;
|
|
11
4
|
}
|
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.replaceMethodWithArrowProp = replaceMethodWithArrowProp;
|
|
7
|
-
|
|
8
|
-
var _hermesTransform = require("hermes-transform");
|
|
9
|
-
|
|
10
|
-
function replaceMethodWithArrowProp(context, method, name) {
|
|
11
|
-
context.replaceNode(method, _hermesTransform.t.PropertyDefinition({
|
|
1
|
+
import { t } from 'hermes-transform';
|
|
2
|
+
export function replaceMethodWithArrowProp(context, method, name) {
|
|
3
|
+
context.replaceNode(method, t.PropertyDefinition({
|
|
12
4
|
computed: false,
|
|
13
5
|
declare: false,
|
|
14
|
-
key:
|
|
6
|
+
key: t.Identifier({
|
|
15
7
|
name,
|
|
16
8
|
typeAnnotation: null
|
|
17
9
|
}),
|
|
18
10
|
optional: false,
|
|
19
11
|
static: false,
|
|
20
|
-
value:
|
|
12
|
+
value: t.ArrowFunctionExpression({
|
|
21
13
|
async: method.value.async,
|
|
22
14
|
body: method.value.body,
|
|
23
15
|
params: method.value.params,
|
|
@@ -25,7 +17,7 @@ function replaceMethodWithArrowProp(context, method, name) {
|
|
|
25
17
|
typeParameters: method.value.typeParameters,
|
|
26
18
|
returnType: method.value.returnType
|
|
27
19
|
}),
|
|
28
|
-
variance:
|
|
20
|
+
variance: t.Variance({
|
|
29
21
|
kind: 'plus'
|
|
30
22
|
})
|
|
31
23
|
}));
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _hermesTransform = require("hermes-transform");
|
|
9
|
-
|
|
10
|
-
var _Types = require("../Types");
|
|
11
|
-
|
|
12
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { t } from 'hermes-transform';
|
|
2
|
+
import { codemod } from '../Types';
|
|
3
|
+
export default codemod({
|
|
13
4
|
title: 'Collapse Object Initialization',
|
|
14
5
|
describe: 'Converts static object assignments to inline properties',
|
|
15
6
|
transform: context => {
|
|
@@ -100,8 +91,7 @@ var _default = (0, _Types.codemod)({
|
|
|
100
91
|
|
|
101
92
|
if (memberObjectNode.type === 'Identifier' && memberObjectNode.name === idNode.name && memberPropertyNode.type === 'Identifier') {
|
|
102
93
|
const shorthand = !leftNode.computed && exprRightNode.type === 'Identifier' && exprRightNode.name === memberPropertyNode.name;
|
|
103
|
-
|
|
104
|
-
const property = _hermesTransform.t.Property({
|
|
94
|
+
const property = t.Property({
|
|
105
95
|
key: memberPropertyNode,
|
|
106
96
|
value: exprRightNode,
|
|
107
97
|
computed: leftNode.computed,
|
|
@@ -109,7 +99,6 @@ var _default = (0, _Types.codemod)({
|
|
|
109
99
|
method: false,
|
|
110
100
|
shorthand
|
|
111
101
|
});
|
|
112
|
-
|
|
113
102
|
return {
|
|
114
103
|
type: 'property',
|
|
115
104
|
keyName: memberPropertyNode.name,
|
|
@@ -222,7 +211,7 @@ var _default = (0, _Types.codemod)({
|
|
|
222
211
|
const newProperties = objectProperties.map(([{
|
|
223
212
|
property
|
|
224
213
|
}, _]) => property);
|
|
225
|
-
context.replaceNode(initNode,
|
|
214
|
+
context.replaceNode(initNode, t.ObjectExpression({
|
|
226
215
|
properties: newProperties
|
|
227
216
|
}));
|
|
228
217
|
objectProperties.forEach(([_, stmtToRemove]) => {
|
|
@@ -233,6 +222,4 @@ var _default = (0, _Types.codemod)({
|
|
|
233
222
|
|
|
234
223
|
};
|
|
235
224
|
}
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
exports.default = _default;
|
|
225
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Make implicitly inexact object types explicitly inexact',
|
|
12
4
|
describe: 'Convert implicitly inexact object type syntax `{}` to explicitly inexact `{...}`',
|
|
13
5
|
transform: context => {
|
|
@@ -20,6 +12,4 @@ var _default = (0, _Types.codemod)({
|
|
|
20
12
|
|
|
21
13
|
};
|
|
22
14
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
15
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
import { t } from 'hermes-transform';
|
|
3
|
+
export default codemod({
|
|
4
|
+
title: 'Convert legacy Flow utility types to modern equivalents',
|
|
5
|
+
describe: `
|
|
6
|
+
Transforms legacy Flow utility types to TypeScript-compatible types:
|
|
7
|
+
- \`$NonMaybeType<T>\` -> \`NonNullable<T>\`
|
|
8
|
+
- \`$ReadOnly<T>\` -> \`Readonly<T>\`
|
|
9
|
+
- \`$ReadOnlyArray<T>\` -> \`ReadonlyArray<T>\`
|
|
10
|
+
- \`$ReadOnlyMap<K, V>\` -> \`ReadonlyMap<K, V>\`
|
|
11
|
+
- \`$ReadOnlySet<T>\` -> \`ReadonlySet<T>\`
|
|
12
|
+
- \`$Keys<T>\` -> \`keyof T\`
|
|
13
|
+
- \`$Values<T>\` -> \`Values<T>\`
|
|
14
|
+
- \`mixed\` -> \`unknown\``,
|
|
15
|
+
transform: context => {
|
|
16
|
+
return {
|
|
17
|
+
MixedTypeAnnotation(node) {
|
|
18
|
+
const newNode = t.GenericTypeAnnotation({
|
|
19
|
+
id: t.Identifier({
|
|
20
|
+
name: 'unknown'
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
context.replaceNode(node, newNode, {
|
|
24
|
+
keepComments: true
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
GenericTypeAnnotation(node) {
|
|
29
|
+
const id = node.id;
|
|
30
|
+
|
|
31
|
+
if (id.type !== 'Identifier') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const typeName = id.name;
|
|
36
|
+
|
|
37
|
+
if (typeName === '$Keys') {
|
|
38
|
+
if (node.typeParameters && node.typeParameters.params && node.typeParameters.params.length === 1) {
|
|
39
|
+
const newNode = t.KeyofTypeAnnotation({
|
|
40
|
+
argument: node.typeParameters.params[0]
|
|
41
|
+
});
|
|
42
|
+
context.replaceNode(node, newNode, {
|
|
43
|
+
keepComments: true
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const typeMap = {
|
|
51
|
+
$NonMaybeType: 'NonNullable',
|
|
52
|
+
$ReadOnly: 'Readonly',
|
|
53
|
+
$ReadOnlyArray: 'ReadonlyArray',
|
|
54
|
+
$ReadOnlyMap: 'ReadonlyMap',
|
|
55
|
+
$ReadOnlySet: 'ReadonlySet',
|
|
56
|
+
$Values: 'Values'
|
|
57
|
+
};
|
|
58
|
+
const modernType = typeMap[typeName];
|
|
59
|
+
|
|
60
|
+
if (modernType) {
|
|
61
|
+
context.modifyNodeInPlace(node.id, {
|
|
62
|
+
name: modernType
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Convert `$Shape` to `Partial`',
|
|
12
4
|
describe: 'Converts usage of the `$Shape` utility type to `Partial`. It is possible that this will create type errors that you will have to resolve.',
|
|
13
5
|
transform: context => {
|
|
@@ -20,6 +12,4 @@ var _default = (0, _Types.codemod)({
|
|
|
20
12
|
|
|
21
13
|
};
|
|
22
14
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
15
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
import { t } from 'hermes-transform';
|
|
3
|
+
|
|
4
|
+
function eliminateAbstractComponent(node) {
|
|
5
|
+
const {
|
|
6
|
+
id: maybeQualifiedIdentifier,
|
|
7
|
+
typeParameters
|
|
8
|
+
} = node;
|
|
9
|
+
|
|
10
|
+
if (maybeQualifiedIdentifier.type === 'QualifiedTypeIdentifier' && maybeQualifiedIdentifier.qualification.name === 'React' && maybeQualifiedIdentifier.id.name === 'AbstractComponent' && typeParameters != null) {
|
|
11
|
+
const [config, instance, renders] = typeParameters.params;
|
|
12
|
+
|
|
13
|
+
if (renders != null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (instance == null || instance.type === 'MixedTypeAnnotation') {
|
|
18
|
+
return t.GenericTypeAnnotation({
|
|
19
|
+
id: t.QualifiedTypeIdentifier({
|
|
20
|
+
qualification: t.Identifier({
|
|
21
|
+
name: 'React'
|
|
22
|
+
}),
|
|
23
|
+
id: t.Identifier({
|
|
24
|
+
name: 'ComponentType'
|
|
25
|
+
})
|
|
26
|
+
}),
|
|
27
|
+
typeParameters: t.TypeParameterInstantiation({
|
|
28
|
+
params: [config]
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (maybeQualifiedIdentifier.type === 'QualifiedTypeIdentifier' && maybeQualifiedIdentifier.qualification.name === 'React' && maybeQualifiedIdentifier.id.name === 'ElementConfig' && typeParameters != null && typeParameters.params.length === 1 && typeParameters.params[0].type === 'GenericTypeAnnotation' && typeParameters.params[0].id.type === 'QualifiedTypeIdentifier' && typeParameters.params[0].id.qualification.name === 'React' && typeParameters.params[0].id.id.name === 'AbstractComponent' && typeParameters.params[0].typeParameters != null && typeParameters.params[0].typeParameters.params.length >= 1) {
|
|
37
|
+
return typeParameters.params[0].typeParameters.params[0];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (maybeQualifiedIdentifier.type === 'QualifiedTypeIdentifier' && maybeQualifiedIdentifier.qualification.name === 'React' && maybeQualifiedIdentifier.id.name === 'ElementRef' && typeParameters != null && typeParameters.params.length === 1 && typeParameters.params[0].type === 'GenericTypeAnnotation' && typeParameters.params[0].id.type === 'QualifiedTypeIdentifier' && typeParameters.params[0].id.qualification.name === 'React' && typeParameters.params[0].id.id.name === 'AbstractComponent' && typeParameters.params[0].typeParameters != null && typeParameters.params[0].typeParameters.params.length >= 2) {
|
|
41
|
+
return typeParameters.params[0].typeParameters.params[1];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (maybeQualifiedIdentifier.type === 'QualifiedTypeIdentifier' && maybeQualifiedIdentifier.qualification.name === 'React' && maybeQualifiedIdentifier.id.name === 'ElementRef' && typeParameters != null && typeParameters.params.length === 1 && typeParameters.params[0].type === 'GenericTypeAnnotation' && typeParameters.params[0].id.type === 'QualifiedTypeIdentifier' && typeParameters.params[0].id.qualification.name === 'React' && typeParameters.params[0].id.id.name === 'AbstractComponent' && typeParameters.params[0].typeParameters != null && typeParameters.params[0].typeParameters.params.length === 1) {
|
|
45
|
+
return t.MixedTypeAnnotation({});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default codemod({
|
|
52
|
+
title: 'Eliminate `React.AbstractComponent<...>`',
|
|
53
|
+
describe: `
|
|
54
|
+
- \`React.AbstractComponent<Props>\` -> \`React.ComponentType<Props>\`
|
|
55
|
+
- \`React.ElementConfig<React.AbstractComponent<Props, Instance>>\` -> \`Props\`
|
|
56
|
+
- \`React.ElementRef<React.AbstractComponent<Props, Instance>>\` -> \`Instance\`
|
|
57
|
+
- \`React.ElementRef<React.AbstractComponent<Props>\` -> \`mixed\``,
|
|
58
|
+
transform: context => {
|
|
59
|
+
return {
|
|
60
|
+
GenericTypeAnnotation(node) {
|
|
61
|
+
const replacement = eliminateAbstractComponent(node);
|
|
62
|
+
|
|
63
|
+
if (replacement) {
|
|
64
|
+
context.replaceNode(node, replacement, {
|
|
65
|
+
keepComments: true
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Remove Annotations In Destructuring',
|
|
12
4
|
describe: 'Remove annotations nested inside of destructuring. These are not valid Flow syntax.',
|
|
13
5
|
transform: context => {
|
|
@@ -26,6 +18,4 @@ var _default = (0, _Types.codemod)({
|
|
|
26
18
|
|
|
27
19
|
};
|
|
28
20
|
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
exports.default = _default;
|
|
21
|
+
});
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _getClassMemberName = require("../codemodUtils/getClassMemberName");
|
|
9
|
-
|
|
10
|
-
var _replaceMethodWithArrowProp = require("../codemodUtils/replaceMethodWithArrowProp");
|
|
11
|
-
|
|
12
|
-
var _Types = require("../Types");
|
|
1
|
+
import { getClassMemberName } from '../codemodUtils/getClassMemberName';
|
|
2
|
+
import { replaceMethodWithArrowProp } from '../codemodUtils/replaceMethodWithArrowProp';
|
|
3
|
+
import { codemod } from '../Types';
|
|
13
4
|
|
|
14
5
|
function getKind(member) {
|
|
15
6
|
switch (member.type) {
|
|
@@ -114,7 +105,7 @@ function findDuplicates(membersMap) {
|
|
|
114
105
|
return toDelete;
|
|
115
106
|
}
|
|
116
107
|
|
|
117
|
-
|
|
108
|
+
export default codemod({
|
|
118
109
|
title: 'Remove Duplicate Class Properties',
|
|
119
110
|
describe: 'Removes useless duplicate class properties and fixes bad constructor binding in those classes',
|
|
120
111
|
transform: context => {
|
|
@@ -126,7 +117,7 @@ var _default = (0, _Types.codemod)({
|
|
|
126
117
|
|
|
127
118
|
for (const member of node.body.body) {
|
|
128
119
|
const membersMap = member.static ? staticMembers : instanceMembers;
|
|
129
|
-
const name =
|
|
120
|
+
const name = getClassMemberName(member);
|
|
130
121
|
|
|
131
122
|
if (name == null) {
|
|
132
123
|
continue;
|
|
@@ -148,9 +139,7 @@ var _default = (0, _Types.codemod)({
|
|
|
148
139
|
}
|
|
149
140
|
|
|
150
141
|
for (const memberToDelete of toDelete) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (memberToDelete.type === 'PropertyDefinition' && ((_memberToDelete$value = memberToDelete.value) === null || _memberToDelete$value === void 0 ? void 0 : _memberToDelete$value.type) === 'CallExpression') {
|
|
142
|
+
if (memberToDelete.type === 'PropertyDefinition' && memberToDelete.value?.type === 'CallExpression') {
|
|
154
143
|
console.log(context.buildCodeFrame(memberToDelete.value, 'Deleted a property with a CallExpression value. You should double check this was safe.'));
|
|
155
144
|
}
|
|
156
145
|
|
|
@@ -168,7 +157,7 @@ var _default = (0, _Types.codemod)({
|
|
|
168
157
|
continue;
|
|
169
158
|
}
|
|
170
159
|
|
|
171
|
-
const name =
|
|
160
|
+
const name = getClassMemberName(member);
|
|
172
161
|
|
|
173
162
|
if (name == null) {
|
|
174
163
|
continue;
|
|
@@ -202,7 +191,7 @@ var _default = (0, _Types.codemod)({
|
|
|
202
191
|
const subjectName = node.property.name;
|
|
203
192
|
const member = instanceMembers.get(subjectName);
|
|
204
193
|
|
|
205
|
-
if (
|
|
194
|
+
if (member?.kind !== 'Method') {
|
|
206
195
|
return;
|
|
207
196
|
}
|
|
208
197
|
|
|
@@ -227,21 +216,15 @@ var _default = (0, _Types.codemod)({
|
|
|
227
216
|
throw new Error('this cannot happen');
|
|
228
217
|
}
|
|
229
218
|
|
|
230
|
-
|
|
219
|
+
replaceMethodWithArrowProp(context, method, subjectName);
|
|
231
220
|
},
|
|
232
221
|
|
|
233
222
|
'ClassDeclaration, ClassExpression:exit'(node) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (classStack && ((_classStack = classStack) === null || _classStack === void 0 ? void 0 : _classStack.current) === node) {
|
|
237
|
-
var _classStack2;
|
|
238
|
-
|
|
239
|
-
classStack = (_classStack2 = classStack) === null || _classStack2 === void 0 ? void 0 : _classStack2.parent;
|
|
223
|
+
if (classStack && classStack?.current === node) {
|
|
224
|
+
classStack = classStack?.parent;
|
|
240
225
|
}
|
|
241
226
|
}
|
|
242
227
|
|
|
243
228
|
};
|
|
244
229
|
}
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
exports.default = _default;
|
|
230
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Remove explicitly exact object type syntax',
|
|
12
4
|
describe: 'Convert explicitly exact object type syntax `{| |}` to be just be `{ }`. To be done after you turn on `exact_by_default=true` in your `.flowconfig`.',
|
|
13
5
|
transform: context => {
|
|
@@ -20,6 +12,4 @@ var _default = (0, _Types.codemod)({
|
|
|
20
12
|
|
|
21
13
|
};
|
|
22
14
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
15
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Rename `$Partial` to `Partial`',
|
|
12
4
|
describe: 'Renames the `$Partial` type utility to `Partial`.',
|
|
13
5
|
transform: context => {
|
|
@@ -20,6 +12,4 @@ var _default = (0, _Types.codemod)({
|
|
|
20
12
|
|
|
21
13
|
};
|
|
22
14
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
15
|
+
});
|