@openrewrite/recipes-react 0.28.0 → 0.29.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/change-react-type.d.ts +14 -0
- package/dist/change-react-type.d.ts.map +1 -0
- package/dist/change-react-type.js +41 -0
- package/dist/change-react-type.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -2
- package/dist/index.js.map +1 -1
- package/dist/react18/add-children-to-props.d.ts.map +1 -1
- package/dist/react18/add-children-to-props.js +24 -6
- package/dist/react18/add-children-to-props.js.map +1 -1
- package/dist/react19/deprecated-prop-types-types.d.ts +23 -0
- package/dist/react19/deprecated-prop-types-types.d.ts.map +1 -0
- package/dist/react19/deprecated-prop-types-types.js +191 -0
- package/dist/react19/deprecated-prop-types-types.js.map +1 -0
- package/dist/react19/deprecated-react-child.d.ts +8 -0
- package/dist/react19/deprecated-react-child.d.ts.map +1 -0
- package/dist/react19/deprecated-react-child.js +91 -0
- package/dist/react19/deprecated-react-child.js.map +1 -0
- package/dist/react19/deprecated-react-fragment.d.ts +8 -0
- package/dist/react19/deprecated-react-fragment.d.ts.map +1 -0
- package/dist/react19/deprecated-react-fragment.js +92 -0
- package/dist/react19/deprecated-react-fragment.js.map +1 -0
- package/dist/react19/deprecated-react-node-array.d.ts +8 -0
- package/dist/react19/deprecated-react-node-array.d.ts.map +1 -0
- package/dist/react19/deprecated-react-node-array.js +92 -0
- package/dist/react19/deprecated-react-node-array.js.map +1 -0
- package/dist/react19/deprecated-react-text.d.ts +8 -0
- package/dist/react19/deprecated-react-text.d.ts.map +1 -0
- package/dist/react19/deprecated-react-text.js +91 -0
- package/dist/react19/deprecated-react-text.js.map +1 -0
- package/dist/react19/deprecated-react-types.d.ts.map +1 -1
- package/dist/react19/deprecated-react-types.js +3 -104
- package/dist/react19/deprecated-react-types.js.map +1 -1
- package/dist/react19/refobject-defaults.d.ts +13 -0
- package/dist/react19/refobject-defaults.d.ts.map +1 -0
- package/dist/react19/refobject-defaults.js +152 -0
- package/dist/react19/refobject-defaults.js.map +1 -0
- package/dist/react19/remove-react-fc.js +3 -2
- package/dist/react19/remove-react-fc.js.map +1 -1
- package/dist/types/imports.d.ts +31 -0
- package/dist/types/imports.d.ts.map +1 -0
- package/dist/types/imports.js +385 -0
- package/dist/types/imports.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +33 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/module.d.ts +6 -0
- package/dist/types/module.d.ts.map +1 -0
- package/dist/types/module.js +5 -0
- package/dist/types/module.js.map +1 -0
- package/dist/types/re-export.d.ts +5 -0
- package/dist/types/re-export.d.ts.map +1 -0
- package/dist/types/re-export.js +12 -0
- package/dist/types/re-export.js.map +1 -0
- package/dist/types/reference.d.ts +20 -0
- package/dist/types/reference.d.ts.map +1 -0
- package/dist/types/reference.js +161 -0
- package/dist/types/reference.js.map +1 -0
- package/dist/types/rename.d.ts +10 -0
- package/dist/types/rename.d.ts.map +1 -0
- package/dist/types/rename.js +136 -0
- package/dist/types/rename.js.map +1 -0
- package/dist/types/replace.d.ts +8 -0
- package/dist/types/replace.d.ts.map +1 -0
- package/dist/types/replace.js +122 -0
- package/dist/types/replace.js.map +1 -0
- package/dist/util/java-recipe-proxy.d.ts +1 -0
- package/dist/util/java-recipe-proxy.d.ts.map +1 -1
- package/dist/util/java-recipe-proxy.js +3 -1
- package/dist/util/java-recipe-proxy.js.map +1 -1
- package/package.json +2 -2
- package/src/change-react-type.ts +32 -0
- package/src/index.ts +21 -0
- package/src/react18/add-children-to-props.ts +22 -7
- package/src/react19/deprecated-prop-types-types.ts +170 -0
- package/src/react19/deprecated-react-child.ts +67 -0
- package/src/react19/deprecated-react-fragment.ts +74 -0
- package/src/react19/deprecated-react-node-array.ts +74 -0
- package/src/react19/deprecated-react-text.ts +66 -0
- package/src/react19/deprecated-react-types.ts +4 -95
- package/src/react19/refobject-defaults.ts +120 -0
- package/src/react19/remove-react-fc.ts +3 -3
- package/src/types/imports.ts +396 -0
- package/src/types/index.ts +21 -0
- package/src/types/module.ts +10 -0
- package/src/types/re-export.ts +14 -0
- package/src/types/reference.ts +186 -0
- package/src/types/rename.ts +112 -0
- package/src/types/replace.ts +123 -0
- package/src/util/java-recipe-proxy.ts +3 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.replaceType = replaceType;
|
|
13
|
+
exports.flattenUnion = flattenUnion;
|
|
14
|
+
exports.unionWith = unionWith;
|
|
15
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
16
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
17
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
18
|
+
const rename_1 = require("./rename");
|
|
19
|
+
function replaceType(visitor, cursor, ref, tree, code) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
const parent = (_a = cursor.parentTree()) === null || _a === void 0 ? void 0 : _a.value;
|
|
23
|
+
const optional = tree.markers.markers.some(m => m.kind === javascript_1.JS.Markers.Optional);
|
|
24
|
+
const heritage = (parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.ClassDeclaration &&
|
|
25
|
+
((_c = (_b = parent.implements) === null || _b === void 0 ? void 0 : _b.elements.some(e => e.element.id === tree.id)) !== null && _c !== void 0 ? _c : false);
|
|
26
|
+
let replacement = yield parseType(code, heritage);
|
|
27
|
+
if (looseTypes.has(replacement.kind) && (optional || needsParentheses(parent, tree))) {
|
|
28
|
+
replacement = yield parseType(`(${code})`);
|
|
29
|
+
}
|
|
30
|
+
if (!ref.qualifier)
|
|
31
|
+
(0, rename_1.unbind)(visitor, ref);
|
|
32
|
+
const comments = innerComments(tree);
|
|
33
|
+
const prefix = comments.length ? Object.assign(Object.assign({}, tree.prefix), { comments: [...tree.prefix.comments, ...comments] }) : tree.prefix;
|
|
34
|
+
return Object.assign(Object.assign({}, replacement), { prefix, markers: tree.markers });
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function flattenUnion(union) {
|
|
38
|
+
return union.types.some(t => t.element.kind === javascript_1.JS.Kind.Union) ? Object.assign(Object.assign({}, union), { types: union.types.flatMap(unionMembers) }) : union;
|
|
39
|
+
}
|
|
40
|
+
function unionWith(type, member) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const added = yield parseType(member);
|
|
43
|
+
if (type.kind === javascript_1.JS.Kind.Union) {
|
|
44
|
+
const union = type;
|
|
45
|
+
const last = union.types[union.types.length - 1];
|
|
46
|
+
return Object.assign(Object.assign({}, union), { types: [...union.types.slice(0, -1), Object.assign(Object.assign({}, last), { after: java_1.singleSpace }), Object.assign(Object.assign({}, last), { element: Object.assign(Object.assign({}, added), { prefix: java_1.singleSpace }) })] });
|
|
47
|
+
}
|
|
48
|
+
const parenthesized = type.kind === javascript_1.JS.Kind.FunctionType || type.kind === javascript_1.JS.Kind.ConditionalType;
|
|
49
|
+
const union = yield parseType(`${parenthesized ? '(T)' : 'T'} | ${member}`);
|
|
50
|
+
const [first, ...rest] = union.types;
|
|
51
|
+
const inner = Object.assign(Object.assign({}, type), { prefix: java_1.emptySpace });
|
|
52
|
+
const element = parenthesized ? withParenthesized(first.element, inner) : inner;
|
|
53
|
+
return Object.assign(Object.assign({}, union), { prefix: type.prefix, types: [Object.assign(Object.assign({}, first), { element }), ...rest] });
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function withParenthesized(tree, inner) {
|
|
57
|
+
const parentheses = tree.parenthesizedType;
|
|
58
|
+
return Object.assign(Object.assign({}, tree), { parenthesizedType: Object.assign(Object.assign({}, parentheses), { tree: Object.assign(Object.assign({}, parentheses.tree), { element: inner }) }) });
|
|
59
|
+
}
|
|
60
|
+
const looseTypes = new Set([javascript_1.JS.Kind.Union, javascript_1.JS.Kind.Intersection, javascript_1.JS.Kind.FunctionType, javascript_1.JS.Kind.ConditionalType,
|
|
61
|
+
javascript_1.JS.Kind.TypeOperator, javascript_1.JS.Kind.InferType]);
|
|
62
|
+
function needsParentheses(parent, child) {
|
|
63
|
+
switch (parent === null || parent === void 0 ? void 0 : parent.kind) {
|
|
64
|
+
case java_1.J.Kind.ArrayType:
|
|
65
|
+
case javascript_1.JS.Kind.Intersection:
|
|
66
|
+
case javascript_1.JS.Kind.TypeOperator:
|
|
67
|
+
return true;
|
|
68
|
+
case javascript_1.JS.Kind.IndexedAccessType:
|
|
69
|
+
return parent.objectType.id === child.id;
|
|
70
|
+
default:
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function innerComments(tree) {
|
|
75
|
+
const found = [];
|
|
76
|
+
const collect = (node, top) => {
|
|
77
|
+
if (!node || typeof node !== 'object')
|
|
78
|
+
return;
|
|
79
|
+
if (Array.isArray(node))
|
|
80
|
+
return node.forEach(n => collect(n, false));
|
|
81
|
+
for (const [key, value] of Object.entries(node)) {
|
|
82
|
+
if (key === 'type' || key === 'markers' || top && key === 'prefix')
|
|
83
|
+
continue;
|
|
84
|
+
if ((value === null || value === void 0 ? void 0 : value.kind) === java_1.J.Kind.Space)
|
|
85
|
+
found.push(...value.comments);
|
|
86
|
+
else
|
|
87
|
+
collect(value, false);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
collect(tree, true);
|
|
91
|
+
return found;
|
|
92
|
+
}
|
|
93
|
+
const parser = new javascript_1.JavaScriptParser();
|
|
94
|
+
function parseType(code_1) {
|
|
95
|
+
return __awaiter(this, arguments, void 0, function* (code, heritage = false) {
|
|
96
|
+
const text = heritage ? `interface T extends ${code} {}` : `type T = ${code};`;
|
|
97
|
+
const statement = (yield parser.parseOnly({ text, sourcePath: 'type.ts' })).statements[0].element;
|
|
98
|
+
const type = heritage ? statement.implements.elements[0].element :
|
|
99
|
+
statement.initializer.element;
|
|
100
|
+
return Object.assign(Object.assign({}, withFreshIds(type)), { prefix: java_1.emptySpace });
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function unionMembers(member) {
|
|
104
|
+
if (member.element.kind !== javascript_1.JS.Kind.Union)
|
|
105
|
+
return [member];
|
|
106
|
+
const types = member.element.types;
|
|
107
|
+
return types.map((t, i) => (Object.assign(Object.assign({}, t), { element: i === 0 ? Object.assign(Object.assign({}, t.element), { prefix: member.element.prefix }) : t.element, after: i === types.length - 1 ? member.after : t.after })));
|
|
108
|
+
}
|
|
109
|
+
function withFreshIds(tree) {
|
|
110
|
+
if (Array.isArray(tree))
|
|
111
|
+
return tree.map(t => withFreshIds(t));
|
|
112
|
+
if (tree === null || typeof tree !== 'object')
|
|
113
|
+
return tree;
|
|
114
|
+
const copy = {};
|
|
115
|
+
for (const [key, value] of Object.entries(tree)) {
|
|
116
|
+
copy[key] = key === 'type' ? value : withFreshIds(value);
|
|
117
|
+
}
|
|
118
|
+
if (typeof copy.id === 'string' && copy.kind)
|
|
119
|
+
copy.id = (0, rewrite_1.randomId)();
|
|
120
|
+
return copy;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=replace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.js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,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IACxD,CAAC,CAAC;AACR,CAAC;AAED,SAAS,YAAY,CAAI,IAAO;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAM,CAAC;IACpE,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3D,MAAM,IAAI,GAAQ,EAAE,CAAC;IACrB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,OAAO,IAAI,CAAC,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI;QAAE,IAAI,CAAC,EAAE,GAAG,IAAA,kBAAQ,GAAE,CAAC;IACnE,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ExecutionContext, RecipeRef, ScanningRecipe, SourceFile, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
2
|
import { DelegatingRecipe } from "@openrewrite/rewrite/rpc";
|
|
3
3
|
export declare const treesOfType: (type: string) => RecipeRef;
|
|
4
|
+
export declare const manifestAndJavaScriptTrees: () => import("@openrewrite/rewrite").CompositePrecondition;
|
|
4
5
|
export declare function isNodeDependencyInput(path: string, includeInputs?: boolean): boolean;
|
|
5
6
|
export declare abstract class JavaDependencyRecipe extends ScanningRecipe<number> {
|
|
6
7
|
private readonly includePackageManagerInputs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"java-recipe-proxy.d.ts","sourceRoot":"","sources":["../../src/util/java-recipe-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAM,SAAS,EAAE,cAAc,EAAE,UAAU,EAAQ,WAAW,EAAC,MAAM,sBAAsB,CAAC;AACnI,OAAO,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAG1D,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,cAA0E,CAAC;
|
|
1
|
+
{"version":3,"file":"java-recipe-proxy.d.ts","sourceRoot":"","sources":["../../src/util/java-recipe-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAM,SAAS,EAAE,cAAc,EAAE,UAAU,EAAQ,WAAW,EAAC,MAAM,sBAAsB,CAAC;AACnI,OAAO,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAG1D,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,cAA0E,CAAC;AAYnH,eAAO,MAAM,0BAA0B,4DAA+F,CAAC;AAEvI,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,UAAQ,GAAG,OAAO,CAElF;AAMD,8BAAsB,oBAAqB,SAAQ,cAAc,CAAC,MAAM,CAAC;IAON,OAAO,CAAC,QAAQ,CAAC,2BAA2B;IAF3G,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAE1C,SAAS,aAAa,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAmB,2BAA2B,UAAQ;IAKnH,YAAY,IAAI,MAAM;IAIhB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IAKvE,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO;IAKjD,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO;IAMhC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IAI9D,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IAIxE,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAInE,UAAU,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAGzD"}
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.JavaDependencyRecipe = exports.treesOfType = void 0;
|
|
12
|
+
exports.JavaDependencyRecipe = exports.manifestAndJavaScriptTrees = exports.treesOfType = void 0;
|
|
13
13
|
exports.isNodeDependencyInput = isNodeDependencyInput;
|
|
14
14
|
const rewrite_1 = require("@openrewrite/rewrite");
|
|
15
15
|
const rpc_1 = require("@openrewrite/rewrite/rpc");
|
|
@@ -19,6 +19,8 @@ const NODE_MANIFESTS = /(^|\/)(package\.json|package-lock\.json|npm-shrinkwrap\.
|
|
|
19
19
|
const NODE_MANIFEST_TREES = ["org.openrewrite.json.tree.Json", "org.openrewrite.yaml.tree.Yaml", "org.openrewrite.text.PlainText"];
|
|
20
20
|
const NODE_INPUTS = /(^|\/)(\.npmrc|\.yarnrc(?:\.yml)?|bunfig\.toml|\.?pnpmfile\.cjs)$|\.patch$/;
|
|
21
21
|
const manifestTrees = () => (0, rewrite_1.or)(...NODE_MANIFEST_TREES.map(exports.treesOfType));
|
|
22
|
+
const manifestAndJavaScriptTrees = () => (0, rewrite_1.or)(...[...NODE_MANIFEST_TREES, "org.openrewrite.javascript.tree.JS"].map(exports.treesOfType));
|
|
23
|
+
exports.manifestAndJavaScriptTrees = manifestAndJavaScriptTrees;
|
|
22
24
|
function isNodeDependencyInput(path, includeInputs = false) {
|
|
23
25
|
return NODE_MANIFESTS.test(path) || includeInputs && NODE_INPUTS.test(path);
|
|
24
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"java-recipe-proxy.js","sourceRoot":"","sources":["../../src/util/java-recipe-proxy.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"java-recipe-proxy.js","sourceRoot":"","sources":["../../src/util/java-recipe-proxy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAkBA,sDAEC;AApBD,kDAAmI;AACnI,kDAA0D;AAGnD,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,mBAAS,CAAC,8CAA8C,EAAE,EAAC,IAAI,EAAC,CAAC,CAAC;AAAtG,QAAA,WAAW,eAA2F;AAGnH,MAAM,cAAc,GAAG,0HAA0H,CAAC;AAClJ,MAAM,mBAAmB,GAAG,CAAC,gCAAgC,EAAE,gCAAgC,EAAE,gCAAgC,CAAC,CAAC;AAGnI,MAAM,WAAW,GAAG,4EAA4E,CAAC;AAEjG,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,IAAA,YAAE,EAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,mBAAW,CAAC,CAAC,CAAC;AAGjE,MAAM,0BAA0B,GAAG,GAAG,EAAE,CAAC,IAAA,YAAE,EAAC,GAAG,CAAC,GAAG,mBAAmB,EAAE,oCAAoC,CAAC,CAAC,GAAG,CAAC,mBAAW,CAAC,CAAC,CAAC;AAA1H,QAAA,0BAA0B,8BAAgG;AAEvI,SAAgB,qBAAqB,CAAC,IAAY,EAAE,aAAa,GAAG,KAAK;IACrE,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,aAAa,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChF,CAAC;AAMD,MAAsB,oBAAqB,SAAQ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
+
"license": "Moderne Proprietary",
|
|
5
5
|
"description": "OpenRewrite recipes for React.",
|
|
6
6
|
"homepage": "https://github.com/openrewrite/rewrite",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {ExecutionContext, Option, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {onTypeScriptSources, react, renamingTypes} from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Before: `const Greeting: SFC<{name: string}> = …;`
|
|
6
|
+
* After: `const Greeting: FC<{name: string}> = …;`
|
|
7
|
+
*
|
|
8
|
+
* A stopgap until `org.openrewrite.javascript.change-import` covers what React's types need, then replace each
|
|
9
|
+
* use with it. As of `@openrewrite/rewrite` 8.110.0 that recipe leaves `React.SFC` through a default import
|
|
10
|
+
* (`import React from 'react'`), through the UMD global `React` with no import, and in `declare module` blocks;
|
|
11
|
+
* renaming onto a type the file already imports binds `import type { FC as SFC }` beside it; and it also edits
|
|
12
|
+
* JavaScript sources.
|
|
13
|
+
*/
|
|
14
|
+
export class ChangeReactType extends Recipe {
|
|
15
|
+
readonly name = "org.openrewrite.react.change-react-type";
|
|
16
|
+
readonly displayName = "Change a React type";
|
|
17
|
+
readonly description = "Renames a type exported by `react` to another `react` type, keeping its type arguments, through named, namespace, default and type-only imports, `import('react')` types, the `React` global and re-exports. Only references to React's own type are renamed.";
|
|
18
|
+
|
|
19
|
+
@Option({displayName: "Old type name", description: "The `react` type to rename.", example: "SFC"})
|
|
20
|
+
oldTypeName!: string;
|
|
21
|
+
|
|
22
|
+
@Option({displayName: "New type name", description: "The `react` type to rename it to.", example: "FC"})
|
|
23
|
+
newTypeName!: string;
|
|
24
|
+
|
|
25
|
+
constructor(options?: { oldTypeName?: string; newTypeName?: string }) {
|
|
26
|
+
super(options);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
30
|
+
return onTypeScriptSources(renamingTypes(react, new Map([[this.oldTypeName, this.newTypeName]])));
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,12 @@ import {FindDeprecatedReactDomAPIs} from './react19/find-deprecated-reactdom-api
|
|
|
18
18
|
import {FindContextConsumer} from './react19/find-context-consumer';
|
|
19
19
|
|
|
20
20
|
import {FindElementRef} from './react19/find-element-ref';
|
|
21
|
+
import {DeprecatedReactChild} from './react19/deprecated-react-child';
|
|
22
|
+
import {DeprecatedReactNodeArray} from './react19/deprecated-react-node-array';
|
|
23
|
+
import {DeprecatedReactFragment} from './react19/deprecated-react-fragment';
|
|
24
|
+
import {DeprecatedReactText} from './react19/deprecated-react-text';
|
|
25
|
+
import {RefObjectDefaults} from './react19/refobject-defaults';
|
|
26
|
+
import {DeprecatedPropTypesTypes} from './react19/deprecated-prop-types-types';
|
|
21
27
|
import {RemoveUnstableBatchedUpdates} from './react19/remove-unstable-batched-updates';
|
|
22
28
|
import {ReplaceCreateFactory} from './react19/replace-create-factory';
|
|
23
29
|
|
|
@@ -77,6 +83,7 @@ import {TranslateHardCodedStrings} from './i18n/translate-hard-coded-strings';
|
|
|
77
83
|
|
|
78
84
|
// General
|
|
79
85
|
import {SimplifyReactImports} from './simplify-react-imports';
|
|
86
|
+
import {ChangeReactType} from './change-react-type';
|
|
80
87
|
import {SimplifyObjectPatternProperty} from './simplify-object-pattern-property';
|
|
81
88
|
import {ChangeComponentPropValue} from './migration/change-component-prop-value';
|
|
82
89
|
|
|
@@ -120,6 +127,12 @@ export async function activate(marketplace: RecipeMarketplace) {
|
|
|
120
127
|
await marketplace.install(FindDeprecatedReactDomAPIs, React19);
|
|
121
128
|
await marketplace.install(FindContextConsumer, React19);
|
|
122
129
|
await marketplace.install(FindElementRef, React19);
|
|
130
|
+
await marketplace.install(DeprecatedReactChild, React19);
|
|
131
|
+
await marketplace.install(DeprecatedReactNodeArray, React19);
|
|
132
|
+
await marketplace.install(DeprecatedReactFragment, React19);
|
|
133
|
+
await marketplace.install(DeprecatedReactText, React19);
|
|
134
|
+
await marketplace.install(RefObjectDefaults, React19);
|
|
135
|
+
await marketplace.install(DeprecatedPropTypesTypes, React19);
|
|
123
136
|
await marketplace.install(RemoveUnstableBatchedUpdates, React19);
|
|
124
137
|
await marketplace.install(ReplaceCreateFactory, React19);
|
|
125
138
|
|
|
@@ -186,6 +199,7 @@ export async function activate(marketplace: RecipeMarketplace) {
|
|
|
186
199
|
|
|
187
200
|
// General
|
|
188
201
|
await marketplace.install(SimplifyReactImports, React);
|
|
202
|
+
await marketplace.install(ChangeReactType, ReactMigrate);
|
|
189
203
|
await marketplace.install(SimplifyObjectPatternProperty, JavaScriptCleanup);
|
|
190
204
|
await marketplace.install(ChangeComponentPropValue, ReactMigration);
|
|
191
205
|
}
|
|
@@ -206,6 +220,12 @@ export {FindLegacyContextAPI} from './react19/find-legacy-context-api';
|
|
|
206
220
|
export {FindDeprecatedReactDomAPIs} from './react19/find-deprecated-reactdom-apis';
|
|
207
221
|
export {FindContextConsumer} from './react19/find-context-consumer';
|
|
208
222
|
export {FindElementRef} from './react19/find-element-ref';
|
|
223
|
+
export {DeprecatedReactChild} from './react19/deprecated-react-child';
|
|
224
|
+
export {DeprecatedReactNodeArray} from './react19/deprecated-react-node-array';
|
|
225
|
+
export {DeprecatedReactFragment} from './react19/deprecated-react-fragment';
|
|
226
|
+
export {DeprecatedReactText} from './react19/deprecated-react-text';
|
|
227
|
+
export {RefObjectDefaults} from './react19/refobject-defaults';
|
|
228
|
+
export {AddTypesPropTypes, DeprecatedPropTypesTypes} from './react19/deprecated-prop-types-types';
|
|
209
229
|
export {RemoveUnstableBatchedUpdates} from './react19/remove-unstable-batched-updates';
|
|
210
230
|
export {ReplaceCreateFactory} from './react19/replace-create-factory';
|
|
211
231
|
|
|
@@ -264,5 +284,6 @@ export * from './mui';
|
|
|
264
284
|
|
|
265
285
|
// General
|
|
266
286
|
export {SimplifyReactImports} from './simplify-react-imports';
|
|
287
|
+
export {ChangeReactType} from './change-react-type';
|
|
267
288
|
export {SimplifyObjectPatternProperty} from './simplify-object-pattern-property';
|
|
268
289
|
export {ChangeComponentPropValue} from './migration/change-component-prop-value';
|
|
@@ -65,16 +65,31 @@ async function classReadsChildren(body: J): Promise<boolean> {
|
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Whether a component reads `children`: by destructuring its first parameter, through `props.children`,
|
|
70
|
+
* or by destructuring `props` in its body, as `const { children } = props`.
|
|
71
|
+
*/
|
|
69
72
|
async function readsChildren(param: J.VariableDeclarations | undefined, body: J | undefined): Promise<boolean> {
|
|
70
73
|
const name = param?.variables[0]?.element.name;
|
|
71
74
|
if (!name) return false;
|
|
72
|
-
if (name.kind
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
if (name.kind !== J.Kind.Identifier) return anyNode(name as unknown as J, n => isIdentifierNamed(n, 'children'));
|
|
76
|
+
const props = (name as J.Identifier).simpleName;
|
|
77
|
+
const patterns: J[] = [];
|
|
78
|
+
const direct = await anyNode(body, n => {
|
|
79
|
+
if (n.kind === J.Kind.FieldAccess) {
|
|
80
|
+
const fa = n as J.FieldAccess;
|
|
81
|
+
return isIdentifierNamed(fa.target, props) && fa.name.element.simpleName === 'children';
|
|
82
|
+
}
|
|
83
|
+
if (n.kind === J.Kind.VariableDeclarations) {
|
|
84
|
+
const v = (n as J.VariableDeclarations).variables[0]?.element;
|
|
85
|
+
const init = v?.initializer?.element;
|
|
86
|
+
if (v && v.name.kind !== J.Kind.Identifier && init && isIdentifierNamed(init, props)) patterns.push(v.name as unknown as J);
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
});
|
|
90
|
+
if (direct) return true;
|
|
91
|
+
for (const pattern of patterns) if (await anyNode(pattern, n => isIdentifierNamed(n, 'children'))) return true;
|
|
92
|
+
return false;
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
/** Names of locally declared props types that a component reads `children` from but does not declare. */
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {check, Cursor, ExecutionContext, Recipe, SourceFile, Tree, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {Expression, J} from "@openrewrite/rewrite/java";
|
|
3
|
+
import {
|
|
4
|
+
AddDependencyOptions,
|
|
5
|
+
compilationUnitOf,
|
|
6
|
+
ImportStyle,
|
|
7
|
+
JavaScriptParser,
|
|
8
|
+
JavaScriptVisitor,
|
|
9
|
+
JS,
|
|
10
|
+
maybeBind,
|
|
11
|
+
maybeRebind,
|
|
12
|
+
moduleBindings,
|
|
13
|
+
namesUsedIn
|
|
14
|
+
} from "@openrewrite/rewrite/javascript";
|
|
15
|
+
import {importsOf, isModule, keepMovedTypesTypeOnly, Module, onTypeScriptSources, react, typeReferenceOf} from "../types";
|
|
16
|
+
import {JavaDependencyRecipe, manifestAndJavaScriptTrees} from "../util/java-recipe-proxy";
|
|
17
|
+
|
|
18
|
+
const propTypes: Module = {module: 'prop-types'};
|
|
19
|
+
|
|
20
|
+
const MOVED = ['Requireable', 'Validator', 'ValidationMap', 'WeakValidationMap'];
|
|
21
|
+
|
|
22
|
+
const TYPES_PROP_TYPES: AddDependencyOptions = {packageName: '@types/prop-types', version: '^15.7.15', scope: 'devDependencies'};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Before: `import {Validator} from 'react';`
|
|
26
|
+
* After: `import type {Validator} from 'prop-types';`
|
|
27
|
+
*
|
|
28
|
+
* @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-deprecated-typescript-types
|
|
29
|
+
*/
|
|
30
|
+
export class DeprecatedPropTypesTypes extends Recipe {
|
|
31
|
+
readonly name = "org.openrewrite.react.19.deprecated-prop-types-types";
|
|
32
|
+
readonly displayName = "Import the prop-types types from `prop-types`";
|
|
33
|
+
readonly description = "Moves `Requireable`, `Validator`, `ValidationMap` and `WeakValidationMap`, which `@types/react` 19 no longer exports, from `react` to `prop-types` as type-only imports, and adds `@types/prop-types` to the packages they move in.";
|
|
34
|
+
|
|
35
|
+
private readonly dependency = new AddTypesPropTypes();
|
|
36
|
+
|
|
37
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
38
|
+
return onTypeScriptSources(movingPropTypesTypes());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async recipeList(): Promise<Recipe[]> {
|
|
42
|
+
return [this.dependency];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class AddTypesPropTypes extends JavaDependencyRecipe {
|
|
47
|
+
readonly name = "org.openrewrite.react.19.add-types-prop-types";
|
|
48
|
+
readonly displayName = "Add `@types/prop-types` where the prop-types types move to `prop-types`";
|
|
49
|
+
readonly description = "Adds `@types/prop-types` as a dev dependency to each package with a TypeScript source whose `Requireable`, `Validator`, `ValidationMap` or `WeakValidationMap` moves from `react` to `prop-types`, since `@types/react` 19 no longer depends on it.";
|
|
50
|
+
|
|
51
|
+
private readonly moving: string[] = [];
|
|
52
|
+
|
|
53
|
+
private readonly held: SourceFile[] = [];
|
|
54
|
+
|
|
55
|
+
constructor() {
|
|
56
|
+
super("org.openrewrite.javascript.AddDependency", TYPES_PROP_TYPES);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override initialValue(): number {
|
|
60
|
+
this.moving.length = 0;
|
|
61
|
+
this.held.length = 0;
|
|
62
|
+
return super.initialValue();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override async scanner(acc: number): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
66
|
+
const manifests = await super.scanner(acc);
|
|
67
|
+
const forecast = await onTypeScriptSources(movingPropTypesTypes());
|
|
68
|
+
const moving = this.moving;
|
|
69
|
+
return check(manifestAndJavaScriptTrees(), new class extends TreeVisitor<Tree, ExecutionContext> {
|
|
70
|
+
override async isAcceptable(): Promise<boolean> {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
override async visit<R extends Tree>(tree: Tree, ctx: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
|
|
75
|
+
if (tree.kind !== JS.Kind.CompilationUnit) return manifests.visit<R>(tree, ctx, parent);
|
|
76
|
+
if (await forecast.visit(tree, ctx) !== tree) moving.push((tree as JS.CompilationUnit).sourcePath);
|
|
77
|
+
return tree as R;
|
|
78
|
+
}
|
|
79
|
+
}());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected override scanned(manifest: SourceFile): boolean {
|
|
83
|
+
if (!isPackageJson(manifest.sourcePath)) return true;
|
|
84
|
+
this.held.push(manifest);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
override async generate(acc: number, ctx: ExecutionContext): Promise<SourceFile[]> {
|
|
89
|
+
const roots = this.held.map(manifest => packageRoot(manifest.sourcePath));
|
|
90
|
+
const owners = new Set(this.moving.map(path => roots.filter(root => path.startsWith(root)).sort((a, b) => b.length - a.length)[0]));
|
|
91
|
+
const scanner = await this.java.scanner(acc);
|
|
92
|
+
for (const manifest of this.held) {
|
|
93
|
+
if (owners.has(packageRoot(manifest.sourcePath))) await scanner.visit(manifest, ctx);
|
|
94
|
+
}
|
|
95
|
+
this.held.length = 0;
|
|
96
|
+
return super.generate(acc, ctx);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function isPackageJson(path: string): boolean {
|
|
101
|
+
return /(^|\/)package\.json$/.test(path) && !path.split('/').includes('node_modules');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function packageRoot(manifestPath: string): string {
|
|
105
|
+
return manifestPath.slice(0, -'package.json'.length);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function movingPropTypesTypes(): JavaScriptVisitor<ExecutionContext> {
|
|
109
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
110
|
+
private qualifier?: string;
|
|
111
|
+
private script = false;
|
|
112
|
+
|
|
113
|
+
override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
|
|
114
|
+
const names = namesUsedIn(cu);
|
|
115
|
+
if (!MOVED.some(member => names.has(member))) return cu;
|
|
116
|
+
this.qualifier = undefined;
|
|
117
|
+
this.script = !isModule(cu);
|
|
118
|
+
for (const member of MOVED) {
|
|
119
|
+
maybeRebind(this, {from: {module: react.module, member}, to: {module: propTypes.module, member}});
|
|
120
|
+
}
|
|
121
|
+
keepMovedTypesTypeOnly(this, cu, propTypes, MOVED);
|
|
122
|
+
return super.visitJsCompilationUnit(cu, ctx);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
override async visitFieldAccess(fieldAccess: J.FieldAccess, ctx: ExecutionContext): Promise<J | undefined> {
|
|
126
|
+
if (!this.readsMovedType(this.cursor, fieldAccess)) return super.visitFieldAccess(fieldAccess, ctx);
|
|
127
|
+
if (!this.script) return this.retargeted(fieldAccess);
|
|
128
|
+
const parent = this.cursor.parentTree()?.value as J | undefined;
|
|
129
|
+
const typeArgumentsFollow = parent?.kind === J.Kind.ParameterizedType && (parent as J.ParameterizedType).class === fieldAccess;
|
|
130
|
+
return typeArgumentsFollow ? fieldAccess : importTypeOf(fieldAccess, fieldAccess.name.element.simpleName);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
override async visitParameterizedType(type: J.ParameterizedType, ctx: ExecutionContext): Promise<J | undefined> {
|
|
134
|
+
const pt = await super.visitParameterizedType(type, ctx) as J.ParameterizedType;
|
|
135
|
+
if (pt.class !== type.class || pt.class.kind !== J.Kind.FieldAccess ||
|
|
136
|
+
!this.readsMovedType(new Cursor(pt.class, this.cursor), pt.class as J.FieldAccess)) return pt;
|
|
137
|
+
const fieldAccess = pt.class as J.FieldAccess;
|
|
138
|
+
return this.script ? importTypeOf(pt, fieldAccess.name.element.simpleName, pt.typeParameters) :
|
|
139
|
+
{...pt, class: this.retargeted(fieldAccess)} as J.ParameterizedType;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private readsMovedType(cursor: Cursor, fieldAccess: J.FieldAccess): boolean {
|
|
143
|
+
const ref = typeReferenceOf(cursor, fieldAccess, react);
|
|
144
|
+
return ref?.qualifier !== undefined && !ref.importScope && MOVED.includes(ref.member);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private retargeted(fieldAccess: J.FieldAccess): J {
|
|
148
|
+
const cu = compilationUnitOf(this.cursor)!;
|
|
149
|
+
this.qualifier ??= importsOf(cu, propTypes).qualifiers.values().next().value ??
|
|
150
|
+
(moduleBindings(this).bindingOf(propTypes.module) === undefined ? maybeBind(this, {
|
|
151
|
+
module: propTypes.module, member: '*', preferredName: 'PropTypes', typeOnly: true,
|
|
152
|
+
onlyIfReferenced: false, style: ImportStyle.ES6Namespace
|
|
153
|
+
}) : undefined);
|
|
154
|
+
if (this.qualifier) {
|
|
155
|
+
return {...fieldAccess, target: {...fieldAccess.target, simpleName: this.qualifier, type: undefined} as J.Identifier} as J.FieldAccess;
|
|
156
|
+
}
|
|
157
|
+
const name = fieldAccess.name.element;
|
|
158
|
+
const local = maybeBind(this, {module: propTypes.module, member: name.simpleName, typeOnly: true, onlyIfReferenced: false});
|
|
159
|
+
return local ? {...name, prefix: fieldAccess.prefix, markers: fieldAccess.markers, simpleName: local, type: undefined} as J.Identifier : fieldAccess;
|
|
160
|
+
}
|
|
161
|
+
}();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const parser = new JavaScriptParser();
|
|
165
|
+
|
|
166
|
+
async function importTypeOf(like: J, member: string, typeArguments?: J.Container<Expression>): Promise<JS.ImportType> {
|
|
167
|
+
const parsed = await parser.parseOnly({text: `type T = import('${propTypes.module}').${member};`, sourcePath: 'import-type.ts'}) as JS.CompilationUnit;
|
|
168
|
+
const importType = (parsed.statements[0].element as JS.TypeDeclaration).initializer.element as JS.ImportType;
|
|
169
|
+
return {...importType, prefix: like.prefix, markers: like.markers, typeArguments};
|
|
170
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
3
|
+
import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
4
|
+
import {
|
|
5
|
+
dropImport,
|
|
6
|
+
importsMember,
|
|
7
|
+
importTypeReferenceOf,
|
|
8
|
+
inTypePosition,
|
|
9
|
+
markReExport,
|
|
10
|
+
onTypeScriptSources,
|
|
11
|
+
react,
|
|
12
|
+
replaceType,
|
|
13
|
+
typeName,
|
|
14
|
+
typeReferenceOf,
|
|
15
|
+
flattenUnion
|
|
16
|
+
} from "../types";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Before: `interface Props { icons: ReactChild[] }`
|
|
20
|
+
* After: `interface Props { icons: (ReactElement | number | string)[] }`
|
|
21
|
+
*
|
|
22
|
+
* @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-deprecated-typescript-types
|
|
23
|
+
*/
|
|
24
|
+
export class DeprecatedReactChild extends Recipe {
|
|
25
|
+
readonly name = "org.openrewrite.react.19.deprecated-react-child";
|
|
26
|
+
readonly displayName = "Replace `ReactChild` with `ReactElement | number | string`";
|
|
27
|
+
readonly description = "Replaces React's `ReactChild` type, removed in `@types/react` 19, with `ReactElement | number | string`, parenthesized where needed.";
|
|
28
|
+
|
|
29
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
30
|
+
return onTypeScriptSources(new class extends JavaScriptVisitor<ExecutionContext> {
|
|
31
|
+
override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
|
|
32
|
+
const visited = await super.visitJsCompilationUnit(cu, ctx);
|
|
33
|
+
if (importsMember(cu, react, 'ReactChild')) dropImport(this, react, 'ReactChild');
|
|
34
|
+
return visited;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override async visitExportSpecifier(specifier: JS.ExportSpecifier): Promise<J | undefined> {
|
|
38
|
+
return markReExport(this.cursor, specifier, react, 'ReactChild');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override async visitIdentifier(identifier: J.Identifier, ctx: ExecutionContext): Promise<J | undefined> {
|
|
42
|
+
return this.replace(await super.visitIdentifier(identifier, ctx) as J.Identifier);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override async visitFieldAccess(fieldAccess: J.FieldAccess, ctx: ExecutionContext): Promise<J | undefined> {
|
|
46
|
+
return typeReferenceOf(this.cursor, fieldAccess, react) ? this.replace(fieldAccess) : super.visitFieldAccess(fieldAccess, ctx);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override async visitImportType(importType: JS.ImportType, ctx: ExecutionContext): Promise<J | undefined> {
|
|
50
|
+
const visited = await super.visitImportType(importType, ctx) as JS.ImportType;
|
|
51
|
+
const ref = importTypeReferenceOf(visited, react);
|
|
52
|
+
if (ref?.member !== 'ReactChild' || !inTypePosition(this.cursor)) return visited;
|
|
53
|
+
return replaceType(this, this.cursor, ref, visited, `${typeName(this, this.cursor, ref, 'ReactElement')} | number | string`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override async visitUnion(union: JS.Union, ctx: ExecutionContext): Promise<J | undefined> {
|
|
57
|
+
return flattenUnion(await super.visitUnion(union, ctx) as JS.Union);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private async replace(name: J.Identifier | J.FieldAccess): Promise<J> {
|
|
61
|
+
const ref = typeReferenceOf(this.cursor, name, react);
|
|
62
|
+
if (ref?.member !== 'ReactChild' || !inTypePosition(this.cursor)) return name;
|
|
63
|
+
return replaceType(this, this.cursor, ref, name, `${typeName(this, this.cursor, ref, 'ReactElement')} | number | string`);
|
|
64
|
+
}
|
|
65
|
+
}());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {J, Type} from "@openrewrite/rewrite/java";
|
|
3
|
+
import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
4
|
+
import {
|
|
5
|
+
dropImport,
|
|
6
|
+
globalTypeName,
|
|
7
|
+
importsMember,
|
|
8
|
+
importTypeReferenceOf,
|
|
9
|
+
inTypePosition,
|
|
10
|
+
markReExport,
|
|
11
|
+
onTypeScriptSources,
|
|
12
|
+
react,
|
|
13
|
+
replaceType,
|
|
14
|
+
typeName,
|
|
15
|
+
TypeReference,
|
|
16
|
+
typeReferenceOf
|
|
17
|
+
} from "../types";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Before: `interface Props { rows: ReactFragment }`
|
|
21
|
+
* After: `interface Props { rows: Iterable<ReactNode> }`
|
|
22
|
+
*
|
|
23
|
+
* @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-deprecated-typescript-types
|
|
24
|
+
*/
|
|
25
|
+
export class DeprecatedReactFragment extends Recipe {
|
|
26
|
+
readonly name = "org.openrewrite.react.19.deprecated-react-fragment";
|
|
27
|
+
readonly displayName = "Replace `ReactFragment` with `Iterable<ReactNode>`";
|
|
28
|
+
readonly description = "Replaces React's `ReactFragment` type, removed in `@types/react` 19, with `Iterable<ReactNode>`, or with `ReactNode` where the installed `@types/react` 16 or 17 still declares it as a `{}` union that takes any element.";
|
|
29
|
+
|
|
30
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
31
|
+
return onTypeScriptSources(new class extends JavaScriptVisitor<ExecutionContext> {
|
|
32
|
+
override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
|
|
33
|
+
const visited = await super.visitJsCompilationUnit(cu, ctx);
|
|
34
|
+
if (importsMember(cu, react, 'ReactFragment')) dropImport(this, react, 'ReactFragment');
|
|
35
|
+
return visited;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
override async visitExportSpecifier(specifier: JS.ExportSpecifier): Promise<J | undefined> {
|
|
39
|
+
return markReExport(this.cursor, specifier, react, 'ReactFragment');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
override async visitIdentifier(identifier: J.Identifier, ctx: ExecutionContext): Promise<J | undefined> {
|
|
43
|
+
return this.replace(await super.visitIdentifier(identifier, ctx) as J.Identifier);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override async visitFieldAccess(fieldAccess: J.FieldAccess, ctx: ExecutionContext): Promise<J | undefined> {
|
|
47
|
+
return typeReferenceOf(this.cursor, fieldAccess, react) ? this.replace(fieldAccess) : super.visitFieldAccess(fieldAccess, ctx);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override async visitImportType(importType: JS.ImportType, ctx: ExecutionContext): Promise<J | undefined> {
|
|
51
|
+
const visited = await super.visitImportType(importType, ctx) as JS.ImportType;
|
|
52
|
+
const ref = importTypeReferenceOf(visited, react);
|
|
53
|
+
if (ref?.member !== 'ReactFragment' || !inTypePosition(this.cursor)) return visited;
|
|
54
|
+
return replaceType(this, this.cursor, ref, visited, this.fragment(ref, visited.qualifier!.element as J.Identifier));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private fragment(ref: TypeReference, name: J.Identifier | J.FieldAccess): string {
|
|
58
|
+
const node = typeName(this, this.cursor, ref, 'ReactNode');
|
|
59
|
+
return takesAnyObject(name) ? node : `${globalTypeName(this.cursor, 'Iterable')}<${node}>`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private async replace(name: J.Identifier | J.FieldAccess): Promise<J> {
|
|
63
|
+
const ref = typeReferenceOf(this.cursor, name, react);
|
|
64
|
+
if (ref?.member !== 'ReactFragment' || !inTypePosition(this.cursor)) return name;
|
|
65
|
+
return replaceType(this, this.cursor, ref, name, this.fragment(ref, name));
|
|
66
|
+
}
|
|
67
|
+
}());
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function takesAnyObject(name: J.Identifier | J.FieldAccess): boolean {
|
|
72
|
+
const type = name.kind === J.Kind.FieldAccess ? (name as J.FieldAccess).type : (name as J.Identifier).type;
|
|
73
|
+
return Type.isUnion(type) && type.bounds.some(bound => Type.isClass(bound) && bound.fullyQualifiedName === '{}');
|
|
74
|
+
}
|