flow-upgrade 2.5.0 → 2.6.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 CHANGED
@@ -105,3 +105,11 @@ 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`
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _Types = require("../Types");
9
+
10
+ var _hermesTransform = require("hermes-transform");
11
+
12
+ function eliminateAbstractComponent(node) {
13
+ const {
14
+ id: maybeQualifiedIdentifier,
15
+ typeParameters
16
+ } = node;
17
+
18
+ if (maybeQualifiedIdentifier.type === 'QualifiedTypeIdentifier' && maybeQualifiedIdentifier.qualification.name === 'React' && maybeQualifiedIdentifier.id.name === 'AbstractComponent' && typeParameters != null) {
19
+ const [config, instance, renders] = typeParameters.params;
20
+
21
+ if (renders != null) {
22
+ return null;
23
+ }
24
+
25
+ if (instance == null || instance.type === 'MixedTypeAnnotation') {
26
+ return _hermesTransform.t.GenericTypeAnnotation({
27
+ id: _hermesTransform.t.QualifiedTypeIdentifier({
28
+ qualification: _hermesTransform.t.Identifier({
29
+ name: 'React'
30
+ }),
31
+ id: _hermesTransform.t.Identifier({
32
+ name: 'ComponentType'
33
+ })
34
+ }),
35
+ typeParameters: _hermesTransform.t.TypeParameterInstantiation({
36
+ params: [config]
37
+ })
38
+ });
39
+ }
40
+
41
+ return null;
42
+ }
43
+
44
+ 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
+ return typeParameters.params[0].typeParameters.params[0];
46
+ }
47
+
48
+ 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
+ return typeParameters.params[0].typeParameters.params[1];
50
+ }
51
+
52
+ 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
+ return _hermesTransform.t.MixedTypeAnnotation({});
54
+ }
55
+
56
+ return null;
57
+ }
58
+
59
+ var _default = (0, _Types.codemod)({
60
+ title: 'Eliminate `React.AbstractComponent<...>`',
61
+ describe: `
62
+ - \`React.AbstractComponent<Props>\` -> \`React.ComponentType<Props>\`
63
+ - \`React.ElementConfig<React.AbstractComponent<Props, Instance>>\` -> \`Props\`
64
+ - \`React.ElementRef<React.AbstractComponent<Props, Instance>>\` -> \`Instance\`
65
+ - \`React.ElementRef<React.AbstractComponent<Props>\` -> \`mixed\``,
66
+ transform: context => {
67
+ return {
68
+ GenericTypeAnnotation(node) {
69
+ const replacement = eliminateAbstractComponent(node);
70
+
71
+ if (replacement) {
72
+ context.replaceNode(node, replacement, {
73
+ keepComments: true
74
+ });
75
+ }
76
+ }
77
+
78
+ };
79
+ }
80
+ });
81
+
82
+ exports.default = _default;
@@ -10,6 +10,7 @@ var _hermesTransform = require("hermes-transform");
10
10
  var _Types = require("../Types");
11
11
 
12
12
  var _default = (0, _Types.codemod)({
13
+ title: 'Replace $TEMPORARY$ types',
13
14
  describe: ['Converts:', ' - `$TEMPORARY$object<{props}>` to `$ReadOnly<{props}>`', ' - `$TEMPORARY$array<T>` to `$ReadOnlyArray<T>`', ' - `$TEMPORARY$number<42>` annotations to `number`', ' - `$TEMPORARY$string<"foo">` annotations to `string`'].join('\n'),
14
15
  transform: context => {
15
16
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-upgrade",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "A utility for upgrading your codebase to the latest version of Flow.",
5
5
  "engines": {
6
6
  "node": ">=14"