flow-upgrade 2.34.0 → 2.35.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/dist/Styled.js +0 -5
- package/dist/Types.js +2 -2
- package/dist/bin/runSpecificCodemod.js +2 -22
- package/dist/bin/upgrade.js +1 -9
- package/dist/codemodUtils/getClassMemberName.js +0 -3
- package/dist/codemodUtils/replaceMethodWithArrowProp.js +0 -2
- package/dist/codemods/collapseObjectInitialization.js +2 -55
- package/dist/codemods/convertImplicitInexactObjectTypes.js +2 -7
- package/dist/codemods/convertLegacyUtilityTypes.js +2 -17
- package/dist/codemods/convertShapeToPartial.js +2 -7
- package/dist/codemods/eliminateAbstractComponent.js +2 -18
- package/dist/codemods/removeAnnotationsInDestructuring.js +2 -8
- package/dist/codemods/removeDuplicateClassProperties.js +2 -60
- package/dist/codemods/removeExplicitlyExactObjectTypeSyntax.js +2 -7
- package/dist/codemods/renamePartial.js +2 -7
- package/dist/codemods/replaceReactDollarUtilityTypes.js +2 -13
- package/dist/codemods/replaceTemporaryTypes.js +2 -14
- package/dist/codemods/typeCastToAsExpression.js +2 -9
- package/dist/codemods/typeParameterBoundExactEmptyObjectToInexact.js +2 -9
- package/dist/findFlowFiles.js +1 -21
- package/dist/runCodemods.js +1 -9
- package/dist/upgrade.js +1 -22
- package/dist/upgrades/0.170.0/index.js +3 -7
- package/dist/upgrades/0.176.0/index.js +3 -7
- package/dist/upgrades/0.201.0/index.js +3 -7
- package/dist/upgrades/0.84.0/index.js +3 -7
- package/dist/upgrades/index.js +2 -9
- package/dist/utils/redirectConsole.js +1 -12
- package/package.json +1 -1
package/dist/Styled.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
-
|
|
5
4
|
exports.divider = function divider() {
|
|
6
5
|
return chalk.grey(Array(80).fill('=').join(''));
|
|
7
6
|
};
|
|
8
|
-
|
|
9
7
|
exports.sectionHeader = function sectionHeader(header) {
|
|
10
8
|
return chalk.bold(`# ${header}`);
|
|
11
9
|
};
|
|
12
|
-
|
|
13
10
|
exports.upgradeTitle = function upgradeTitle(title, n) {
|
|
14
11
|
return chalk.bold(`${chalk.grey(`${n}.`)} ${chalk.blue(title)}`);
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
exports.codeblock = function codeblock(code) {
|
|
18
14
|
return code.split('\n').map(line => ` ${line}`).join('\n').replace(/([={}()\[\];<>,:.*/])/g, chalk.grey('$1')).replace(/(import|from|typeof|type|class|extends|static|return|function)/g, chalk.magenta('$1')).replace(/('[^\n]*')/g, chalk.green('$1'));
|
|
19
15
|
};
|
|
20
|
-
|
|
21
16
|
exports.list = function list(items) {
|
|
22
17
|
return items.map(item => item.split('\n').map((line, i) => `${i === 0 ? chalk.grey('- ') : ' '}${line}`).join('\n')).join('\n');
|
|
23
18
|
};
|
package/dist/Types.js
CHANGED
|
@@ -2,34 +2,20 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
5
|
-
|
|
6
5
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
7
|
-
|
|
8
6
|
var _yargs = _interopRequireDefault(require("yargs/yargs"));
|
|
9
|
-
|
|
10
7
|
var _upgrade = _interopRequireDefault(require("../upgrade"));
|
|
11
|
-
|
|
12
8
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
9
|
var _findFlowFiles = require("../findFlowFiles");
|
|
15
|
-
|
|
16
10
|
var _runCodemods = _interopRequireDefault(require("../runCodemods"));
|
|
17
|
-
|
|
18
11
|
var _Styled = _interopRequireDefault(require("../Styled"));
|
|
19
|
-
|
|
20
|
-
function
|
|
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
|
-
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
26
14
|
const CODEMOD_DIR = _path.default.resolve(__dirname, '..', 'codemods');
|
|
27
|
-
|
|
28
15
|
async function main(args) {
|
|
29
16
|
const codemodNames = _fsExtra.default.readdirSync(CODEMOD_DIR, {
|
|
30
17
|
withFileTypes: false
|
|
31
18
|
}).map(f => _path.default.parse(f).name);
|
|
32
|
-
|
|
33
19
|
const yargs = (0, _yargs.default)(args).usage('Usage: flow-upgrade-codemod <codemod name>').positional('codemod name', {
|
|
34
20
|
describe: 'Your current flow version',
|
|
35
21
|
choices: codemodNames
|
|
@@ -56,7 +42,6 @@ async function main(args) {
|
|
|
56
42
|
if (!yargs.prettierrc) {
|
|
57
43
|
return {};
|
|
58
44
|
}
|
|
59
|
-
|
|
60
45
|
return _fsExtra.default.readJSON(yargs.prettierrc);
|
|
61
46
|
})();
|
|
62
47
|
const options = {
|
|
@@ -67,13 +52,11 @@ async function main(args) {
|
|
|
67
52
|
};
|
|
68
53
|
const codemodName = yargs._[0];
|
|
69
54
|
const directory = process.cwd();
|
|
70
|
-
|
|
71
55
|
try {
|
|
72
56
|
const filePaths = await (0, _findFlowFiles.findFlowFilesWithSpinner)(directory, options);
|
|
73
57
|
const {
|
|
74
58
|
default: upgrade
|
|
75
59
|
} = await Promise.resolve(`${CODEMOD_DIR}/${codemodName}.js`).then(s => _interopRequireWildcard(require(s)));
|
|
76
|
-
|
|
77
60
|
if (!options.silent) {
|
|
78
61
|
console.log(_Styled.default.sectionHeader('Codemods'));
|
|
79
62
|
console.log();
|
|
@@ -88,12 +71,10 @@ async function main(args) {
|
|
|
88
71
|
console.log(`Running ${_chalk.default.bold.cyan(1)} codemod...`);
|
|
89
72
|
console.log();
|
|
90
73
|
}
|
|
91
|
-
|
|
92
74
|
switch (upgrade.kind) {
|
|
93
75
|
case 'codemod':
|
|
94
76
|
await (0, _runCodemods.default)([upgrade], filePaths, options);
|
|
95
77
|
break;
|
|
96
|
-
|
|
97
78
|
default:
|
|
98
79
|
throw new Error(`Unexpected upgrade kind: '${upgrade.kind}'`);
|
|
99
80
|
}
|
|
@@ -101,5 +82,4 @@ async function main(args) {
|
|
|
101
82
|
console.error(_chalk.default.red(error ? error.stack || error : error));
|
|
102
83
|
}
|
|
103
84
|
}
|
|
104
|
-
|
|
105
85
|
void main(process.argv.slice(2));
|
package/dist/bin/upgrade.js
CHANGED
|
@@ -2,15 +2,10 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
5
|
-
|
|
6
5
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
7
|
-
|
|
8
6
|
var _yargs = _interopRequireDefault(require("yargs/yargs"));
|
|
9
|
-
|
|
10
7
|
var _upgrade = _interopRequireDefault(require("../upgrade"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
9
|
async function main(args) {
|
|
15
10
|
const yargs = (0, _yargs.default)(args).usage('Usage: flow-upgrade <current version> <target version>').positional('current version', {
|
|
16
11
|
describe: 'Your current flow version'
|
|
@@ -39,7 +34,6 @@ async function main(args) {
|
|
|
39
34
|
if (!yargs.prettierrc) {
|
|
40
35
|
return {};
|
|
41
36
|
}
|
|
42
|
-
|
|
43
37
|
return _fsExtra.default.readJSON(yargs.prettierrc);
|
|
44
38
|
})();
|
|
45
39
|
const options = {
|
|
@@ -50,12 +44,10 @@ async function main(args) {
|
|
|
50
44
|
};
|
|
51
45
|
const fromVersion = yargs._[0];
|
|
52
46
|
const toVersion = yargs._[1];
|
|
53
|
-
|
|
54
47
|
try {
|
|
55
48
|
await (0, _upgrade.default)(process.cwd(), fromVersion, toVersion, options);
|
|
56
49
|
} catch (error) {
|
|
57
50
|
console.error(_chalk.default.red(error ? error.stack || error : error));
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
|
-
|
|
61
53
|
void main(process.argv.slice(2));
|
|
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getClassMemberName = getClassMemberName;
|
|
7
|
-
|
|
8
7
|
function getClassMemberName(member) {
|
|
9
8
|
if (member.key.type === 'PrivateIdentifier') {
|
|
10
9
|
return `#${member.key.name}`;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
if (member.computed === true || member.key.type !== 'Identifier') {
|
|
14
12
|
return null;
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
return member.key.name;
|
|
18
15
|
}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.replaceMethodWithArrowProp = replaceMethodWithArrowProp;
|
|
7
|
-
|
|
8
7
|
var _hermesTransform = require("hermes-transform");
|
|
9
|
-
|
|
10
8
|
function replaceMethodWithArrowProp(context, method, name) {
|
|
11
9
|
context.replaceNode(method, _hermesTransform.t.PropertyDefinition({
|
|
12
10
|
computed: false,
|
|
@@ -4,103 +4,79 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _hermesTransform = require("hermes-transform");
|
|
9
|
-
|
|
10
8
|
var _Types = require("../Types");
|
|
11
|
-
|
|
12
|
-
var _default = (0, _Types.codemod)({
|
|
9
|
+
var _default = exports.default = (0, _Types.codemod)({
|
|
13
10
|
title: 'Collapse Object Initialization',
|
|
14
11
|
describe: 'Converts static object assignments to inline properties',
|
|
15
12
|
transform: context => {
|
|
16
13
|
function getStatementContainerArray(stmtNode) {
|
|
17
14
|
const parent = stmtNode.parent;
|
|
18
|
-
|
|
19
15
|
switch (parent.type) {
|
|
20
16
|
case 'SwitchCase':
|
|
21
17
|
{
|
|
22
18
|
return parent.consequent;
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
case 'BlockStatement':
|
|
26
21
|
{
|
|
27
22
|
return parent.body;
|
|
28
23
|
}
|
|
29
|
-
|
|
30
24
|
case 'Program':
|
|
31
25
|
{
|
|
32
26
|
return parent.body;
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
default:
|
|
36
29
|
return null;
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
|
-
|
|
40
32
|
function getNextSibling(node) {
|
|
41
33
|
if (node == null) {
|
|
42
34
|
return null;
|
|
43
35
|
}
|
|
44
|
-
|
|
45
36
|
const parentContainer = getStatementContainerArray(node);
|
|
46
|
-
|
|
47
37
|
if (parentContainer == null) {
|
|
48
38
|
return null;
|
|
49
39
|
}
|
|
50
|
-
|
|
51
40
|
const nodeIndex = parentContainer.indexOf(node);
|
|
52
|
-
|
|
53
41
|
if (nodeIndex === -1) {
|
|
54
42
|
return null;
|
|
55
43
|
}
|
|
56
|
-
|
|
57
44
|
return parentContainer[nodeIndex + 1];
|
|
58
45
|
}
|
|
59
|
-
|
|
60
46
|
function containsReference(node, references) {
|
|
61
47
|
return references.some(reference => {
|
|
62
48
|
const refRange = reference.identifier.range;
|
|
63
49
|
return node.range[0] <= refRange[0] && refRange[1] <= node.range[1];
|
|
64
50
|
});
|
|
65
51
|
}
|
|
66
|
-
|
|
67
52
|
function processStmtNode(idNode, references, stmtNode) {
|
|
68
53
|
if (stmtNode.type !== 'ExpressionStatement') {
|
|
69
54
|
return {
|
|
70
55
|
type: 'abort'
|
|
71
56
|
};
|
|
72
57
|
}
|
|
73
|
-
|
|
74
58
|
const exprNode = stmtNode.expression;
|
|
75
|
-
|
|
76
59
|
if (exprNode.type !== 'AssignmentExpression') {
|
|
77
60
|
return {
|
|
78
61
|
type: 'abort'
|
|
79
62
|
};
|
|
80
63
|
}
|
|
81
|
-
|
|
82
64
|
const leftNode = exprNode.left;
|
|
83
|
-
|
|
84
65
|
if (leftNode.type !== 'MemberExpression') {
|
|
85
66
|
return {
|
|
86
67
|
type: 'abort'
|
|
87
68
|
};
|
|
88
69
|
}
|
|
89
|
-
|
|
90
70
|
const exprRightNode = exprNode.right;
|
|
91
|
-
|
|
92
71
|
if (containsReference(exprRightNode, references)) {
|
|
93
72
|
return {
|
|
94
73
|
type: 'abort'
|
|
95
74
|
};
|
|
96
75
|
}
|
|
97
|
-
|
|
98
76
|
const memberObjectNode = leftNode.object;
|
|
99
77
|
const memberPropertyNode = leftNode.property;
|
|
100
|
-
|
|
101
78
|
if (memberObjectNode.type === 'Identifier' && memberObjectNode.name === idNode.name && memberPropertyNode.type === 'Identifier') {
|
|
102
79
|
const shorthand = !leftNode.computed && exprRightNode.type === 'Identifier' && exprRightNode.name === memberPropertyNode.name;
|
|
103
|
-
|
|
104
80
|
const property = _hermesTransform.t.Property({
|
|
105
81
|
key: memberPropertyNode,
|
|
106
82
|
value: exprRightNode,
|
|
@@ -109,7 +85,6 @@ var _default = (0, _Types.codemod)({
|
|
|
109
85
|
method: false,
|
|
110
86
|
shorthand
|
|
111
87
|
});
|
|
112
|
-
|
|
113
88
|
return {
|
|
114
89
|
type: 'property',
|
|
115
90
|
keyName: memberPropertyNode.name,
|
|
@@ -117,67 +92,50 @@ var _default = (0, _Types.codemod)({
|
|
|
117
92
|
computed: leftNode.computed
|
|
118
93
|
};
|
|
119
94
|
}
|
|
120
|
-
|
|
121
95
|
return {
|
|
122
96
|
type: 'abort'
|
|
123
97
|
};
|
|
124
98
|
}
|
|
125
|
-
|
|
126
99
|
function isWriteToObject(ref) {
|
|
127
100
|
let currNode = ref.identifier;
|
|
128
|
-
|
|
129
101
|
while (currNode.parent.type === 'MemberExpression' && currNode.parent.object === currNode) {
|
|
130
102
|
currNode = currNode.parent;
|
|
131
103
|
}
|
|
132
|
-
|
|
133
104
|
return currNode.parent.type === 'AssignmentExpression';
|
|
134
105
|
}
|
|
135
|
-
|
|
136
106
|
return {
|
|
137
107
|
VariableDeclarator(node) {
|
|
138
108
|
const initNode = node.init;
|
|
139
|
-
|
|
140
109
|
if (initNode == null || initNode.type !== 'ObjectExpression' || initNode.properties.length > 0) {
|
|
141
110
|
return;
|
|
142
111
|
}
|
|
143
|
-
|
|
144
112
|
const idNode = node.id;
|
|
145
|
-
|
|
146
113
|
if (idNode.type !== 'Identifier' || idNode.typeAnnotation != null) {
|
|
147
114
|
return;
|
|
148
115
|
}
|
|
149
|
-
|
|
150
116
|
const stmtNode = node.parent;
|
|
151
|
-
|
|
152
117
|
if (stmtNode.type !== 'VariableDeclaration') {
|
|
153
118
|
throw new Error(context.buildCodeFrame(stmtNode, `This is not right, parent of VariableDeclarator should always be a VariableDeclaration, instead got a "${stmtNode.type}"`));
|
|
154
119
|
}
|
|
155
|
-
|
|
156
120
|
const binding = context.getBinding(idNode.name);
|
|
157
|
-
|
|
158
121
|
if (binding == null) {
|
|
159
122
|
throw new Error(context.buildCodeFrame(idNode, `No binding found for node of name "${idNode.name}"`));
|
|
160
123
|
}
|
|
161
|
-
|
|
162
124
|
let nextStmtNode = stmtNode;
|
|
163
125
|
let finish = false;
|
|
164
126
|
const objectProperties = [];
|
|
165
|
-
|
|
166
127
|
while (finish !== true && (nextStmtNode = getNextSibling(nextStmtNode)) && nextStmtNode != null) {
|
|
167
128
|
const out = processStmtNode(idNode, binding.references, nextStmtNode);
|
|
168
|
-
|
|
169
129
|
switch (out.type) {
|
|
170
130
|
case 'abort':
|
|
171
131
|
{
|
|
172
132
|
finish = true;
|
|
173
133
|
break;
|
|
174
134
|
}
|
|
175
|
-
|
|
176
135
|
case 'skip':
|
|
177
136
|
{
|
|
178
137
|
break;
|
|
179
138
|
}
|
|
180
|
-
|
|
181
139
|
case 'property':
|
|
182
140
|
{
|
|
183
141
|
const {
|
|
@@ -189,36 +147,28 @@ var _default = (0, _Types.codemod)({
|
|
|
189
147
|
}
|
|
190
148
|
}
|
|
191
149
|
}
|
|
192
|
-
|
|
193
150
|
if (objectProperties.length > 0) {
|
|
194
151
|
const assignmentRefsCount = binding.references.reduce((acc, ref) => {
|
|
195
152
|
if (isWriteToObject(ref)) {
|
|
196
153
|
return acc + 1;
|
|
197
154
|
}
|
|
198
|
-
|
|
199
155
|
return acc;
|
|
200
156
|
}, 0);
|
|
201
|
-
|
|
202
157
|
if (assignmentRefsCount !== objectProperties.length) {
|
|
203
158
|
console.error(context.buildCodeFrame(stmtNode, 'Object had non inlinable and inlineable properties'));
|
|
204
159
|
}
|
|
205
|
-
|
|
206
160
|
const keyNames = new Set();
|
|
207
|
-
|
|
208
161
|
for (const [{
|
|
209
162
|
keyName,
|
|
210
163
|
computed
|
|
211
164
|
}, _] of objectProperties) {
|
|
212
165
|
const name = `${computed ? 'c' : 'v'}-${keyName}`;
|
|
213
|
-
|
|
214
166
|
if (keyNames.has(name)) {
|
|
215
167
|
console.error(context.buildCodeFrame(stmtNode, `Object has duplicate key of "${keyName}"`));
|
|
216
168
|
return;
|
|
217
169
|
}
|
|
218
|
-
|
|
219
170
|
keyNames.add(name);
|
|
220
171
|
}
|
|
221
|
-
|
|
222
172
|
const newProperties = objectProperties.map(([{
|
|
223
173
|
property
|
|
224
174
|
}, _]) => property);
|
|
@@ -230,9 +180,6 @@ var _default = (0, _Types.codemod)({
|
|
|
230
180
|
});
|
|
231
181
|
}
|
|
232
182
|
}
|
|
233
|
-
|
|
234
183
|
};
|
|
235
184
|
}
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
exports.default = _default;
|
|
185
|
+
});
|
|
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
8
|
+
var _default = exports.default = (0, _Types.codemod)({
|
|
11
9
|
title: 'Make implicitly inexact object types explicitly inexact',
|
|
12
10
|
describe: 'Convert implicitly inexact object type syntax `{}` to explicitly inexact `{...}`',
|
|
13
11
|
transform: context => {
|
|
@@ -17,9 +15,6 @@ var _default = (0, _Types.codemod)({
|
|
|
17
15
|
inexact: true
|
|
18
16
|
});
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
};
|
|
22
19
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
20
|
+
});
|
|
@@ -4,12 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _Types = require("../Types");
|
|
9
|
-
|
|
10
8
|
var _hermesTransform = require("hermes-transform");
|
|
11
|
-
|
|
12
|
-
var _default = (0, _Types.codemod)({
|
|
9
|
+
var _default = exports.default = (0, _Types.codemod)({
|
|
13
10
|
title: 'Convert legacy Flow utility types to modern equivalents',
|
|
14
11
|
describe: `
|
|
15
12
|
Transforms legacy Flow utility types to TypeScript-compatible types:
|
|
@@ -29,35 +26,27 @@ Transforms legacy Flow utility types to TypeScript-compatible types:
|
|
|
29
26
|
name: 'unknown'
|
|
30
27
|
})
|
|
31
28
|
});
|
|
32
|
-
|
|
33
29
|
context.replaceNode(node, newNode, {
|
|
34
30
|
keepComments: true
|
|
35
31
|
});
|
|
36
32
|
},
|
|
37
|
-
|
|
38
33
|
GenericTypeAnnotation(node) {
|
|
39
34
|
const id = node.id;
|
|
40
|
-
|
|
41
35
|
if (id.type !== 'Identifier') {
|
|
42
36
|
return;
|
|
43
37
|
}
|
|
44
|
-
|
|
45
38
|
const typeName = id.name;
|
|
46
|
-
|
|
47
39
|
if (typeName === '$Keys') {
|
|
48
40
|
if (node.typeParameters && node.typeParameters.params && node.typeParameters.params.length === 1) {
|
|
49
41
|
const newNode = _hermesTransform.t.KeyofTypeAnnotation({
|
|
50
42
|
argument: node.typeParameters.params[0]
|
|
51
43
|
});
|
|
52
|
-
|
|
53
44
|
context.replaceNode(node, newNode, {
|
|
54
45
|
keepComments: true
|
|
55
46
|
});
|
|
56
47
|
}
|
|
57
|
-
|
|
58
48
|
return;
|
|
59
49
|
}
|
|
60
|
-
|
|
61
50
|
const typeMap = {
|
|
62
51
|
$NonMaybeType: 'NonNullable',
|
|
63
52
|
$ReadOnly: 'Readonly',
|
|
@@ -67,16 +56,12 @@ Transforms legacy Flow utility types to TypeScript-compatible types:
|
|
|
67
56
|
$Values: 'Values'
|
|
68
57
|
};
|
|
69
58
|
const modernType = typeMap[typeName];
|
|
70
|
-
|
|
71
59
|
if (modernType) {
|
|
72
60
|
context.modifyNodeInPlace(node.id, {
|
|
73
61
|
name: modernType
|
|
74
62
|
});
|
|
75
63
|
}
|
|
76
64
|
}
|
|
77
|
-
|
|
78
65
|
};
|
|
79
66
|
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
exports.default = _default;
|
|
67
|
+
});
|
|
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
8
|
+
var _default = exports.default = (0, _Types.codemod)({
|
|
11
9
|
title: 'Convert `$Shape` to `Partial`',
|
|
12
10
|
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
11
|
transform: context => {
|
|
@@ -17,9 +15,6 @@ var _default = (0, _Types.codemod)({
|
|
|
17
15
|
name: 'Partial'
|
|
18
16
|
});
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
};
|
|
22
19
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
20
|
+
});
|
|
@@ -4,24 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _Types = require("../Types");
|
|
9
|
-
|
|
10
8
|
var _hermesTransform = require("hermes-transform");
|
|
11
|
-
|
|
12
9
|
function eliminateAbstractComponent(node) {
|
|
13
10
|
const {
|
|
14
11
|
id: maybeQualifiedIdentifier,
|
|
15
12
|
typeParameters
|
|
16
13
|
} = node;
|
|
17
|
-
|
|
18
14
|
if (maybeQualifiedIdentifier.type === 'QualifiedTypeIdentifier' && maybeQualifiedIdentifier.qualification.name === 'React' && maybeQualifiedIdentifier.id.name === 'AbstractComponent' && typeParameters != null) {
|
|
19
15
|
const [config, instance, renders] = typeParameters.params;
|
|
20
|
-
|
|
21
16
|
if (renders != null) {
|
|
22
17
|
return null;
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
if (instance == null || instance.type === 'MixedTypeAnnotation') {
|
|
26
20
|
return _hermesTransform.t.GenericTypeAnnotation({
|
|
27
21
|
id: _hermesTransform.t.QualifiedTypeIdentifier({
|
|
@@ -37,26 +31,20 @@ function eliminateAbstractComponent(node) {
|
|
|
37
31
|
})
|
|
38
32
|
});
|
|
39
33
|
}
|
|
40
|
-
|
|
41
34
|
return null;
|
|
42
35
|
}
|
|
43
|
-
|
|
44
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) {
|
|
45
37
|
return typeParameters.params[0].typeParameters.params[0];
|
|
46
38
|
}
|
|
47
|
-
|
|
48
39
|
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) {
|
|
49
40
|
return typeParameters.params[0].typeParameters.params[1];
|
|
50
41
|
}
|
|
51
|
-
|
|
52
42
|
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) {
|
|
53
43
|
return _hermesTransform.t.MixedTypeAnnotation({});
|
|
54
44
|
}
|
|
55
|
-
|
|
56
45
|
return null;
|
|
57
46
|
}
|
|
58
|
-
|
|
59
|
-
var _default = (0, _Types.codemod)({
|
|
47
|
+
var _default = exports.default = (0, _Types.codemod)({
|
|
60
48
|
title: 'Eliminate `React.AbstractComponent<...>`',
|
|
61
49
|
describe: `
|
|
62
50
|
- \`React.AbstractComponent<Props>\` -> \`React.ComponentType<Props>\`
|
|
@@ -67,16 +55,12 @@ var _default = (0, _Types.codemod)({
|
|
|
67
55
|
return {
|
|
68
56
|
GenericTypeAnnotation(node) {
|
|
69
57
|
const replacement = eliminateAbstractComponent(node);
|
|
70
|
-
|
|
71
58
|
if (replacement) {
|
|
72
59
|
context.replaceNode(node, replacement, {
|
|
73
60
|
keepComments: true
|
|
74
61
|
});
|
|
75
62
|
}
|
|
76
63
|
}
|
|
77
|
-
|
|
78
64
|
};
|
|
79
65
|
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
exports.default = _default;
|
|
66
|
+
});
|
|
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
8
|
+
var _default = exports.default = (0, _Types.codemod)({
|
|
11
9
|
title: 'Remove Annotations In Destructuring',
|
|
12
10
|
describe: 'Remove annotations nested inside of destructuring. These are not valid Flow syntax.',
|
|
13
11
|
transform: context => {
|
|
@@ -17,15 +15,11 @@ var _default = (0, _Types.codemod)({
|
|
|
17
15
|
typeAnnotation: null
|
|
18
16
|
});
|
|
19
17
|
},
|
|
20
|
-
|
|
21
18
|
':matches(ArrayPattern, ObjectPattern) > :matches(RestElement, Property) > [typeAnnotation!=null]'(node) {
|
|
22
19
|
context.modifyNodeInPlace(node, {
|
|
23
20
|
typeAnnotation: null
|
|
24
21
|
});
|
|
25
22
|
}
|
|
26
|
-
|
|
27
23
|
};
|
|
28
24
|
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
exports.default = _default;
|
|
25
|
+
});
|