@openrewrite/recipes-react 0.28.0 → 0.31.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 +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +67 -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/react18/deprecated-react-type.d.ts +8 -0
- package/dist/react18/deprecated-react-type.d.ts.map +1 -0
- package/dist/react18/deprecated-react-type.js +29 -0
- package/dist/react18/deprecated-react-type.js.map +1 -0
- package/dist/react18/deprecated-sfc-element.d.ts +8 -0
- package/dist/react18/deprecated-sfc-element.d.ts.map +1 -0
- package/dist/react18/deprecated-sfc-element.js +29 -0
- package/dist/react18/deprecated-sfc-element.js.map +1 -0
- package/dist/react18/deprecated-sfc.d.ts +8 -0
- package/dist/react18/deprecated-sfc.d.ts.map +1 -0
- package/dist/react18/deprecated-sfc.js +29 -0
- package/dist/react18/deprecated-sfc.js.map +1 -0
- package/dist/react18/deprecated-stateless-component.d.ts +8 -0
- package/dist/react18/deprecated-stateless-component.d.ts.map +1 -0
- package/dist/react18/deprecated-stateless-component.js +29 -0
- package/dist/react18/deprecated-stateless-component.js.map +1 -0
- package/dist/react19/deprecated-legacy-ref.d.ts +8 -0
- package/dist/react19/deprecated-legacy-ref.d.ts.map +1 -0
- package/dist/react19/deprecated-legacy-ref.js +29 -0
- package/dist/react19/deprecated-legacy-ref.js.map +1 -0
- 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/deprecated-void-function-component.d.ts +8 -0
- package/dist/react19/deprecated-void-function-component.d.ts.map +1 -0
- package/dist/react19/deprecated-void-function-component.js +32 -0
- package/dist/react19/deprecated-void-function-component.js.map +1 -0
- 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/react19/replace-act-import.d.ts +8 -0
- package/dist/react19/replace-act-import.d.ts.map +1 -0
- package/dist/react19/replace-act-import.js +29 -0
- package/dist/react19/replace-act-import.js.map +1 -0
- package/dist/react19/replace-react-shallow-renderer.d.ts +8 -0
- package/dist/react19/replace-react-shallow-renderer.d.ts.map +1 -0
- package/dist/react19/replace-react-shallow-renderer.js +29 -0
- package/dist/react19/replace-react-shallow-renderer.js.map +1 -0
- package/dist/react19/replace-use-form-state.d.ts +8 -0
- package/dist/react19/replace-use-form-state.d.ts.map +1 -0
- package/dist/react19/replace-use-form-state.js +29 -0
- package/dist/react19/replace-use-form-state.js.map +1 -0
- 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 +48 -0
- package/src/migration/cra-to-vite/add-vite-config.ts +0 -1
- package/src/react18/add-children-to-props.ts +22 -7
- package/src/react18/deprecated-react-type.ts +19 -0
- package/src/react18/deprecated-sfc-element.ts +19 -0
- package/src/react18/deprecated-sfc.ts +19 -0
- package/src/react18/deprecated-stateless-component.ts +19 -0
- package/src/react19/deprecated-legacy-ref.ts +19 -0
- 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/deprecated-void-function-component.ts +22 -0
- package/src/react19/refobject-defaults.ts +120 -0
- package/src/react19/remove-react-fc.ts +3 -3
- package/src/react19/replace-act-import.ts +19 -0
- package/src/react19/replace-react-shallow-renderer.ts +19 -0
- package/src/react19/replace-use-form-state.ts +19 -0
- 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","sourceRoot":"","sources":["../../src/types/replace.ts"],"names":[],"mappings":";;;;;;;;;;;AAYA,kCAaC;AAMD,oCAEC;AAMD,8BAgBC;AAvDD,kDAAsD;AACtD,oDAAqE;AACrE,gEAAwF;AAExF,qCAAgC;AAQhC,SAAsB,WAAW,CAAC,OAA+B,EAAE,MAAc,EAAE,GAAkB,EAAE,IAAO,EAAE,IAAY;;;QACxH,MAAM,MAAM,GAAG,MAAA,MAAM,CAAC,UAAU,EAAE,0CAAE,KAAsB,CAAC;QAC3D,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChF,MAAM,QAAQ,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,MAAK,QAAC,CAAC,IAAI,CAAC,gBAAgB;YACrD,CAAC,MAAA,MAAC,MAA6B,CAAC,UAAU,0CAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,mCAAI,KAAK,CAAC,CAAC;QACvG,IAAI,WAAW,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAClD,IAAI,UAAU,CAAC,GAAG,CAAC,WAAW,C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"@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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,CAAC;aAAA;SACJ,EAAE,CAAC;QAIJ,IAAI,aAAa;YAAE,OAAO,SAAS,CAAC;QACpC,OAAO,MAAM,IAAA,eAAK,EAAC,aAAa,EAAE,EAAE,SAAS,CAAC,CAAC;IACnD,CAAC;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrewrite/recipes-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"license": "Moderne
|
|
3
|
+
"version": "0.31.0",
|
|
4
|
+
"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,17 @@ 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 {DeprecatedLegacyRef} from './react19/deprecated-legacy-ref';
|
|
26
|
+
import {DeprecatedVoidFunctionComponent} from './react19/deprecated-void-function-component';
|
|
27
|
+
import {ReplaceActImport} from './react19/replace-act-import';
|
|
28
|
+
import {ReplaceUseFormState} from './react19/replace-use-form-state';
|
|
29
|
+
import {ReplaceReactShallowRenderer} from './react19/replace-react-shallow-renderer';
|
|
30
|
+
import {RefObjectDefaults} from './react19/refobject-defaults';
|
|
31
|
+
import {DeprecatedPropTypesTypes} from './react19/deprecated-prop-types-types';
|
|
21
32
|
import {RemoveUnstableBatchedUpdates} from './react19/remove-unstable-batched-updates';
|
|
22
33
|
import {ReplaceCreateFactory} from './react19/replace-create-factory';
|
|
23
34
|
|
|
@@ -26,6 +37,10 @@ import {ReplaceReactDomRender} from './react18/replace-reactdom-render';
|
|
|
26
37
|
import {ReplaceUnmountComponentAtNode} from './react18/replace-unmount-component-at-node';
|
|
27
38
|
import {ReplaceRenderCallback} from './react18/replace-render-callback';
|
|
28
39
|
import {AddChildrenToProps} from './react18/add-children-to-props';
|
|
40
|
+
import {DeprecatedReactType} from './react18/deprecated-react-type';
|
|
41
|
+
import {DeprecatedSfc} from './react18/deprecated-sfc';
|
|
42
|
+
import {DeprecatedSfcElement} from './react18/deprecated-sfc-element';
|
|
43
|
+
import {DeprecatedStatelessComponent} from './react18/deprecated-stateless-component';
|
|
29
44
|
|
|
30
45
|
// React 17
|
|
31
46
|
import {MigrateDeprecatedLifecycles} from './react17/migrate-deprecated-lifecycles';
|
|
@@ -77,6 +92,7 @@ import {TranslateHardCodedStrings} from './i18n/translate-hard-coded-strings';
|
|
|
77
92
|
|
|
78
93
|
// General
|
|
79
94
|
import {SimplifyReactImports} from './simplify-react-imports';
|
|
95
|
+
import {ChangeReactType} from './change-react-type';
|
|
80
96
|
import {SimplifyObjectPatternProperty} from './simplify-object-pattern-property';
|
|
81
97
|
import {ChangeComponentPropValue} from './migration/change-component-prop-value';
|
|
82
98
|
|
|
@@ -120,14 +136,29 @@ export async function activate(marketplace: RecipeMarketplace) {
|
|
|
120
136
|
await marketplace.install(FindDeprecatedReactDomAPIs, React19);
|
|
121
137
|
await marketplace.install(FindContextConsumer, React19);
|
|
122
138
|
await marketplace.install(FindElementRef, React19);
|
|
139
|
+
await marketplace.install(DeprecatedReactChild, React19);
|
|
140
|
+
await marketplace.install(DeprecatedReactNodeArray, React19);
|
|
141
|
+
await marketplace.install(DeprecatedReactFragment, React19);
|
|
142
|
+
await marketplace.install(DeprecatedReactText, React19);
|
|
143
|
+
await marketplace.install(DeprecatedLegacyRef, React19);
|
|
144
|
+
await marketplace.install(DeprecatedVoidFunctionComponent, React19);
|
|
145
|
+
await marketplace.install(RefObjectDefaults, React19);
|
|
146
|
+
await marketplace.install(DeprecatedPropTypesTypes, React19);
|
|
123
147
|
await marketplace.install(RemoveUnstableBatchedUpdates, React19);
|
|
124
148
|
await marketplace.install(ReplaceCreateFactory, React19);
|
|
149
|
+
await marketplace.install(ReplaceActImport, React19);
|
|
150
|
+
await marketplace.install(ReplaceUseFormState, React19);
|
|
151
|
+
await marketplace.install(ReplaceReactShallowRenderer, React19);
|
|
125
152
|
|
|
126
153
|
// React 18
|
|
127
154
|
await marketplace.install(ReplaceReactDomRender, React18);
|
|
128
155
|
await marketplace.install(ReplaceUnmountComponentAtNode, React18);
|
|
129
156
|
await marketplace.install(ReplaceRenderCallback, React18);
|
|
130
157
|
await marketplace.install(AddChildrenToProps, React18);
|
|
158
|
+
await marketplace.install(DeprecatedReactType, React18);
|
|
159
|
+
await marketplace.install(DeprecatedSfc, React18);
|
|
160
|
+
await marketplace.install(DeprecatedSfcElement, React18);
|
|
161
|
+
await marketplace.install(DeprecatedStatelessComponent, React18);
|
|
131
162
|
|
|
132
163
|
// React 17
|
|
133
164
|
await marketplace.install(MigrateDeprecatedLifecycles, React17);
|
|
@@ -186,6 +217,7 @@ export async function activate(marketplace: RecipeMarketplace) {
|
|
|
186
217
|
|
|
187
218
|
// General
|
|
188
219
|
await marketplace.install(SimplifyReactImports, React);
|
|
220
|
+
await marketplace.install(ChangeReactType, ReactMigrate);
|
|
189
221
|
await marketplace.install(SimplifyObjectPatternProperty, JavaScriptCleanup);
|
|
190
222
|
await marketplace.install(ChangeComponentPropValue, ReactMigration);
|
|
191
223
|
}
|
|
@@ -206,14 +238,29 @@ export {FindLegacyContextAPI} from './react19/find-legacy-context-api';
|
|
|
206
238
|
export {FindDeprecatedReactDomAPIs} from './react19/find-deprecated-reactdom-apis';
|
|
207
239
|
export {FindContextConsumer} from './react19/find-context-consumer';
|
|
208
240
|
export {FindElementRef} from './react19/find-element-ref';
|
|
241
|
+
export {DeprecatedReactChild} from './react19/deprecated-react-child';
|
|
242
|
+
export {DeprecatedReactNodeArray} from './react19/deprecated-react-node-array';
|
|
243
|
+
export {DeprecatedReactFragment} from './react19/deprecated-react-fragment';
|
|
244
|
+
export {DeprecatedReactText} from './react19/deprecated-react-text';
|
|
245
|
+
export {DeprecatedLegacyRef} from './react19/deprecated-legacy-ref';
|
|
246
|
+
export {DeprecatedVoidFunctionComponent} from './react19/deprecated-void-function-component';
|
|
247
|
+
export {RefObjectDefaults} from './react19/refobject-defaults';
|
|
248
|
+
export {AddTypesPropTypes, DeprecatedPropTypesTypes} from './react19/deprecated-prop-types-types';
|
|
209
249
|
export {RemoveUnstableBatchedUpdates} from './react19/remove-unstable-batched-updates';
|
|
210
250
|
export {ReplaceCreateFactory} from './react19/replace-create-factory';
|
|
251
|
+
export {ReplaceActImport} from './react19/replace-act-import';
|
|
252
|
+
export {ReplaceUseFormState} from './react19/replace-use-form-state';
|
|
253
|
+
export {ReplaceReactShallowRenderer} from './react19/replace-react-shallow-renderer';
|
|
211
254
|
|
|
212
255
|
// React 18
|
|
213
256
|
export {ReplaceReactDomRender} from './react18/replace-reactdom-render';
|
|
214
257
|
export {ReplaceUnmountComponentAtNode} from './react18/replace-unmount-component-at-node';
|
|
215
258
|
export {ReplaceRenderCallback} from './react18/replace-render-callback';
|
|
216
259
|
export {AddChildrenToProps} from './react18/add-children-to-props';
|
|
260
|
+
export {DeprecatedReactType} from './react18/deprecated-react-type';
|
|
261
|
+
export {DeprecatedSfc} from './react18/deprecated-sfc';
|
|
262
|
+
export {DeprecatedSfcElement} from './react18/deprecated-sfc-element';
|
|
263
|
+
export {DeprecatedStatelessComponent} from './react18/deprecated-stateless-component';
|
|
217
264
|
|
|
218
265
|
// React 17
|
|
219
266
|
export {MigrateDeprecatedLifecycles} from './react17/migrate-deprecated-lifecycles';
|
|
@@ -264,5 +311,6 @@ export * from './mui';
|
|
|
264
311
|
|
|
265
312
|
// General
|
|
266
313
|
export {SimplifyReactImports} from './simplify-react-imports';
|
|
314
|
+
export {ChangeReactType} from './change-react-type';
|
|
267
315
|
export {SimplifyObjectPatternProperty} from './simplify-object-pattern-property';
|
|
268
316
|
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,19 @@
|
|
|
1
|
+
import {Recipe} from "@openrewrite/rewrite";
|
|
2
|
+
import {ChangeReactType} from "../change-react-type";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This recipe can be replaced by an inline `change-react-type` entry in `react-migrate.yml` once
|
|
6
|
+
* {@link https://github.com/openrewrite/rewrite/issues/10113 openrewrite/rewrite#10113} is fixed. Until then, the
|
|
7
|
+
* platform can't load a TypeScript recipe configured with options from the jar's YAML.
|
|
8
|
+
*
|
|
9
|
+
* @see https://react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-typescript-definitions
|
|
10
|
+
*/
|
|
11
|
+
export class DeprecatedReactType extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.react.18.deprecated-react-type";
|
|
13
|
+
readonly displayName = "Replace `ReactType` with `ElementType`";
|
|
14
|
+
readonly description = "Renames React's deprecated `ReactType` type to `ElementType`, keeping its type arguments, as `@types/react` 18 removed it. Only references to React's own type are renamed.";
|
|
15
|
+
|
|
16
|
+
async recipeList(): Promise<Recipe[]> {
|
|
17
|
+
return [new ChangeReactType({oldTypeName: "ReactType", newTypeName: "ElementType"})];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {Recipe} from "@openrewrite/rewrite";
|
|
2
|
+
import {ChangeReactType} from "../change-react-type";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This recipe can be replaced by an inline `change-react-type` entry in `react-migrate.yml` once
|
|
6
|
+
* {@link https://github.com/openrewrite/rewrite/issues/10113 openrewrite/rewrite#10113} is fixed. Until then, the
|
|
7
|
+
* platform can't load a TypeScript recipe configured with options from the jar's YAML.
|
|
8
|
+
*
|
|
9
|
+
* @see https://react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-typescript-definitions
|
|
10
|
+
*/
|
|
11
|
+
export class DeprecatedSfcElement extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.react.18.deprecated-sfc-element";
|
|
13
|
+
readonly displayName = "Replace `SFCElement` with `FunctionComponentElement`";
|
|
14
|
+
readonly description = "Renames React's deprecated `SFCElement` type to `FunctionComponentElement`, keeping its type arguments, as `@types/react` 18 removed it. Only references to React's own type are renamed.";
|
|
15
|
+
|
|
16
|
+
async recipeList(): Promise<Recipe[]> {
|
|
17
|
+
return [new ChangeReactType({oldTypeName: "SFCElement", newTypeName: "FunctionComponentElement"})];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {Recipe} from "@openrewrite/rewrite";
|
|
2
|
+
import {ChangeReactType} from "../change-react-type";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This recipe can be replaced by an inline `change-react-type` entry in `react-migrate.yml` once
|
|
6
|
+
* {@link https://github.com/openrewrite/rewrite/issues/10113 openrewrite/rewrite#10113} is fixed. Until then, the
|
|
7
|
+
* platform can't load a TypeScript recipe configured with options from the jar's YAML.
|
|
8
|
+
*
|
|
9
|
+
* @see https://react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-typescript-definitions
|
|
10
|
+
*/
|
|
11
|
+
export class DeprecatedSfc extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.react.18.deprecated-sfc";
|
|
13
|
+
readonly displayName = "Replace `SFC` with `FC`";
|
|
14
|
+
readonly description = "Renames React's deprecated `SFC` type to `FC`, keeping its type arguments, as `@types/react` 18 removed it. Only references to React's own type are renamed.";
|
|
15
|
+
|
|
16
|
+
async recipeList(): Promise<Recipe[]> {
|
|
17
|
+
return [new ChangeReactType({oldTypeName: "SFC", newTypeName: "FC"})];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {Recipe} from "@openrewrite/rewrite";
|
|
2
|
+
import {ChangeReactType} from "../change-react-type";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This recipe can be replaced by an inline `change-react-type` entry in `react-migrate.yml` once
|
|
6
|
+
* {@link https://github.com/openrewrite/rewrite/issues/10113 openrewrite/rewrite#10113} is fixed. Until then, the
|
|
7
|
+
* platform can't load a TypeScript recipe configured with options from the jar's YAML.
|
|
8
|
+
*
|
|
9
|
+
* @see https://react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-typescript-definitions
|
|
10
|
+
*/
|
|
11
|
+
export class DeprecatedStatelessComponent extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.react.18.deprecated-stateless-component";
|
|
13
|
+
readonly displayName = "Replace `StatelessComponent` with `FunctionComponent`";
|
|
14
|
+
readonly description = "Renames React's deprecated `StatelessComponent` type to `FunctionComponent`, keeping its type arguments, as `@types/react` 18 removed it. Only references to React's own type are renamed, so another library's `StatelessComponent` (such as `ink`'s) stays.";
|
|
15
|
+
|
|
16
|
+
async recipeList(): Promise<Recipe[]> {
|
|
17
|
+
return [new ChangeReactType({oldTypeName: "StatelessComponent", newTypeName: "FunctionComponent"})];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {Recipe} from "@openrewrite/rewrite";
|
|
2
|
+
import {ChangeReactType} from "../change-react-type";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This recipe can be replaced by an inline `change-react-type` entry in `react-migrate.yml` once
|
|
6
|
+
* {@link https://github.com/openrewrite/rewrite/issues/10113 openrewrite/rewrite#10113} is fixed. Until then, the
|
|
7
|
+
* platform can't load a TypeScript recipe configured with options from the jar's YAML.
|
|
8
|
+
*
|
|
9
|
+
* @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-deprecated-typescript-types
|
|
10
|
+
*/
|
|
11
|
+
export class DeprecatedLegacyRef extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.react.19.deprecated-legacy-ref";
|
|
13
|
+
readonly displayName = "Replace `LegacyRef` with `Ref`";
|
|
14
|
+
readonly description = "Replaces React's `LegacyRef` type, deprecated in `@types/react` 19, with `Ref`, keeping its type argument.";
|
|
15
|
+
|
|
16
|
+
async recipeList(): Promise<Recipe[]> {
|
|
17
|
+
return [new ChangeReactType({oldTypeName: "LegacyRef", newTypeName: "Ref"})];
|
|
18
|
+
}
|
|
19
|
+
}
|