flow-upgrade 2.3.0 → 2.4.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
@@ -93,3 +93,8 @@ Run with `yarn run flow-codemod convertShapeToPartial`.
93
93
  Converts usages of the old casting syntax `(x: T)` to the new casting syntax `x as T`.
94
94
 
95
95
  Run with `yarn run flow-codemod typeCastToAsExpression`.
96
+
97
+ ### Migrate internal Flow types for React to public-facing ones
98
+ Converts usages of the internal React types like `React$Node` to public facing ones like `React.Node`.
99
+
100
+ Run with `yarn run flow-codemod replaceReactDollarUtilityTypes`.
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _hermesTransform = require("hermes-transform");
9
+
10
+ var _Types = require("../Types");
11
+
12
+ const UTILITY_TYPES = new Set(['React$ComponentType', 'React$AbstractComponent', 'React$Element', 'React$MixedElement', 'React$ElementType', 'React$Key', 'React$Ref', 'React$RefSetter', 'React$Node', 'React$Context', 'React$Portal', 'React$ElementProps', 'React$ElementConfig', 'React$ElementRef', 'React$Config', 'React$Config', 'React$RefObject']);
13
+
14
+ var _default = (0, _Types.codemod)({
15
+ title: 'Replace React$SomeUtilityType with React.SomeUtilityType.',
16
+ transform: context => {
17
+ return {
18
+ GenericTypeAnnotation(node) {
19
+ if (typeof node.id.name !== 'string') {
20
+ return;
21
+ }
22
+
23
+ const utilTypeName = node.id.name;
24
+
25
+ if (!UTILITY_TYPES.has(utilTypeName)) {
26
+ return;
27
+ }
28
+
29
+ const newNode = _hermesTransform.t.GenericTypeAnnotation({
30
+ id: _hermesTransform.t.QualifiedTypeIdentifier({
31
+ id: _hermesTransform.t.Identifier({
32
+ name: utilTypeName.substring('React$'.length)
33
+ }),
34
+ qualification: _hermesTransform.t.Identifier({
35
+ name: 'React'
36
+ })
37
+ }),
38
+ typeParameters: node.typeParameters
39
+ });
40
+
41
+ context.replaceNode(node, newNode);
42
+ }
43
+
44
+ };
45
+ }
46
+ });
47
+
48
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-upgrade",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "A utility for upgrading your codebase to the latest version of Flow.",
5
5
  "engines": {
6
6
  "node": ">=14"
@@ -30,15 +30,15 @@
30
30
  "homepage": "https://github.com/facebook/flow/tree/master/packages/flow-upgrade#readme",
31
31
  "dependencies": {
32
32
  "@babel/highlight": "^7.18.6",
33
- "babel-plugin-syntax-hermes-parser": "0.19.0",
33
+ "babel-plugin-syntax-hermes-parser": "0.23.0",
34
34
  "chalk": "^2.0.1",
35
35
  "fs-extra": "10.1.0",
36
- "hermes-estree": "0.19.0",
37
- "hermes-parser": "0.19.0",
38
- "hermes-transform": "0.19.0",
36
+ "hermes-estree": "0.23.0",
37
+ "hermes-parser": "0.23.0",
38
+ "hermes-transform": "0.23.0",
39
39
  "klaw-sync": "^6.0.0",
40
40
  "ora": "^5.4.1",
41
- "prettier-plugin-hermes-parser": "0.19.0",
41
+ "prettier-plugin-hermes-parser": "0.23.0",
42
42
  "prompt-confirm": "^1.2.0",
43
43
  "semver": "^7.3.7",
44
44
  "yargs": "^17.0.1"