@openrewrite/recipes-react 0.2.9

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.
Files changed (251) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +130 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/migration/change-component-prop-value.d.ts +20 -0
  6. package/dist/migration/change-component-prop-value.d.ts.map +1 -0
  7. package/dist/migration/change-component-prop-value.js +217 -0
  8. package/dist/migration/change-component-prop-value.js.map +1 -0
  9. package/dist/react-native/view-prop-types.d.ts +8 -0
  10. package/dist/react-native/view-prop-types.d.ts.map +1 -0
  11. package/dist/react-native/view-prop-types.js +65 -0
  12. package/dist/react-native/view-prop-types.js.map +1 -0
  13. package/dist/react16/error-boundaries.d.ts +8 -0
  14. package/dist/react16/error-boundaries.d.ts.map +1 -0
  15. package/dist/react16/error-boundaries.js +42 -0
  16. package/dist/react16/error-boundaries.js.map +1 -0
  17. package/dist/react16/find-dom-node.d.ts +8 -0
  18. package/dist/react16/find-dom-node.d.ts.map +1 -0
  19. package/dist/react16/find-dom-node.js +48 -0
  20. package/dist/react16/find-dom-node.js.map +1 -0
  21. package/dist/react16/react-dom-factories.d.ts +8 -0
  22. package/dist/react16/react-dom-factories.d.ts.map +1 -0
  23. package/dist/react16/react-dom-factories.js +72 -0
  24. package/dist/react16/react-dom-factories.js.map +1 -0
  25. package/dist/react16/react-prop-types.d.ts +8 -0
  26. package/dist/react16/react-prop-types.d.ts.map +1 -0
  27. package/dist/react16/react-prop-types.js +69 -0
  28. package/dist/react16/react-prop-types.js.map +1 -0
  29. package/dist/react16/react-to-react-dom.d.ts +8 -0
  30. package/dist/react16/react-to-react-dom.d.ts.map +1 -0
  31. package/dist/react16/react-to-react-dom.js +97 -0
  32. package/dist/react16/react-to-react-dom.js.map +1 -0
  33. package/dist/react16/replace-create-factory.d.ts +8 -0
  34. package/dist/react16/replace-create-factory.d.ts.map +1 -0
  35. package/dist/react16/replace-create-factory.js +69 -0
  36. package/dist/react16/replace-create-factory.js.map +1 -0
  37. package/dist/react16/upgrade-to-react-16.d.ts +8 -0
  38. package/dist/react16/upgrade-to-react-16.d.ts.map +1 -0
  39. package/dist/react16/upgrade-to-react-16.js +41 -0
  40. package/dist/react16/upgrade-to-react-16.js.map +1 -0
  41. package/dist/react17/remove-event-persist.d.ts +8 -0
  42. package/dist/react17/remove-event-persist.d.ts.map +1 -0
  43. package/dist/react17/remove-event-persist.js +114 -0
  44. package/dist/react17/remove-event-persist.js.map +1 -0
  45. package/dist/react17/rename-unsafe-lifecycles.d.ts +8 -0
  46. package/dist/react17/rename-unsafe-lifecycles.d.ts.map +1 -0
  47. package/dist/react17/rename-unsafe-lifecycles.js +48 -0
  48. package/dist/react17/rename-unsafe-lifecycles.js.map +1 -0
  49. package/dist/react17/update-react-imports.d.ts +8 -0
  50. package/dist/react17/update-react-imports.d.ts.map +1 -0
  51. package/dist/react17/update-react-imports.js +40 -0
  52. package/dist/react17/update-react-imports.js.map +1 -0
  53. package/dist/react17/upgrade-to-react-17.d.ts +8 -0
  54. package/dist/react17/upgrade-to-react-17.d.ts.map +1 -0
  55. package/dist/react17/upgrade-to-react-17.js +37 -0
  56. package/dist/react17/upgrade-to-react-17.js.map +1 -0
  57. package/dist/react18/remove-unstable-batched-updates.d.ts +8 -0
  58. package/dist/react18/remove-unstable-batched-updates.d.ts.map +1 -0
  59. package/dist/react18/remove-unstable-batched-updates.js +170 -0
  60. package/dist/react18/remove-unstable-batched-updates.js.map +1 -0
  61. package/dist/react18/replace-reactdom-render.d.ts +8 -0
  62. package/dist/react18/replace-reactdom-render.d.ts.map +1 -0
  63. package/dist/react18/replace-reactdom-render.js +55 -0
  64. package/dist/react18/replace-reactdom-render.js.map +1 -0
  65. package/dist/react18/replace-render-callback.d.ts +8 -0
  66. package/dist/react18/replace-render-callback.d.ts.map +1 -0
  67. package/dist/react18/replace-render-callback.js +60 -0
  68. package/dist/react18/replace-render-callback.js.map +1 -0
  69. package/dist/react18/replace-unmount-component-at-node.d.ts +8 -0
  70. package/dist/react18/replace-unmount-component-at-node.d.ts.map +1 -0
  71. package/dist/react18/replace-unmount-component-at-node.js +54 -0
  72. package/dist/react18/replace-unmount-component-at-node.js.map +1 -0
  73. package/dist/react18/upgrade-to-react-18.d.ts +8 -0
  74. package/dist/react18/upgrade-to-react-18.d.ts.map +1 -0
  75. package/dist/react18/upgrade-to-react-18.js +39 -0
  76. package/dist/react18/upgrade-to-react-18.js.map +1 -0
  77. package/dist/react19/deprecated-react-types.d.ts +8 -0
  78. package/dist/react19/deprecated-react-types.d.ts.map +1 -0
  79. package/dist/react19/deprecated-react-types.js +135 -0
  80. package/dist/react19/deprecated-react-types.js.map +1 -0
  81. package/dist/react19/find-context-consumer.d.ts +9 -0
  82. package/dist/react19/find-context-consumer.d.ts.map +1 -0
  83. package/dist/react19/find-context-consumer.js +128 -0
  84. package/dist/react19/find-context-consumer.js.map +1 -0
  85. package/dist/react19/find-deprecated-reactdom-apis.d.ts +9 -0
  86. package/dist/react19/find-deprecated-reactdom-apis.d.ts.map +1 -0
  87. package/dist/react19/find-deprecated-reactdom-apis.js +132 -0
  88. package/dist/react19/find-deprecated-reactdom-apis.js.map +1 -0
  89. package/dist/react19/find-element-ref.d.ts +9 -0
  90. package/dist/react19/find-element-ref.d.ts.map +1 -0
  91. package/dist/react19/find-element-ref.js +88 -0
  92. package/dist/react19/find-element-ref.js.map +1 -0
  93. package/dist/react19/find-legacy-context-api.d.ts +9 -0
  94. package/dist/react19/find-legacy-context-api.d.ts.map +1 -0
  95. package/dist/react19/find-legacy-context-api.js +163 -0
  96. package/dist/react19/find-legacy-context-api.js.map +1 -0
  97. package/dist/react19/no-implicit-ref-callback-return.d.ts +8 -0
  98. package/dist/react19/no-implicit-ref-callback-return.d.ts.map +1 -0
  99. package/dist/react19/no-implicit-ref-callback-return.js +107 -0
  100. package/dist/react19/no-implicit-ref-callback-return.js.map +1 -0
  101. package/dist/react19/remove-context-provider.d.ts +8 -0
  102. package/dist/react19/remove-context-provider.d.ts.map +1 -0
  103. package/dist/react19/remove-context-provider.js +59 -0
  104. package/dist/react19/remove-context-provider.js.map +1 -0
  105. package/dist/react19/remove-forward-ref.d.ts +8 -0
  106. package/dist/react19/remove-forward-ref.d.ts.map +1 -0
  107. package/dist/react19/remove-forward-ref.js +73 -0
  108. package/dist/react19/remove-forward-ref.js.map +1 -0
  109. package/dist/react19/remove-prop-types.d.ts +8 -0
  110. package/dist/react19/remove-prop-types.d.ts.map +1 -0
  111. package/dist/react19/remove-prop-types.js +76 -0
  112. package/dist/react19/remove-prop-types.js.map +1 -0
  113. package/dist/react19/remove-react-fc.d.ts +8 -0
  114. package/dist/react19/remove-react-fc.d.ts.map +1 -0
  115. package/dist/react19/remove-react-fc.js +149 -0
  116. package/dist/react19/remove-react-fc.js.map +1 -0
  117. package/dist/react19/replace-act-import.d.ts +9 -0
  118. package/dist/react19/replace-act-import.d.ts.map +1 -0
  119. package/dist/react19/replace-act-import.js +34 -0
  120. package/dist/react19/replace-act-import.js.map +1 -0
  121. package/dist/react19/replace-default-props.d.ts +8 -0
  122. package/dist/react19/replace-default-props.d.ts.map +1 -0
  123. package/dist/react19/replace-default-props.js +195 -0
  124. package/dist/react19/replace-default-props.js.map +1 -0
  125. package/dist/react19/replace-react-shallow-renderer.d.ts +8 -0
  126. package/dist/react19/replace-react-shallow-renderer.d.ts.map +1 -0
  127. package/dist/react19/replace-react-shallow-renderer.js +69 -0
  128. package/dist/react19/replace-react-shallow-renderer.js.map +1 -0
  129. package/dist/react19/replace-reactdom-hydrate.d.ts +8 -0
  130. package/dist/react19/replace-reactdom-hydrate.d.ts.map +1 -0
  131. package/dist/react19/replace-reactdom-hydrate.js +55 -0
  132. package/dist/react19/replace-reactdom-hydrate.js.map +1 -0
  133. package/dist/react19/replace-string-ref.d.ts +8 -0
  134. package/dist/react19/replace-string-ref.d.ts.map +1 -0
  135. package/dist/react19/replace-string-ref.js +75 -0
  136. package/dist/react19/replace-string-ref.js.map +1 -0
  137. package/dist/react19/replace-use-form-state.d.ts +8 -0
  138. package/dist/react19/replace-use-form-state.d.ts.map +1 -0
  139. package/dist/react19/replace-use-form-state.js +54 -0
  140. package/dist/react19/replace-use-form-state.js.map +1 -0
  141. package/dist/react19/upgrade-to-react-19.d.ts +8 -0
  142. package/dist/react19/upgrade-to-react-19.d.ts.map +1 -0
  143. package/dist/react19/upgrade-to-react-19.js +59 -0
  144. package/dist/react19/upgrade-to-react-19.js.map +1 -0
  145. package/dist/react19/use-context-hook.d.ts +8 -0
  146. package/dist/react19/use-context-hook.d.ts.map +1 -0
  147. package/dist/react19/use-context-hook.js +54 -0
  148. package/dist/react19/use-context-hook.js.map +1 -0
  149. package/dist/react19/use-ref-required-initial.d.ts +8 -0
  150. package/dist/react19/use-ref-required-initial.d.ts.map +1 -0
  151. package/dist/react19/use-ref-required-initial.js +74 -0
  152. package/dist/react19/use-ref-required-initial.js.map +1 -0
  153. package/dist/refactoring/class-to-functional.d.ts +8 -0
  154. package/dist/refactoring/class-to-functional.d.ts.map +1 -0
  155. package/dist/refactoring/class-to-functional.js +205 -0
  156. package/dist/refactoring/class-to-functional.js.map +1 -0
  157. package/dist/refactoring/create-class-to-es6.d.ts +8 -0
  158. package/dist/refactoring/create-class-to-es6.d.ts.map +1 -0
  159. package/dist/refactoring/create-class-to-es6.js +289 -0
  160. package/dist/refactoring/create-class-to-es6.js.map +1 -0
  161. package/dist/refactoring/create-element-to-jsx.d.ts +8 -0
  162. package/dist/refactoring/create-element-to-jsx.d.ts.map +1 -0
  163. package/dist/refactoring/create-element-to-jsx.js +167 -0
  164. package/dist/refactoring/create-element-to-jsx.js.map +1 -0
  165. package/dist/refactoring/manual-bind-to-arrow.d.ts +8 -0
  166. package/dist/refactoring/manual-bind-to-arrow.d.ts.map +1 -0
  167. package/dist/refactoring/manual-bind-to-arrow.js +134 -0
  168. package/dist/refactoring/manual-bind-to-arrow.js.map +1 -0
  169. package/dist/refactoring/pure-render-mixin.d.ts +8 -0
  170. package/dist/refactoring/pure-render-mixin.d.ts.map +1 -0
  171. package/dist/refactoring/pure-render-mixin.js +253 -0
  172. package/dist/refactoring/pure-render-mixin.js.map +1 -0
  173. package/dist/refactoring/sort-comp.d.ts +8 -0
  174. package/dist/refactoring/sort-comp.d.ts.map +1 -0
  175. package/dist/refactoring/sort-comp.js +128 -0
  176. package/dist/refactoring/sort-comp.js.map +1 -0
  177. package/dist/search/find-hook-usage.d.ts +9 -0
  178. package/dist/search/find-hook-usage.d.ts.map +1 -0
  179. package/dist/search/find-hook-usage.js +262 -0
  180. package/dist/search/find-hook-usage.js.map +1 -0
  181. package/dist/search/find-prop-usage.d.ts +15 -0
  182. package/dist/search/find-prop-usage.d.ts.map +1 -0
  183. package/dist/search/find-prop-usage.js +177 -0
  184. package/dist/search/find-prop-usage.js.map +1 -0
  185. package/dist/search/find-react-component.d.ts +15 -0
  186. package/dist/search/find-react-component.d.ts.map +1 -0
  187. package/dist/search/find-react-component.js +260 -0
  188. package/dist/search/find-react-component.js.map +1 -0
  189. package/dist/search/find-server-rendering-usage.d.ts +9 -0
  190. package/dist/search/find-server-rendering-usage.d.ts.map +1 -0
  191. package/dist/search/find-server-rendering-usage.js +131 -0
  192. package/dist/search/find-server-rendering-usage.js.map +1 -0
  193. package/dist/simplify-object-pattern-property.d.ts +8 -0
  194. package/dist/simplify-object-pattern-property.d.ts.map +1 -0
  195. package/dist/simplify-object-pattern-property.js +59 -0
  196. package/dist/simplify-object-pattern-property.js.map +1 -0
  197. package/dist/simplify-react-imports.d.ts +8 -0
  198. package/dist/simplify-react-imports.d.ts.map +1 -0
  199. package/dist/simplify-react-imports.js +199 -0
  200. package/dist/simplify-react-imports.js.map +1 -0
  201. package/package.json +39 -0
  202. package/src/index.ts +149 -0
  203. package/src/migration/change-component-prop-value.ts +268 -0
  204. package/src/react-native/view-prop-types.ts +63 -0
  205. package/src/react16/error-boundaries.ts +46 -0
  206. package/src/react16/find-dom-node.ts +55 -0
  207. package/src/react16/react-dom-factories.ts +99 -0
  208. package/src/react16/react-prop-types.ts +71 -0
  209. package/src/react16/react-to-react-dom.ts +104 -0
  210. package/src/react16/replace-create-factory.ts +96 -0
  211. package/src/react16/upgrade-to-react-16.ts +37 -0
  212. package/src/react17/remove-event-persist.ts +121 -0
  213. package/src/react17/rename-unsafe-lifecycles.ts +57 -0
  214. package/src/react17/update-react-imports.ts +50 -0
  215. package/src/react17/upgrade-to-react-17.ts +30 -0
  216. package/src/react18/remove-unstable-batched-updates.ts +192 -0
  217. package/src/react18/replace-reactdom-render.ts +68 -0
  218. package/src/react18/replace-render-callback.ts +66 -0
  219. package/src/react18/replace-unmount-component-at-node.ts +66 -0
  220. package/src/react18/upgrade-to-react-18.ts +33 -0
  221. package/src/react19/deprecated-react-types.ts +120 -0
  222. package/src/react19/find-context-consumer.ts +127 -0
  223. package/src/react19/find-deprecated-reactdom-apis.ts +125 -0
  224. package/src/react19/find-element-ref.ts +86 -0
  225. package/src/react19/find-legacy-context-api.ts +157 -0
  226. package/src/react19/no-implicit-ref-callback-return.ts +123 -0
  227. package/src/react19/remove-context-provider.ts +87 -0
  228. package/src/react19/remove-forward-ref.ts +69 -0
  229. package/src/react19/remove-prop-types.ts +86 -0
  230. package/src/react19/remove-react-fc.ts +247 -0
  231. package/src/react19/replace-act-import.ts +36 -0
  232. package/src/react19/replace-default-props.ts +220 -0
  233. package/src/react19/replace-react-shallow-renderer.ts +75 -0
  234. package/src/react19/replace-reactdom-hydrate.ts +67 -0
  235. package/src/react19/replace-string-ref.ts +89 -0
  236. package/src/react19/replace-use-form-state.ts +66 -0
  237. package/src/react19/upgrade-to-react-19.ts +66 -0
  238. package/src/react19/use-context-hook.ts +67 -0
  239. package/src/react19/use-ref-required-initial.ts +75 -0
  240. package/src/refactoring/class-to-functional.ts +229 -0
  241. package/src/refactoring/create-class-to-es6.ts +309 -0
  242. package/src/refactoring/create-element-to-jsx.ts +200 -0
  243. package/src/refactoring/manual-bind-to-arrow.ts +139 -0
  244. package/src/refactoring/pure-render-mixin.ts +346 -0
  245. package/src/refactoring/sort-comp.ts +135 -0
  246. package/src/search/find-hook-usage.ts +226 -0
  247. package/src/search/find-prop-usage.ts +176 -0
  248. package/src/search/find-react-component.ts +254 -0
  249. package/src/search/find-server-rendering-usage.ts +120 -0
  250. package/src/simplify-object-pattern-property.ts +71 -0
  251. package/src/simplify-react-imports.ts +241 -0
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.FindHookUsage = void 0;
19
+ const rewrite_1 = require("@openrewrite/rewrite");
20
+ const javascript_1 = require("@openrewrite/rewrite/javascript");
21
+ const java_1 = require("@openrewrite/rewrite/java");
22
+ const BUILT_IN_HOOKS = new Set([
23
+ "useState", "useEffect", "useContext", "useReducer", "useCallback",
24
+ "useMemo", "useRef", "useImperativeHandle", "useLayoutEffect",
25
+ "useDebugValue", "useDeferredValue", "useTransition", "useId",
26
+ "useSyncExternalStore", "useInsertionEffect", "useOptimistic",
27
+ "useFormStatus", "useFormState", "useActionState", "use"
28
+ ]);
29
+ const HOOK_CATEGORIES = {
30
+ useState: "state", useReducer: "state",
31
+ useEffect: "effect", useLayoutEffect: "effect", useInsertionEffect: "effect",
32
+ useContext: "context", use: "context",
33
+ useRef: "ref", useImperativeHandle: "ref",
34
+ useMemo: "memo",
35
+ useCallback: "callback",
36
+ useId: "id",
37
+ useDeferredValue: "concurrency", useTransition: "concurrency",
38
+ useSyncExternalStore: "sync",
39
+ useDebugValue: "debug",
40
+ useOptimistic: "state", useFormStatus: "state", useFormState: "state", useActionState: "state"
41
+ };
42
+ class FindHookUsageRow {
43
+ }
44
+ __decorate([
45
+ (0, rewrite_1.Column)({ displayName: "Hook name", description: "The name of the hook" })
46
+ ], FindHookUsageRow.prototype, "hookName", void 0);
47
+ __decorate([
48
+ (0, rewrite_1.Column)({ displayName: "File path", description: "The file path where the hook is used" })
49
+ ], FindHookUsageRow.prototype, "filePath", void 0);
50
+ __decorate([
51
+ (0, rewrite_1.Column)({ displayName: "Component name", description: "The name of the enclosing component or custom hook" })
52
+ ], FindHookUsageRow.prototype, "componentName", void 0);
53
+ __decorate([
54
+ (0, rewrite_1.Column)({ displayName: "Hook type", description: "Whether the hook is built-in or custom" })
55
+ ], FindHookUsageRow.prototype, "hookType", void 0);
56
+ __decorate([
57
+ (0, rewrite_1.Column)({ displayName: "Hook category", description: "The category of the hook (state, effect, ref, memo, callback, context, custom)" })
58
+ ], FindHookUsageRow.prototype, "hookCategory", void 0);
59
+ __decorate([
60
+ (0, rewrite_1.Column)({ displayName: "Is conditional", description: "Whether the hook is called inside a conditional block" })
61
+ ], FindHookUsageRow.prototype, "isConditional", void 0);
62
+ __decorate([
63
+ (0, rewrite_1.Column)({ displayName: "Is in loop", description: "Whether the hook is called inside a loop" })
64
+ ], FindHookUsageRow.prototype, "isInLoop", void 0);
65
+ class FindHookUsage extends rewrite_1.Recipe {
66
+ constructor() {
67
+ super(...arguments);
68
+ this.name = "org.openrewrite.react.search.find-hook-usage";
69
+ this.displayName = "Find React hook usage";
70
+ this.description = "Finds all React hook usages including built-in and custom hooks, and detects Rules of Hooks violations.";
71
+ this.dataTable = new rewrite_1.DataTable("org.openrewrite.react.search.FindHookUsageTable", "React hook usages", "Table of all React hook usages found in the codebase.", FindHookUsageRow);
72
+ }
73
+ editor() {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const dataTable = this.dataTable;
76
+ return new class extends javascript_1.JavaScriptVisitor {
77
+ constructor() {
78
+ super(...arguments);
79
+ this.filePath = "";
80
+ this.componentStack = [];
81
+ this.conditionalDepth = 0;
82
+ this.loopDepth = 0;
83
+ }
84
+ visitJsCompilationUnit(cu, ctx) {
85
+ const _super = Object.create(null, {
86
+ visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
87
+ });
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ var _a;
90
+ this.filePath = (_a = cu.sourcePath) !== null && _a !== void 0 ? _a : "";
91
+ this.componentStack = [];
92
+ this.conditionalDepth = 0;
93
+ this.loopDepth = 0;
94
+ return _super.visitJsCompilationUnit.call(this, cu, ctx);
95
+ });
96
+ }
97
+ visitMethodDeclaration(method, ctx) {
98
+ const _super = Object.create(null, {
99
+ visitMethodDeclaration: { get: () => super.visitMethodDeclaration }
100
+ });
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const name = method.name.simpleName;
103
+ this.componentStack.push(name);
104
+ const result = yield _super.visitMethodDeclaration.call(this, method, ctx);
105
+ this.componentStack.pop();
106
+ return result;
107
+ });
108
+ }
109
+ visitLambda(lambda, ctx) {
110
+ const _super = Object.create(null, {
111
+ visitLambda: { get: () => super.visitLambda }
112
+ });
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ const varName = this.getLambdaName();
115
+ if (varName) {
116
+ this.componentStack.push(varName);
117
+ }
118
+ const result = yield _super.visitLambda.call(this, lambda, ctx);
119
+ if (varName) {
120
+ this.componentStack.pop();
121
+ }
122
+ return result;
123
+ });
124
+ }
125
+ visitIf(ifStmt, ctx) {
126
+ const _super = Object.create(null, {
127
+ visitIf: { get: () => super.visitIf }
128
+ });
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ this.conditionalDepth++;
131
+ const result = yield _super.visitIf.call(this, ifStmt, ctx);
132
+ this.conditionalDepth--;
133
+ return result;
134
+ });
135
+ }
136
+ visitTernary(ternary, ctx) {
137
+ const _super = Object.create(null, {
138
+ visitTernary: { get: () => super.visitTernary }
139
+ });
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ this.conditionalDepth++;
142
+ const result = yield _super.visitTernary.call(this, ternary, ctx);
143
+ this.conditionalDepth--;
144
+ return result;
145
+ });
146
+ }
147
+ visitForLoop(forLoop, ctx) {
148
+ const _super = Object.create(null, {
149
+ visitForLoop: { get: () => super.visitForLoop }
150
+ });
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ this.loopDepth++;
153
+ const result = yield _super.visitForLoop.call(this, forLoop, ctx);
154
+ this.loopDepth--;
155
+ return result;
156
+ });
157
+ }
158
+ visitForEachLoop(forEachLoop, ctx) {
159
+ const _super = Object.create(null, {
160
+ visitForEachLoop: { get: () => super.visitForEachLoop }
161
+ });
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ this.loopDepth++;
164
+ const result = yield _super.visitForEachLoop.call(this, forEachLoop, ctx);
165
+ this.loopDepth--;
166
+ return result;
167
+ });
168
+ }
169
+ visitWhileLoop(whileLoop, ctx) {
170
+ const _super = Object.create(null, {
171
+ visitWhileLoop: { get: () => super.visitWhileLoop }
172
+ });
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ this.loopDepth++;
175
+ const result = yield _super.visitWhileLoop.call(this, whileLoop, ctx);
176
+ this.loopDepth--;
177
+ return result;
178
+ });
179
+ }
180
+ visitDoWhileLoop(doWhileLoop, ctx) {
181
+ const _super = Object.create(null, {
182
+ visitDoWhileLoop: { get: () => super.visitDoWhileLoop }
183
+ });
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ this.loopDepth++;
186
+ const result = yield _super.visitDoWhileLoop.call(this, doWhileLoop, ctx);
187
+ this.loopDepth--;
188
+ return result;
189
+ });
190
+ }
191
+ visitMethodInvocation(method, ctx) {
192
+ const _super = Object.create(null, {
193
+ visitMethodInvocation: { get: () => super.visitMethodInvocation }
194
+ });
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ var _a;
197
+ let m = yield _super.visitMethodInvocation.call(this, method, ctx);
198
+ const hookName = this.getHookName(m);
199
+ if (!hookName)
200
+ return m;
201
+ const isBuiltIn = BUILT_IN_HOOKS.has(hookName);
202
+ const hookType = isBuiltIn ? "built-in" : "custom";
203
+ const hookCategory = (_a = HOOK_CATEGORIES[hookName]) !== null && _a !== void 0 ? _a : "custom";
204
+ const componentName = this.componentStack.length > 0
205
+ ? this.componentStack[this.componentStack.length - 1]
206
+ : "<module>";
207
+ dataTable.insertRow(ctx, {
208
+ hookName,
209
+ filePath: this.filePath,
210
+ componentName,
211
+ hookType,
212
+ hookCategory,
213
+ isConditional: this.conditionalDepth > 0,
214
+ isInLoop: this.loopDepth > 0
215
+ });
216
+ return (0, rewrite_1.foundSearchResult)(m, hookName);
217
+ });
218
+ }
219
+ getHookName(method) {
220
+ var _a;
221
+ const name = method.name.simpleName;
222
+ if (this.isHookName(name) && !method.select) {
223
+ return name;
224
+ }
225
+ if (this.isHookName(name) && method.select) {
226
+ const select = (_a = method.select.element) !== null && _a !== void 0 ? _a : method.select;
227
+ if ((0, java_1.isIdentifier)(select)) {
228
+ return name;
229
+ }
230
+ }
231
+ return null;
232
+ }
233
+ isHookName(name) {
234
+ return name.length > 3 && name.startsWith("use") && name[3] === name[3].toUpperCase();
235
+ }
236
+ getLambdaName() {
237
+ let cursor = this.cursor;
238
+ while (cursor.parent) {
239
+ const node = cursor.parent.value;
240
+ if (!node || typeof node !== 'object')
241
+ break;
242
+ if (node.kind === java_1.J.Kind.NamedVariable) {
243
+ const namedVar = node;
244
+ const name = namedVar.name;
245
+ if ((0, java_1.isIdentifier)(name)) {
246
+ return name.simpleName;
247
+ }
248
+ }
249
+ if (node.kind === javascript_1.JS.Kind.ScopedVariableDeclarations)
250
+ break;
251
+ if (node.kind === java_1.J.Kind.MethodDeclaration)
252
+ break;
253
+ cursor = cursor.parent;
254
+ }
255
+ return null;
256
+ }
257
+ }();
258
+ });
259
+ }
260
+ }
261
+ exports.FindHookUsage = FindHookUsage;
262
+ //# sourceMappingURL=find-hook-usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-hook-usage.js","sourceRoot":"","sources":["../../src/search/find-hook-usage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,kDAAiH;AACjH,gEAAsE;AACtE,oDAA0D;AAE1D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC3B,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa;IAClE,SAAS,EAAE,QAAQ,EAAE,qBAAqB,EAAE,iBAAiB;IAC7D,eAAe,EAAE,kBAAkB,EAAE,eAAe,EAAE,OAAO;IAC7D,sBAAsB,EAAE,oBAAoB,EAAE,eAAe;IAC7D,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,KAAK;CAC3D,CAAC,CAAC;AAEH,MAAM,eAAe,GAA2B;IAC5C,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO;IACtC,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,kBAAkB,EAAE,QAAQ;IAC5E,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS;IACrC,MAAM,EAAE,KAAK,EAAE,mBAAmB,EAAE,KAAK;IACzC,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,UAAU;IACvB,KAAK,EAAE,IAAI;IACX,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAE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CAAC;4BAC9D,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;4BAC3B,IAAI,IAAA,mBAAY,EAAC,IAAI,CAAC,EAAE,CAAC;gCACrB,OAAO,IAAI,CAAC,UAAU,CAAC;4BAC3B,CAAC;wBACL,CAAC;wBACD,IAAK,IAAY,CAAC,IAAI,KAAK,eAAE,CAAC,IAAI,CAAC,0BAA0B;4BAAE,MAAM;wBACrE,IAAK,IAAY,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,iBAAiB;4BAAE,MAAM;wBAC3D,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;oBAC3B,CAAC;oBACD,OAAO,IAAI,CAAC;gBAChB,CAAC;aACJ,EAAE,CAAC;QACR,CAAC;KAAA;CACJ;AAtKD,sCAsKC"}
@@ -0,0 +1,15 @@
1
+ import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
2
+ export declare class FindPropUsage extends Recipe {
3
+ readonly name = "org.openrewrite.react.search.find-prop-usage";
4
+ readonly displayName: string;
5
+ readonly description: string;
6
+ componentName?: string;
7
+ propName?: string;
8
+ private dataTable;
9
+ constructor(options?: {
10
+ componentName?: string;
11
+ propName?: string;
12
+ });
13
+ editor(): Promise<TreeVisitor<any, ExecutionContext>>;
14
+ }
15
+ //# sourceMappingURL=find-prop-usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-prop-usage.d.ts","sourceRoot":"","sources":["../../src/search/find-prop-usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,gBAAgB,EAA6B,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAmCzH,qBAAa,aAAc,SAAQ,MAAM;IACrC,QAAQ,CAAC,IAAI,kDAAkD;IAC/D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA2B;IACvD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAsG;IAQlI,aAAa,CAAC,EAAE,MAAM,CAAC;IAQvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,OAAO,CAAC,SAAS,CAKf;gBAEU,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;IAI7D,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA4G9D"}
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.FindPropUsage = void 0;
19
+ const rewrite_1 = require("@openrewrite/rewrite");
20
+ const javascript_1 = require("@openrewrite/rewrite/javascript");
21
+ const java_1 = require("@openrewrite/rewrite/java");
22
+ class FindPropUsageRow {
23
+ }
24
+ __decorate([
25
+ (0, rewrite_1.Column)({ displayName: "Component name", description: "The name of the JSX element receiving the prop" })
26
+ ], FindPropUsageRow.prototype, "componentName", void 0);
27
+ __decorate([
28
+ (0, rewrite_1.Column)({ displayName: "File path", description: "The file path where the prop usage is found" })
29
+ ], FindPropUsageRow.prototype, "filePath", void 0);
30
+ __decorate([
31
+ (0, rewrite_1.Column)({ displayName: "Prop name", description: "The name of the prop" })
32
+ ], FindPropUsageRow.prototype, "propName", void 0);
33
+ __decorate([
34
+ (0, rewrite_1.Column)({ displayName: "Prop value type", description: "The type of value passed to the prop (string, expression, boolean, spread)" })
35
+ ], FindPropUsageRow.prototype, "propValueType", void 0);
36
+ __decorate([
37
+ (0, rewrite_1.Column)({ displayName: "Prop value", description: "The literal value if available" })
38
+ ], FindPropUsageRow.prototype, "propValue", void 0);
39
+ __decorate([
40
+ (0, rewrite_1.Column)({ displayName: "Is spread", description: "Whether this prop comes from a spread attribute" })
41
+ ], FindPropUsageRow.prototype, "isSpread", void 0);
42
+ class FindPropUsage extends rewrite_1.Recipe {
43
+ constructor(options) {
44
+ super(options);
45
+ this.name = "org.openrewrite.react.search.find-prop-usage";
46
+ this.displayName = "Find React prop usage";
47
+ this.description = "Finds all prop usages on React JSX elements, with optional filtering by component and prop name.";
48
+ this.dataTable = new rewrite_1.DataTable("org.openrewrite.react.search.FindPropUsageTable", "React prop usages", "Table of all React prop usages found in the codebase.", FindPropUsageRow);
49
+ }
50
+ editor() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const filterComponent = this.componentName;
53
+ const filterProp = this.propName;
54
+ const dataTable = this.dataTable;
55
+ return new class extends javascript_1.JavaScriptVisitor {
56
+ constructor() {
57
+ super(...arguments);
58
+ this.filePath = "";
59
+ }
60
+ visitJsCompilationUnit(cu, ctx) {
61
+ const _super = Object.create(null, {
62
+ visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
63
+ });
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ var _a;
66
+ this.filePath = (_a = cu.sourcePath) !== null && _a !== void 0 ? _a : "";
67
+ return _super.visitJsCompilationUnit.call(this, cu, ctx);
68
+ });
69
+ }
70
+ visitJsxAttribute(attribute, ctx) {
71
+ const _super = Object.create(null, {
72
+ visitJsxAttribute: { get: () => super.visitJsxAttribute }
73
+ });
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ var _a;
76
+ const attr = yield _super.visitJsxAttribute.call(this, attribute, ctx);
77
+ const tag = this.cursor.firstEnclosing((t) => t.kind === javascript_1.JS.Kind.JsxTag);
78
+ if (!tag)
79
+ return attr;
80
+ const tagName = this.getTagName(tag);
81
+ if (filterComponent && tagName !== filterComponent)
82
+ return attr;
83
+ const key = attr.key;
84
+ if (!(0, java_1.isIdentifier)(key))
85
+ return attr;
86
+ const propNameStr = key.simpleName;
87
+ if (filterProp && propNameStr !== filterProp)
88
+ return attr;
89
+ let propValueType;
90
+ let propValue;
91
+ if (!attr.value) {
92
+ propValueType = "boolean";
93
+ propValue = "true";
94
+ }
95
+ else {
96
+ const valueExpr = attr.value.element;
97
+ if (valueExpr.kind === java_1.J.Kind.Literal) {
98
+ const literal = valueExpr;
99
+ propValueType = typeof literal.value === 'string' ? "string" : String(typeof literal.value);
100
+ propValue = String((_a = literal.value) !== null && _a !== void 0 ? _a : "");
101
+ }
102
+ else {
103
+ propValueType = "expression";
104
+ propValue = "";
105
+ }
106
+ }
107
+ dataTable.insertRow(ctx, {
108
+ componentName: tagName,
109
+ filePath: this.filePath,
110
+ propName: propNameStr,
111
+ propValueType,
112
+ propValue,
113
+ isSpread: false
114
+ });
115
+ return (0, rewrite_1.foundSearchResult)(attr, propNameStr);
116
+ });
117
+ }
118
+ visitJsxSpreadAttribute(spread, ctx) {
119
+ const _super = Object.create(null, {
120
+ visitJsxSpreadAttribute: { get: () => super.visitJsxSpreadAttribute }
121
+ });
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ const s = yield _super.visitJsxSpreadAttribute.call(this, spread, ctx);
124
+ const tag = this.cursor.firstEnclosing((t) => t.kind === javascript_1.JS.Kind.JsxTag);
125
+ if (!tag)
126
+ return s;
127
+ const tagName = this.getTagName(tag);
128
+ if (filterComponent && tagName !== filterComponent)
129
+ return s;
130
+ if (filterProp)
131
+ return s;
132
+ dataTable.insertRow(ctx, {
133
+ componentName: tagName,
134
+ filePath: this.filePath,
135
+ propName: "...",
136
+ propValueType: "spread",
137
+ propValue: "",
138
+ isSpread: true
139
+ });
140
+ return (0, rewrite_1.foundSearchResult)(s, "...");
141
+ });
142
+ }
143
+ getTagName(tag) {
144
+ const openName = tag.openName.element;
145
+ if ((0, java_1.isIdentifier)(openName)) {
146
+ return openName.simpleName;
147
+ }
148
+ else if (openName.kind === java_1.J.Kind.FieldAccess) {
149
+ const fa = openName;
150
+ const target = (0, java_1.isIdentifier)(fa.target) ? fa.target.simpleName + "." : "";
151
+ const name = fa.name.element;
152
+ return target + ((0, java_1.isIdentifier)(name) ? name.simpleName : "");
153
+ }
154
+ return "";
155
+ }
156
+ }();
157
+ });
158
+ }
159
+ }
160
+ exports.FindPropUsage = FindPropUsage;
161
+ __decorate([
162
+ (0, rewrite_1.Option)({
163
+ displayName: "Component name",
164
+ description: "Optional component name to filter (e.g., 'Button'). If not specified, finds props on all components.",
165
+ required: false,
166
+ example: "Button"
167
+ })
168
+ ], FindPropUsage.prototype, "componentName", void 0);
169
+ __decorate([
170
+ (0, rewrite_1.Option)({
171
+ displayName: "Prop name",
172
+ description: "Optional prop name to filter (e.g., 'onClick'). If not specified, finds all props.",
173
+ required: false,
174
+ example: "onClick"
175
+ })
176
+ ], FindPropUsage.prototype, "propName", void 0);
177
+ //# sourceMappingURL=find-prop-usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-prop-usage.js","sourceRoot":"","sources":["../../src/search/find-prop-usage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,kDAAyH;AACzH,gEAA2E;AAC3E,oDAAsE;AAEtE,MAAM,gBAAgB;CAkBrB;AAhBG;IADC,IAAA,gBAAM,EAAC,EAAC,WAAW,EAAE,gBAAgB,EAAE,WAAW,EAAE,gDAAgD,EAAC,CA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E,SAAS;KACrB,CAAC;+CACgB"}
@@ -0,0 +1,15 @@
1
+ import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
2
+ export declare class FindReactComponent extends Recipe {
3
+ readonly name = "org.openrewrite.react.search.find-react-component";
4
+ readonly displayName: string;
5
+ readonly description: string;
6
+ componentName: string;
7
+ importPath?: string;
8
+ private dataTable;
9
+ constructor(options?: {
10
+ componentName?: string;
11
+ importPath?: string;
12
+ });
13
+ editor(): Promise<TreeVisitor<any, ExecutionContext>>;
14
+ }
15
+ //# sourceMappingURL=find-react-component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-react-component.d.ts","sourceRoot":"","sources":["../../src/search/find-react-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,gBAAgB,EAA6B,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAmCzH,qBAAa,kBAAmB,SAAQ,MAAM;IAC1C,QAAQ,CAAC,IAAI,uDAAuD;IACpE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA0B;IACtD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAkG;IAO9H,aAAa,EAAG,MAAM,CAAC;IAQvB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,OAAO,CAAC,SAAS,CAKf;gBAEU,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;IAI/D,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA2L9D"}