@openrewrite/recipes-react 0.26.0 → 0.28.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.
Files changed (431) hide show
  1. package/dist/i18n/translate-hard-coded-strings.d.ts.map +1 -1
  2. package/dist/i18n/translate-hard-coded-strings.js +3 -2
  3. package/dist/i18n/translate-hard-coded-strings.js.map +1 -1
  4. package/dist/index.d.ts +1 -4
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +6 -18
  7. package/dist/index.js.map +1 -1
  8. package/dist/migration/change-component-prop-value.d.ts.map +1 -1
  9. package/dist/migration/change-component-prop-value.js.map +1 -1
  10. package/dist/migration/cra-to-vite/add-vite-config.d.ts.map +1 -1
  11. package/dist/migration/cra-to-vite/add-vite-config.js.map +1 -1
  12. package/dist/migration/cra-to-vite/cra-to-vite.d.ts.map +1 -1
  13. package/dist/migration/cra-to-vite/cra-to-vite.js.map +1 -1
  14. package/dist/migration/cra-to-vite/find-cra-config-blockers.d.ts.map +1 -1
  15. package/dist/migration/cra-to-vite/find-cra-config-blockers.js.map +1 -1
  16. package/dist/migration/cra-to-vite/find-cra-env-file-blockers.d.ts.map +1 -1
  17. package/dist/migration/cra-to-vite/find-cra-env-file-blockers.js.map +1 -1
  18. package/dist/migration/cra-to-vite/find-cra-source-blockers.d.ts.map +1 -1
  19. package/dist/migration/cra-to-vite/find-cra-source-blockers.js.map +1 -1
  20. package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.d.ts.map +1 -1
  21. package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.js.map +1 -1
  22. package/dist/migration/cra-to-vite/migrate-cra-package.d.ts.map +1 -1
  23. package/dist/migration/cra-to-vite/migrate-cra-package.js.map +1 -1
  24. package/dist/migration/cra-to-vite/migrate-cra-svg-imports.d.ts.map +1 -1
  25. package/dist/migration/cra-to-vite/migrate-cra-svg-imports.js +3 -3
  26. package/dist/migration/cra-to-vite/migrate-cra-svg-imports.js.map +1 -1
  27. package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.d.ts.map +1 -1
  28. package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.js.map +1 -1
  29. package/dist/migration/cra-to-vite/move-public-index-html.d.ts +1 -1
  30. package/dist/migration/cra-to-vite/move-public-index-html.d.ts.map +1 -1
  31. package/dist/migration/cra-to-vite/move-public-index-html.js +1 -1
  32. package/dist/migration/cra-to-vite/move-public-index-html.js.map +1 -1
  33. package/dist/migration/cra-to-vite/remove-cra-configuration.d.ts.map +1 -1
  34. package/dist/migration/cra-to-vite/remove-cra-configuration.js.map +1 -1
  35. package/dist/migration/cra-to-vite/rename-jsx-files.d.ts.map +1 -1
  36. package/dist/migration/cra-to-vite/rename-jsx-files.js.map +1 -1
  37. package/dist/migration/cra-to-vite/rename-process-env-react-app.d.ts +1 -1
  38. package/dist/migration/cra-to-vite/rename-process-env-react-app.d.ts.map +1 -1
  39. package/dist/migration/cra-to-vite/rename-process-env-react-app.js +1 -1
  40. package/dist/migration/cra-to-vite/rename-process-env-react-app.js.map +1 -1
  41. package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.d.ts +1 -1
  42. package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.d.ts.map +1 -1
  43. package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js +1 -1
  44. package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js.map +1 -1
  45. package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts +1 -1
  46. package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts.map +1 -1
  47. package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js +1 -1
  48. package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js.map +1 -1
  49. package/dist/migration/cra-to-vite/update-react-app-env-types.d.ts.map +1 -1
  50. package/dist/migration/cra-to-vite/update-react-app-env-types.js.map +1 -1
  51. package/dist/migration/cra-to-vite/update-react-scripts-scripts.d.ts.map +1 -1
  52. package/dist/migration/cra-to-vite/update-react-scripts-scripts.js.map +1 -1
  53. package/dist/migration/cra-to-vite/update-tsconfig-for-vite.d.ts.map +1 -1
  54. package/dist/migration/cra-to-vite/update-tsconfig-for-vite.js.map +1 -1
  55. package/dist/mui/adapt-v4-theme.d.ts.map +1 -1
  56. package/dist/mui/adapt-v4-theme.js +1 -1
  57. package/dist/mui/adapt-v4-theme.js.map +1 -1
  58. package/dist/mui/add-component-prop.d.ts.map +1 -1
  59. package/dist/mui/add-component-prop.js.map +1 -1
  60. package/dist/mui/add-emotion-prepend.d.ts.map +1 -1
  61. package/dist/mui/add-emotion-prepend.js +3 -16
  62. package/dist/mui/add-emotion-prepend.js.map +1 -1
  63. package/dist/mui/convert-mui-imports.d.ts.map +1 -1
  64. package/dist/mui/convert-mui-imports.js +1 -1
  65. package/dist/mui/convert-mui-imports.js.map +1 -1
  66. package/dist/mui/convert-prop-to-sx.d.ts.map +1 -1
  67. package/dist/mui/convert-prop-to-sx.js +1 -1
  68. package/dist/mui/convert-prop-to-sx.js.map +1 -1
  69. package/dist/mui/mark-manual-migration.d.ts.map +1 -1
  70. package/dist/mui/mark-manual-migration.js.map +1 -1
  71. package/dist/mui/mark-palette-mode-usage.d.ts.map +1 -1
  72. package/dist/mui/mark-palette-mode-usage.js.map +1 -1
  73. package/dist/mui/move-component-prop-to-slot.d.ts.map +1 -1
  74. package/dist/mui/move-component-prop-to-slot.js.map +1 -1
  75. package/dist/mui/move-primary-text-to-children.d.ts.map +1 -1
  76. package/dist/mui/move-primary-text-to-children.js.map +1 -1
  77. package/dist/mui/move-system-props-to-sx.d.ts.map +1 -1
  78. package/dist/mui/move-system-props-to-sx.js +1 -1
  79. package/dist/mui/move-system-props-to-sx.js.map +1 -1
  80. package/dist/mui/remove-component-prop.d.ts.map +1 -1
  81. package/dist/mui/remove-component-prop.js.map +1 -1
  82. package/dist/mui/remove-root-ref.d.ts.map +1 -1
  83. package/dist/mui/remove-root-ref.js +1 -1
  84. package/dist/mui/remove-root-ref.js.map +1 -1
  85. package/dist/mui/remove-spacing-px-suffix.d.ts.map +1 -1
  86. package/dist/mui/remove-spacing-px-suffix.js +7 -10
  87. package/dist/mui/remove-spacing-px-suffix.js.map +1 -1
  88. package/dist/mui/rename-component-prop.d.ts.map +1 -1
  89. package/dist/mui/rename-component-prop.js.map +1 -1
  90. package/dist/mui/rename-joy-css-variables.d.ts.map +1 -1
  91. package/dist/mui/rename-joy-css-variables.js.map +1 -1
  92. package/dist/mui/rename-theme-palette-type.d.ts.map +1 -1
  93. package/dist/mui/rename-theme-palette-type.js.map +1 -1
  94. package/dist/mui/replace-box-border-radius.d.ts.map +1 -1
  95. package/dist/mui/replace-box-border-radius.js.map +1 -1
  96. package/dist/mui/replace-breakpoints-width.d.ts.map +1 -1
  97. package/dist/mui/replace-breakpoints-width.js.map +1 -1
  98. package/dist/mui/replace-component-class.d.ts.map +1 -1
  99. package/dist/mui/replace-component-class.js.map +1 -1
  100. package/dist/mui/replace-components-with-slots.d.ts.map +1 -1
  101. package/dist/mui/replace-components-with-slots.js.map +1 -1
  102. package/dist/mui/replace-import-paths.d.ts.map +1 -1
  103. package/dist/mui/replace-import-paths.js.map +1 -1
  104. package/dist/mui/replace-in-string-literals.d.ts.map +1 -1
  105. package/dist/mui/replace-in-string-literals.js.map +1 -1
  106. package/dist/mui/replace-list-item-button-prop.d.ts.map +1 -1
  107. package/dist/mui/replace-list-item-button-prop.js +2 -2
  108. package/dist/mui/replace-list-item-button-prop.js.map +1 -1
  109. package/dist/mui/replace-tabs-scroll-buttons.d.ts.map +1 -1
  110. package/dist/mui/replace-tabs-scroll-buttons.js.map +1 -1
  111. package/dist/mui/replace-theme-color-functions.d.ts.map +1 -1
  112. package/dist/mui/replace-theme-color-functions.js +7 -21
  113. package/dist/mui/replace-theme-color-functions.js.map +1 -1
  114. package/dist/mui/replace-theme-spacing-unit.d.ts.map +1 -1
  115. package/dist/mui/replace-theme-spacing-unit.js.map +1 -1
  116. package/dist/mui/replace-typography-round.d.ts.map +1 -1
  117. package/dist/mui/replace-typography-round.js.map +1 -1
  118. package/dist/mui/shift-hidden-down-props.d.ts.map +1 -1
  119. package/dist/mui/shift-hidden-down-props.js +4 -5
  120. package/dist/mui/shift-hidden-down-props.js.map +1 -1
  121. package/dist/mui/update-theme-breakpoints.d.ts.map +1 -1
  122. package/dist/mui/update-theme-breakpoints.js.map +1 -1
  123. package/dist/mui/upgrade-grid-props.d.ts.map +1 -1
  124. package/dist/mui/upgrade-grid-props.js +1 -1
  125. package/dist/mui/upgrade-grid-props.js.map +1 -1
  126. package/dist/react-native/view-prop-types.d.ts.map +1 -1
  127. package/dist/react-native/view-prop-types.js +3 -9
  128. package/dist/react-native/view-prop-types.js.map +1 -1
  129. package/dist/react16/error-boundaries.d.ts.map +1 -1
  130. package/dist/react16/error-boundaries.js +1 -1
  131. package/dist/react16/error-boundaries.js.map +1 -1
  132. package/dist/react16/find-dom-node.d.ts.map +1 -1
  133. package/dist/react16/find-dom-node.js.map +1 -1
  134. package/dist/react16/react-dom-factories.d.ts.map +1 -1
  135. package/dist/react16/react-dom-factories.js.map +1 -1
  136. package/dist/react16/react-prop-types.d.ts.map +1 -1
  137. package/dist/react16/react-prop-types.js +3 -9
  138. package/dist/react16/react-prop-types.js.map +1 -1
  139. package/dist/react16/react-to-react-dom.d.ts.map +1 -1
  140. package/dist/react16/react-to-react-dom.js +2 -2
  141. package/dist/react16/react-to-react-dom.js.map +1 -1
  142. package/dist/react17/migrate-deprecated-lifecycles.d.ts +1 -1
  143. package/dist/react17/migrate-deprecated-lifecycles.d.ts.map +1 -1
  144. package/dist/react17/migrate-deprecated-lifecycles.js +5 -6
  145. package/dist/react17/migrate-deprecated-lifecycles.js.map +1 -1
  146. package/dist/react17/remove-event-persist.d.ts.map +1 -1
  147. package/dist/react17/remove-event-persist.js.map +1 -1
  148. package/dist/react17/rename-unsafe-lifecycles.d.ts.map +1 -1
  149. package/dist/react17/rename-unsafe-lifecycles.js +1 -1
  150. package/dist/react17/rename-unsafe-lifecycles.js.map +1 -1
  151. package/dist/react17/update-react-imports.d.ts.map +1 -1
  152. package/dist/react17/update-react-imports.js +1 -1
  153. package/dist/react17/update-react-imports.js.map +1 -1
  154. package/dist/react17/use-new-jsx-transform.d.ts +1 -1
  155. package/dist/react17/use-new-jsx-transform.d.ts.map +1 -1
  156. package/dist/react17/use-new-jsx-transform.js +2 -1
  157. package/dist/react17/use-new-jsx-transform.js.map +1 -1
  158. package/dist/react18/add-children-to-props.js +1 -1
  159. package/dist/react18/add-children-to-props.js.map +1 -1
  160. package/dist/react18/replace-reactdom-render.d.ts.map +1 -1
  161. package/dist/react18/replace-reactdom-render.js +1 -1
  162. package/dist/react18/replace-reactdom-render.js.map +1 -1
  163. package/dist/react18/replace-render-callback.d.ts.map +1 -1
  164. package/dist/react18/replace-render-callback.js +3 -12
  165. package/dist/react18/replace-render-callback.js.map +1 -1
  166. package/dist/react18/replace-unmount-component-at-node.d.ts.map +1 -1
  167. package/dist/react18/replace-unmount-component-at-node.js +1 -1
  168. package/dist/react18/replace-unmount-component-at-node.js.map +1 -1
  169. package/dist/react19/find-context-consumer.d.ts.map +1 -1
  170. package/dist/react19/find-context-consumer.js.map +1 -1
  171. package/dist/react19/find-deprecated-reactdom-apis.d.ts.map +1 -1
  172. package/dist/react19/find-deprecated-reactdom-apis.js +16 -61
  173. package/dist/react19/find-deprecated-reactdom-apis.js.map +1 -1
  174. package/dist/react19/find-element-ref.d.ts.map +1 -1
  175. package/dist/react19/find-element-ref.js.map +1 -1
  176. package/dist/react19/find-legacy-context-api.d.ts.map +1 -1
  177. package/dist/react19/find-legacy-context-api.js.map +1 -1
  178. package/dist/react19/no-implicit-ref-callback-return.d.ts.map +1 -1
  179. package/dist/react19/no-implicit-ref-callback-return.js +1 -1
  180. package/dist/react19/no-implicit-ref-callback-return.js.map +1 -1
  181. package/dist/react19/remove-context-provider.d.ts.map +1 -1
  182. package/dist/react19/remove-context-provider.js +1 -7
  183. package/dist/react19/remove-context-provider.js.map +1 -1
  184. package/dist/react19/remove-forward-ref.d.ts.map +1 -1
  185. package/dist/react19/remove-forward-ref.js +2 -2
  186. package/dist/react19/remove-forward-ref.js.map +1 -1
  187. package/dist/react19/remove-prop-types.d.ts.map +1 -1
  188. package/dist/react19/remove-prop-types.js.map +1 -1
  189. package/dist/react19/remove-react-fc.js +2 -2
  190. package/dist/react19/remove-react-fc.js.map +1 -1
  191. package/dist/react19/remove-unstable-batched-updates.d.ts +1 -1
  192. package/dist/react19/remove-unstable-batched-updates.d.ts.map +1 -1
  193. package/dist/react19/remove-unstable-batched-updates.js +9 -88
  194. package/dist/react19/remove-unstable-batched-updates.js.map +1 -1
  195. package/dist/{react16 → react19}/replace-create-factory.d.ts +1 -1
  196. package/dist/react19/replace-create-factory.d.ts.map +1 -0
  197. package/dist/{react16 → react19}/replace-create-factory.js +5 -5
  198. package/dist/react19/replace-create-factory.js.map +1 -0
  199. package/dist/react19/replace-reactdom-hydrate.d.ts.map +1 -1
  200. package/dist/react19/replace-reactdom-hydrate.js +1 -1
  201. package/dist/react19/replace-reactdom-hydrate.js.map +1 -1
  202. package/dist/react19/replace-string-ref.d.ts.map +1 -1
  203. package/dist/react19/replace-string-ref.js.map +1 -1
  204. package/dist/react19/scoped-jsx-namespace.d.ts.map +1 -1
  205. package/dist/react19/scoped-jsx-namespace.js +2 -6
  206. package/dist/react19/scoped-jsx-namespace.js.map +1 -1
  207. package/dist/react19/use-context-hook.d.ts.map +1 -1
  208. package/dist/react19/use-context-hook.js +1 -1
  209. package/dist/react19/use-context-hook.js.map +1 -1
  210. package/dist/react19/use-ref-required-initial.d.ts.map +1 -1
  211. package/dist/react19/use-ref-required-initial.js +3 -1
  212. package/dist/react19/use-ref-required-initial.js.map +1 -1
  213. package/dist/refactoring/class-to-functional.d.ts.map +1 -1
  214. package/dist/refactoring/class-to-functional.js +7 -3
  215. package/dist/refactoring/class-to-functional.js.map +1 -1
  216. package/dist/refactoring/create-class-to-es6.d.ts.map +1 -1
  217. package/dist/refactoring/create-class-to-es6.js +1 -1
  218. package/dist/refactoring/create-class-to-es6.js.map +1 -1
  219. package/dist/refactoring/create-element-to-jsx.d.ts.map +1 -1
  220. package/dist/refactoring/create-element-to-jsx.js +5 -7
  221. package/dist/refactoring/create-element-to-jsx.js.map +1 -1
  222. package/dist/refactoring/fix-async-effect.d.ts.map +1 -1
  223. package/dist/refactoring/fix-async-effect.js.map +1 -1
  224. package/dist/refactoring/manual-bind-to-arrow.d.ts.map +1 -1
  225. package/dist/refactoring/manual-bind-to-arrow.js.map +1 -1
  226. package/dist/refactoring/prop-types-to-typescript.d.ts +1 -1
  227. package/dist/refactoring/prop-types-to-typescript.d.ts.map +1 -1
  228. package/dist/refactoring/prop-types-to-typescript.js +2 -2
  229. package/dist/refactoring/prop-types-to-typescript.js.map +1 -1
  230. package/dist/refactoring/pure-render-mixin.d.ts.map +1 -1
  231. package/dist/refactoring/pure-render-mixin.js +2 -8
  232. package/dist/refactoring/pure-render-mixin.js.map +1 -1
  233. package/dist/refactoring/sort-comp.d.ts.map +1 -1
  234. package/dist/refactoring/sort-comp.js +1 -1
  235. package/dist/refactoring/sort-comp.js.map +1 -1
  236. package/dist/search/find-deprecated-lifecycles.d.ts +1 -1
  237. package/dist/search/find-deprecated-lifecycles.d.ts.map +1 -1
  238. package/dist/search/find-deprecated-lifecycles.js +2 -2
  239. package/dist/search/find-deprecated-lifecycles.js.map +1 -1
  240. package/dist/search/find-effects-without-cleanup.d.ts +1 -1
  241. package/dist/search/find-effects-without-cleanup.d.ts.map +1 -1
  242. package/dist/search/find-effects-without-cleanup.js +7 -9
  243. package/dist/search/find-effects-without-cleanup.js.map +1 -1
  244. package/dist/search/find-enzyme-usage.d.ts.map +1 -1
  245. package/dist/search/find-enzyme-usage.js.map +1 -1
  246. package/dist/search/find-function-component-default-props.d.ts +1 -1
  247. package/dist/search/find-function-component-default-props.d.ts.map +1 -1
  248. package/dist/search/find-function-component-default-props.js +2 -2
  249. package/dist/search/find-function-component-default-props.js.map +1 -1
  250. package/dist/search/find-hard-coded-strings.d.ts.map +1 -1
  251. package/dist/search/find-hard-coded-strings.js.map +1 -1
  252. package/dist/search/find-hook-usage.d.ts.map +1 -1
  253. package/dist/search/find-hook-usage.js.map +1 -1
  254. package/dist/search/find-legacy-react-apis.d.ts +1 -1
  255. package/dist/search/find-legacy-react-apis.d.ts.map +1 -1
  256. package/dist/search/find-legacy-react-apis.js +1 -1
  257. package/dist/search/find-legacy-react-apis.js.map +1 -1
  258. package/dist/search/find-missing-use-client-directive.d.ts.map +1 -1
  259. package/dist/search/find-missing-use-client-directive.js +11 -10
  260. package/dist/search/find-missing-use-client-directive.js.map +1 -1
  261. package/dist/search/find-prop-usage.d.ts.map +1 -1
  262. package/dist/search/find-prop-usage.js.map +1 -1
  263. package/dist/search/find-react-component.d.ts.map +1 -1
  264. package/dist/search/find-react-component.js.map +1 -1
  265. package/dist/search/find-reactdom-root-apis.d.ts.map +1 -1
  266. package/dist/search/find-reactdom-root-apis.js +2 -42
  267. package/dist/search/find-reactdom-root-apis.js.map +1 -1
  268. package/dist/search/find-redux-stores.d.ts +1 -1
  269. package/dist/search/find-redux-stores.d.ts.map +1 -1
  270. package/dist/search/find-redux-stores.js +1 -1
  271. package/dist/search/find-redux-stores.js.map +1 -1
  272. package/dist/search/find-server-rendering-usage.d.ts.map +1 -1
  273. package/dist/search/find-server-rendering-usage.js +13 -54
  274. package/dist/search/find-server-rendering-usage.js.map +1 -1
  275. package/dist/simplify-object-pattern-property.d.ts.map +1 -1
  276. package/dist/simplify-object-pattern-property.js.map +1 -1
  277. package/dist/simplify-react-imports.d.ts.map +1 -1
  278. package/dist/simplify-react-imports.js +1 -1
  279. package/dist/simplify-react-imports.js.map +1 -1
  280. package/dist/testing/enzyme-host-components.d.ts.map +1 -1
  281. package/dist/testing/enzyme-host-components.js +2 -2
  282. package/dist/testing/enzyme-host-components.js.map +1 -1
  283. package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
  284. package/dist/testing/enzyme-to-react-testing-library.js +11 -19
  285. package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
  286. package/dist/testing/enzyme-usage.js +2 -2
  287. package/dist/testing/enzyme-usage.js.map +1 -1
  288. package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
  289. package/dist/testing/enzyme-wrapper-scope.js +5 -12
  290. package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
  291. package/dist/util/react-class.d.ts +2 -0
  292. package/dist/util/react-class.d.ts.map +1 -1
  293. package/dist/util/react-class.js +14 -0
  294. package/dist/util/react-class.js.map +1 -1
  295. package/dist/util/react-matchers.d.ts +8 -0
  296. package/dist/util/react-matchers.d.ts.map +1 -0
  297. package/dist/util/react-matchers.js +25 -0
  298. package/dist/util/react-matchers.js.map +1 -0
  299. package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
  300. package/dist/zustand/redux-to-zustand.js +20 -20
  301. package/dist/zustand/redux-to-zustand.js.map +1 -1
  302. package/package.json +2 -2
  303. package/src/i18n/translate-hard-coded-strings.ts +5 -12
  304. package/src/index.ts +3 -12
  305. package/src/migration/change-component-prop-value.ts +0 -40
  306. package/src/migration/cra-to-vite/add-vite-config.ts +0 -10
  307. package/src/migration/cra-to-vite/cra-to-vite.ts +0 -3
  308. package/src/migration/cra-to-vite/find-cra-config-blockers.ts +2 -7
  309. package/src/migration/cra-to-vite/find-cra-env-file-blockers.ts +0 -7
  310. package/src/migration/cra-to-vite/find-cra-source-blockers.ts +0 -9
  311. package/src/migration/cra-to-vite/find-cra-to-vite-blockers.ts +0 -4
  312. package/src/migration/cra-to-vite/migrate-cra-package.ts +0 -1
  313. package/src/migration/cra-to-vite/migrate-cra-svg-imports.ts +3 -4
  314. package/src/migration/cra-to-vite/migrate-cra-tests-to-vitest.ts +1 -3
  315. package/src/migration/cra-to-vite/move-public-index-html.ts +1 -13
  316. package/src/migration/cra-to-vite/remove-cra-configuration.ts +0 -1
  317. package/src/migration/cra-to-vite/rename-jsx-files.ts +0 -4
  318. package/src/migration/cra-to-vite/rename-process-env-react-app.ts +1 -17
  319. package/src/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.ts +1 -11
  320. package/src/migration/cra-to-vite/replace-react-scripts-dependency.ts +1 -12
  321. package/src/migration/cra-to-vite/update-react-app-env-types.ts +0 -9
  322. package/src/migration/cra-to-vite/update-react-scripts-scripts.ts +0 -15
  323. package/src/migration/cra-to-vite/update-tsconfig-for-vite.ts +0 -11
  324. package/src/mui/adapt-v4-theme.ts +2 -7
  325. package/src/mui/add-component-prop.ts +0 -7
  326. package/src/mui/add-emotion-prepend.ts +5 -17
  327. package/src/mui/convert-mui-imports.ts +1 -12
  328. package/src/mui/convert-prop-to-sx.ts +1 -9
  329. package/src/mui/mark-manual-migration.ts +0 -6
  330. package/src/mui/mark-palette-mode-usage.ts +0 -6
  331. package/src/mui/move-component-prop-to-slot.ts +0 -9
  332. package/src/mui/move-primary-text-to-children.ts +0 -5
  333. package/src/mui/move-system-props-to-sx.ts +1 -11
  334. package/src/mui/remove-component-prop.ts +0 -5
  335. package/src/mui/remove-root-ref.ts +2 -8
  336. package/src/mui/remove-spacing-px-suffix.ts +3 -11
  337. package/src/mui/rename-component-prop.ts +0 -7
  338. package/src/mui/rename-joy-css-variables.ts +0 -6
  339. package/src/mui/rename-theme-palette-type.ts +0 -5
  340. package/src/mui/replace-box-border-radius.ts +0 -5
  341. package/src/mui/replace-breakpoints-width.ts +0 -2
  342. package/src/mui/replace-component-class.ts +0 -10
  343. package/src/mui/replace-components-with-slots.ts +0 -8
  344. package/src/mui/replace-import-paths.ts +0 -11
  345. package/src/mui/replace-in-string-literals.ts +0 -7
  346. package/src/mui/replace-list-item-button-prop.ts +3 -10
  347. package/src/mui/replace-tabs-scroll-buttons.ts +0 -5
  348. package/src/mui/replace-theme-color-functions.ts +9 -26
  349. package/src/mui/replace-theme-spacing-unit.ts +0 -6
  350. package/src/mui/replace-typography-round.ts +0 -5
  351. package/src/mui/shift-hidden-down-props.ts +3 -12
  352. package/src/mui/update-theme-breakpoints.ts +0 -8
  353. package/src/mui/upgrade-grid-props.ts +1 -9
  354. package/src/react-native/view-prop-types.ts +4 -26
  355. package/src/react16/error-boundaries.ts +1 -20
  356. package/src/react16/find-dom-node.ts +0 -17
  357. package/src/react16/react-dom-factories.ts +0 -14
  358. package/src/react16/react-prop-types.ts +4 -29
  359. package/src/react16/react-to-react-dom.ts +3 -20
  360. package/src/react17/migrate-deprecated-lifecycles.ts +6 -21
  361. package/src/react17/remove-event-persist.ts +2 -27
  362. package/src/react17/rename-unsafe-lifecycles.ts +1 -24
  363. package/src/react17/update-react-imports.ts +2 -27
  364. package/src/react17/use-new-jsx-transform.ts +2 -15
  365. package/src/react18/add-children-to-props.ts +2 -2
  366. package/src/react18/replace-reactdom-render.ts +2 -24
  367. package/src/react18/replace-render-callback.ts +5 -31
  368. package/src/react18/replace-unmount-component-at-node.ts +2 -22
  369. package/src/react19/find-context-consumer.ts +0 -23
  370. package/src/react19/find-deprecated-reactdom-apis.ts +20 -80
  371. package/src/react19/find-element-ref.ts +0 -15
  372. package/src/react19/find-legacy-context-api.ts +0 -12
  373. package/src/react19/no-implicit-ref-callback-return.ts +1 -19
  374. package/src/react19/remove-context-provider.ts +1 -25
  375. package/src/react19/remove-forward-ref.ts +3 -18
  376. package/src/react19/remove-prop-types.ts +0 -24
  377. package/src/react19/remove-react-fc.ts +3 -3
  378. package/src/react19/remove-unstable-batched-updates.ts +15 -129
  379. package/src/{react16 → react19}/replace-create-factory.ts +8 -21
  380. package/src/react19/replace-reactdom-hydrate.ts +2 -19
  381. package/src/react19/replace-string-ref.ts +0 -14
  382. package/src/react19/scoped-jsx-namespace.ts +3 -7
  383. package/src/react19/use-context-hook.ts +2 -20
  384. package/src/react19/use-ref-required-initial.ts +4 -17
  385. package/src/refactoring/class-to-functional.ts +9 -33
  386. package/src/refactoring/create-class-to-es6.ts +1 -15
  387. package/src/refactoring/create-element-to-jsx.ts +7 -31
  388. package/src/refactoring/fix-async-effect.ts +0 -28
  389. package/src/refactoring/manual-bind-to-arrow.ts +0 -23
  390. package/src/refactoring/prop-types-to-typescript.ts +3 -34
  391. package/src/refactoring/pure-render-mixin.ts +3 -30
  392. package/src/refactoring/sort-comp.ts +1 -11
  393. package/src/search/find-deprecated-lifecycles.ts +3 -6
  394. package/src/search/find-effects-without-cleanup.ts +5 -15
  395. package/src/search/find-enzyme-usage.ts +0 -3
  396. package/src/search/find-function-component-default-props.ts +3 -7
  397. package/src/search/find-hard-coded-strings.ts +0 -9
  398. package/src/search/find-hook-usage.ts +0 -10
  399. package/src/search/find-legacy-react-apis.ts +1 -18
  400. package/src/search/find-missing-use-client-directive.ts +13 -19
  401. package/src/search/find-prop-usage.ts +0 -11
  402. package/src/search/find-react-component.ts +0 -11
  403. package/src/search/find-reactdom-root-apis.ts +5 -44
  404. package/src/search/find-redux-stores.ts +1 -9
  405. package/src/search/find-server-rendering-usage.ts +15 -72
  406. package/src/simplify-object-pattern-property.ts +0 -8
  407. package/src/simplify-react-imports.ts +3 -23
  408. package/src/testing/enzyme-host-components.ts +3 -2
  409. package/src/testing/enzyme-to-react-testing-library.ts +10 -50
  410. package/src/testing/enzyme-usage.ts +2 -2
  411. package/src/testing/enzyme-wrapper-scope.ts +7 -15
  412. package/src/util/react-class.ts +17 -1
  413. package/src/util/react-matchers.ts +34 -0
  414. package/src/zustand/redux-to-zustand.ts +21 -75
  415. package/dist/react16/replace-create-factory.d.ts.map +0 -1
  416. package/dist/react16/replace-create-factory.js.map +0 -1
  417. package/dist/react19/replace-act-import.d.ts +0 -9
  418. package/dist/react19/replace-act-import.d.ts.map +0 -1
  419. package/dist/react19/replace-act-import.js +0 -34
  420. package/dist/react19/replace-act-import.js.map +0 -1
  421. package/dist/react19/replace-react-shallow-renderer.d.ts +0 -8
  422. package/dist/react19/replace-react-shallow-renderer.d.ts.map +0 -1
  423. package/dist/react19/replace-react-shallow-renderer.js +0 -49
  424. package/dist/react19/replace-react-shallow-renderer.js.map +0 -1
  425. package/dist/react19/replace-use-form-state.d.ts +0 -8
  426. package/dist/react19/replace-use-form-state.d.ts.map +0 -1
  427. package/dist/react19/replace-use-form-state.js +0 -57
  428. package/dist/react19/replace-use-form-state.js.map +0 -1
  429. package/src/react19/replace-act-import.ts +0 -36
  430. package/src/react19/replace-react-shallow-renderer.ts +0 -47
  431. package/src/react19/replace-use-form-state.ts +0 -69
@@ -1,64 +1,30 @@
1
- import {Cursor, ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, maybeRemoveImport, isVendoredOrBundled, moduleBindings, declarationsOf, bindingNames, resolve} from "@openrewrite/rewrite/javascript";
3
- import {isIdentifier, J, Statement} from "@openrewrite/rewrite/java";
1
+ import {ExecutionContext, Recipe, TreeVisitor, and, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, JS, MethodMatcher, maybeUnbind, isVendoredOrBundled, usesMethod} from "@openrewrite/rewrite/javascript";
3
+ import {J, Statement} from "@openrewrite/rewrite/java";
4
4
  import {create} from "mutative";
5
5
  import {reindent} from "../util/reindent";
6
6
 
7
7
  const REACT_DOM = "react-dom";
8
8
  const BATCHED_UPDATES = "unstable_batchedUpdates";
9
+ const BATCHED_UPDATES_PATTERN = `${REACT_DOM} ${BATCHED_UPDATES}(..)`;
10
+ const BATCHED_UPDATES_CALL = new MethodMatcher(BATCHED_UPDATES_PATTERN);
9
11
 
10
12
  /**
11
- * Removes `unstable_batchedUpdates` wrappers from `react-dom`.
12
- *
13
- * In React 18, all state updates are automatically batched,
14
- * making `unstable_batchedUpdates` unnecessary. This recipe
15
- * unwraps the callback body and removes the wrapping call.
16
- *
17
- * Automatic batching only applies to roots created with `createRoot` or
18
- * `hydrateRoot`; a legacy `ReactDOM.render` or `hydrate` root still needs the
19
- * wrapper. React 19 removes the legacy APIs, so this recipe runs in the
20
- * React 18 to 19 migration rather than the 17 to 18 one.
21
- *
22
- * Before:
23
- * ```tsx
24
- * import { unstable_batchedUpdates } from 'react-dom';
25
- *
26
- * unstable_batchedUpdates(() => {
27
- * setCount(1);
28
- * setFlag(true);
29
- * });
30
- * ```
31
- *
32
- * After:
33
- * ```tsx
34
- * setCount(1);
35
- * setFlag(true);
36
- * ```
37
- *
38
- * Only calls that resolve to `react-dom` through an import or `require` are
39
- * unwrapped, so a local helper of the same name and the `react-native` export
40
- * are left alone. A call is also left in place, which is harmless in React 18,
41
- * when the body would mean something else in the enclosing scope: it uses
42
- * `return`, `this` or `arguments`, the callback is `async`, or the body declares
43
- * a variable, function or class.
13
+ * Automatic batching only applies to roots created with `createRoot` or `hydrateRoot`; a legacy `ReactDOM.render`
14
+ * or `hydrate` root still needs the wrapper. React 19 removes the legacy APIs, so this runs in the React 18 to 19
15
+ * migration rather than the 17 to 18 one.
44
16
  *
45
17
  * @see https://react.dev/blog/2022/03/29/react-v18#new-feature-automatic-batching
46
18
  */
47
19
  export class RemoveUnstableBatchedUpdates extends Recipe {
48
20
  readonly name = "org.openrewrite.react.19.remove-unstable-batched-updates";
49
21
  readonly displayName = "Remove `unstable_batchedUpdates`";
50
- readonly description = "Removes `unstable_batchedUpdates` wrappers from `react-dom`. React 18 automatically batches all state updates on roots created with `createRoot` or `hydrateRoot`, the only roots React 19 supports, making this function unnecessary.";
22
+ readonly description = "Removes `unstable_batchedUpdates` wrappers from `react-dom`. React 18 automatically batches all state updates on roots created with `createRoot` or `hydrateRoot`, the only roots React 19 supports, making this function unnecessary. " +
23
+ "A call is left in place, which is harmless, when its body would mean something else unwrapped: it uses `return`, `this` or `arguments`, the callback is `async`, or the body declares a variable, function or class.";
51
24
 
52
25
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
53
- return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
54
- private changed = false;
55
- private names: ReadonlySet<string> = new Set();
56
-
26
+ return check(and(not(isVendoredOrBundled()), usesMethod(BATCHED_UPDATES_PATTERN)), new class extends JavaScriptVisitor<ExecutionContext> {
57
27
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
58
- this.changed = false;
59
- this.names = batchedUpdatesNames(cu);
60
- if (this.names.size === 0 && moduleBindings(this).moduleSystem === "none") return cu;
61
-
62
28
  let result = await super.visitJsCompilationUnit(cu, ctx) as JS.CompilationUnit;
63
29
 
64
30
  const statements = await this.spliceStatements(result.statements);
@@ -68,8 +34,8 @@ export class RemoveUnstableBatchedUpdates extends Recipe {
68
34
  });
69
35
  }
70
36
 
71
- if (this.changed) {
72
- maybeRemoveImport(this, REACT_DOM, BATCHED_UPDATES);
37
+ if (result !== cu) {
38
+ maybeUnbind(this, {module: REACT_DOM, member: BATCHED_UPDATES});
73
39
  }
74
40
 
75
41
  return result;
@@ -86,7 +52,6 @@ export class RemoveUnstableBatchedUpdates extends Recipe {
86
52
 
87
53
  private async spliceStatements(statements: J.RightPadded<Statement>[]): Promise<J.RightPadded<Statement>[] | null> {
88
54
  const newStatements: J.RightPadded<Statement>[] = [];
89
- let changed = false;
90
55
 
91
56
  for (const paddedStmt of statements) {
92
57
  const stmt = paddedStmt.element;
@@ -102,11 +67,9 @@ export class RemoveUnstableBatchedUpdates extends Recipe {
102
67
  const element = await reindent(bodyStmt.element, innerIndent, outerIndent);
103
68
  newStatements.push({...bodyStmt, element: i === 0 ? {...element, prefix: joinPrefixes(stmt.prefix, element.prefix)} : element});
104
69
  }
105
- changed = true;
106
- this.changed = true;
107
70
  }
108
71
 
109
- return changed ? newStatements : null;
72
+ return newStatements.length === statements.length && newStatements.every((s, i) => s === statements[i]) ? null : newStatements;
110
73
  }
111
74
 
112
75
  private async extractBatchedUpdatesBody(stmt: Statement): Promise<J.RightPadded<Statement>[] | null> {
@@ -121,7 +84,7 @@ export class RemoveUnstableBatchedUpdates extends Recipe {
121
84
  if (!expr || expr.kind !== J.Kind.MethodInvocation) return null;
122
85
 
123
86
  const method = expr as J.MethodInvocation;
124
- if (!isBatchedUpdatesCall(this, this.names, new Cursor(stmt, this.cursor), method)) return null;
87
+ if (!BATCHED_UPDATES_CALL.matches(method.methodType)) return null;
125
88
 
126
89
  const callback = method.arguments?.elements[0]?.element as J | undefined;
127
90
  if (callback?.kind !== JS.Kind.ArrowFunction) return null;
@@ -213,83 +176,6 @@ class ScopeEscapeFinder extends JavaScriptVisitor<ExecutionContext> {
213
176
  }
214
177
  }
215
178
 
216
- /**
217
- * Local names of `unstable_batchedUpdates` that `react-dom` binds at the top level of the file:
218
- * `import {unstable_batchedUpdates as batch}` and `const {unstable_batchedUpdates: batch} = require(...)`.
219
- * Whole-module bindings (`import X`, `import * as X`, `const X = require(...)`) are
220
- * `moduleBindings(...).moduleOf`'s to answer.
221
- */
222
- function batchedUpdatesNames(cu: JS.CompilationUnit): Set<string> {
223
- const names = new Set<string>();
224
- for (const padded of cu.statements) {
225
- const stmt = padded.element as J;
226
- if (stmt.kind === JS.Kind.Import) {
227
- const imp = stmt as JS.Import;
228
- const named = imp.importClause?.namedBindings as J | undefined;
229
- if (!isReactDomLiteral(unwrap(imp.moduleSpecifier)) || named?.kind !== JS.Kind.NamedImports) continue;
230
- for (const el of (named as JS.NamedImports).elements.elements) {
231
- const specifier = el.element.specifier as J;
232
- if (isIdentifier(specifier)) {
233
- if (specifier.simpleName === BATCHED_UPDATES) names.add(BATCHED_UPDATES);
234
- } else if (specifier.kind === JS.Kind.Alias) {
235
- const alias = specifier as JS.Alias;
236
- const imported = alias.propertyName.element;
237
- if (isIdentifier(imported) && imported.simpleName === BATCHED_UPDATES && isIdentifier(alias.alias)) {
238
- names.add(alias.alias.simpleName);
239
- }
240
- }
241
- }
242
- } else {
243
- for (const decl of declarationsOf(stmt)) {
244
- for (const v of decl.variables) {
245
- if (!isRequireOfReactDom(unwrap(v.element.initializer as J | { element: J } | undefined))) continue;
246
- for (const {name, member} of bindingNames(v.element.name as J)) {
247
- if (member === BATCHED_UPDATES) names.add(name);
248
- }
249
- }
250
- }
251
- }
252
- }
253
- return names;
254
- }
255
-
256
- /**
257
- * Whether the call is `react-dom`'s `unstable_batchedUpdates`: its callee resolves to the
258
- * compilation unit, so a parameter or local of the same name does not count.
259
- */
260
- function isBatchedUpdatesCall(visitor: JavaScriptVisitor<ExecutionContext>, names: ReadonlySet<string>, cursor: Cursor, method: J.MethodInvocation): boolean {
261
- const select = method.select ? unwrap(method.select as J | { element: J }) : undefined;
262
- if (!select) {
263
- return names.has(method.name.simpleName) && resolvesToFile(cursor, method.name);
264
- }
265
- return method.name.simpleName === BATCHED_UPDATES
266
- && isIdentifier(select)
267
- && moduleBindings(visitor).moduleOf(select.simpleName) === REACT_DOM
268
- && resolvesToFile(cursor, select);
269
- }
270
-
271
- function resolvesToFile(cursor: Cursor, identifier: J.Identifier): boolean {
272
- return resolve(new Cursor(identifier, cursor), identifier)?.kind === JS.Kind.CompilationUnit;
273
- }
274
-
275
- function isReactDomLiteral(expr: unknown): boolean {
276
- const literal = expr as J.Literal | undefined;
277
- return literal?.kind === J.Kind.Literal && literal.value === REACT_DOM;
278
- }
279
-
280
- function isRequireOfReactDom(expr: J | undefined): boolean {
281
- if (expr?.kind !== J.Kind.MethodInvocation) return false;
282
- const call = expr as J.MethodInvocation;
283
- return !call.select
284
- && call.name.simpleName === "require"
285
- && isReactDomLiteral(call.arguments.elements[0]?.element);
286
- }
287
-
288
- /** LST fields are sometimes wrapped in a `LeftPadded`/`RightPadded`; reads the node either way. */
289
- function unwrap<T>(value: T | { element: T } | undefined): T | undefined {
290
- return value && typeof value === "object" && "element" in value ? value.element : value as T | undefined;
291
- }
292
-
293
179
  /** The call's line break and comments, then those of the first statement that replaces it. */
294
180
  function joinPrefixes(call: J.Space, first: J.Space): J.Space {
295
181
  return {...call, comments: [...call.comments, ...first.comments]};
@@ -1,29 +1,17 @@
1
1
  import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
2
  import {JavaScriptVisitor, JS, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J, singleSpace} from "@openrewrite/rewrite/java";
4
+ import {reactFunction, typedOrNamedCall} from "../util/react-matchers";
5
+
6
+ const CREATE_FACTORY = typedOrNamedCall(reactFunction("createFactory"), "React", "createFactory");
4
7
 
5
8
  /**
6
- * Replaces `React.createFactory(type)(props, children)` with
7
- * `React.createElement(type, props, children)`.
8
- *
9
- * `React.createFactory` was deprecated in React 15.6 and removed in React 16.
10
- * This recipe handles the case where the factory is immediately invoked inline
11
- * (chained call), transforming it into the equivalent `createElement` call.
12
- *
13
- * Before:
14
- * ```tsx
15
- * const el = React.createFactory('div')({className: 'foo'}, 'Hello');
16
- * ```
17
- *
18
- * After:
19
- * ```tsx
20
- * const el = React.createElement('div', {className: 'foo'}, 'Hello');
21
- * ```
9
+ * @see https://legacy.reactjs.org/blog/2020/02/26/react-v16.13.0.html#deprecating-reactcreatefactory
22
10
  */
23
11
  export class ReplaceCreateFactory extends Recipe {
24
- readonly name = "org.openrewrite.react.16.replace-create-factory";
12
+ readonly name = "org.openrewrite.react.19.replace-create-factory";
25
13
  readonly displayName: string = "Replace `React.createFactory` with `React.createElement`";
26
- readonly description: string = "Replaces `React.createFactory(type)(props, children)` with `React.createElement(type, props, children)`. React.createFactory was deprecated in React 15.6 and removed in React 16.";
14
+ readonly description: string = "Replaces `React.createFactory(type)(props, children)` with `React.createElement(type, props, children)`. `React.createFactory` was deprecated in React 16.13 and removed in React 19. Only a factory that is called right away is replaced.";
27
15
 
28
16
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
29
17
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
@@ -37,9 +25,8 @@ export class ReplaceCreateFactory extends Recipe {
37
25
  if (callee.kind !== J.Kind.MethodInvocation) return fc;
38
26
  const innerCall = callee as J.MethodInvocation;
39
27
 
40
- if (innerCall.name.simpleName !== 'createFactory') return fc;
41
-
42
- if (!innerCall.select) return fc;
28
+ // Without a receiver, the `createElement` the result would call is not imported
29
+ if (!innerCall.select || !CREATE_FACTORY(innerCall)) return fc;
43
30
 
44
31
  const innerArgs = innerCall.arguments?.elements;
45
32
  if (!innerArgs || innerArgs.length !== 1) return fc;
@@ -2,7 +2,7 @@ import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/re
2
2
  import {
3
3
  capture,
4
4
  JavaScriptVisitor,
5
- maybeRemoveImport,
5
+ maybeUnbind,
6
6
  pattern,
7
7
  rewrite,
8
8
  template,
@@ -11,23 +11,6 @@ import {
11
11
  import {Expression, J} from "@openrewrite/rewrite/java";
12
12
 
13
13
  /**
14
- * Replaces `ReactDOM.hydrate()` with `hydrateRoot()`.
15
- *
16
- * In React 18+, `ReactDOM.hydrate()` is deprecated in favor of
17
- * `hydrateRoot()` from `react-dom/client`.
18
- *
19
- * Before:
20
- * ```tsx
21
- * import ReactDOM from 'react-dom';
22
- * ReactDOM.hydrate(<App />, document.getElementById('root'));
23
- * ```
24
- *
25
- * After:
26
- * ```tsx
27
- * import { hydrateRoot } from 'react-dom/client';
28
- * hydrateRoot(document.getElementById('root'), <App />);
29
- * ```
30
- *
31
14
  * @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-reactdom-hydrate
32
15
  */
33
16
  export class ReplaceReactDomHydrate extends Recipe {
@@ -58,7 +41,7 @@ export class ReplaceReactDomHydrate extends Recipe {
58
41
 
59
42
  const result = await rule.tryOn(this.cursor, m!, {visitor: this});
60
43
  if (result) {
61
- maybeRemoveImport(this, "react-dom", "hydrate");
44
+ maybeUnbind(this, {module: "react-dom", member: "hydrate"});
62
45
  return result;
63
46
  }
64
47
 
@@ -4,20 +4,6 @@ import {J} from "@openrewrite/rewrite/java";
4
4
  import {JS, JSX} from "@openrewrite/rewrite/javascript";
5
5
 
6
6
  /**
7
- * Replaces deprecated string refs with callback refs.
8
- *
9
- * String refs have been deprecated in React and are removed in React 19.
10
- *
11
- * Before:
12
- * ```tsx
13
- * <input ref="myInput" />
14
- * ```
15
- *
16
- * After:
17
- * ```tsx
18
- * <input ref={(ref) => { this.myInput = ref; }} />
19
- * ```
20
- *
21
7
  * @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-string-refs
22
8
  */
23
9
  export class ReplaceStringRef extends Recipe {
@@ -1,8 +1,7 @@
1
1
  import {emptyMarkers, ExecutionContext, randomId, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
2
  import {emptySpace, isIdentifier, J, rightPadded, Type} from "@openrewrite/rewrite/java";
3
- import {JavaScriptVisitor, JS, maybeAddImport, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
+ import {JavaScriptVisitor, JS, maybeBind, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
4
4
 
5
- /** Imports the scoped namespace that replaces React's global JSX types in React 19. */
6
5
  export class ScopedJsxNamespace extends Recipe {
7
6
  readonly name = "org.openrewrite.react.19.scoped-jsx-namespace";
8
7
  readonly displayName = "Import the scoped React JSX namespace";
@@ -31,10 +30,7 @@ export class ScopedJsxNamespace extends Recipe {
31
30
  override async visitFieldAccess(field: J.FieldAccess, ctx: ExecutionContext): Promise<J | undefined> {
32
31
  const fa = await super.visitFieldAccess(field, ctx) as J.FieldAccess;
33
32
  if (this.declaresJsx || !isIdentifier(fa.target) || fa.target.simpleName !== 'JSX') return fa;
34
- let type = fa.type;
35
- if (type?.kind === Type.Kind.Parameterized) type = (type as Type.Parameterized).type;
36
- const name = (type as Type.Class | undefined)?.fullyQualifiedName;
37
- if (!name?.startsWith('JSX.')) return fa;
33
+ if (!Type.isOfTypeWithName(fa.type, false, name => name.startsWith('JSX.'))) return fa;
38
34
  if (this.declarationFile) {
39
35
  // An inline import type leaves ambient modules ambient and avoids introducing
40
36
  // a top-level import into a declaration file that was previously a script.
@@ -60,7 +56,7 @@ export class ScopedJsxNamespace extends Recipe {
60
56
  type: fa.type
61
57
  } as JS.ImportType;
62
58
  }
63
- const local = maybeAddImport(this, {module: 'react', member: 'JSX', typeOnly: true, onlyIfReferenced: false});
59
+ const local = maybeBind(this, {module: 'react', member: 'JSX', typeOnly: true, onlyIfReferenced: false});
64
60
  return local === fa.target.simpleName ? fa : {
65
61
  ...fa, target: {...fa.target, simpleName: local}
66
62
  } as J.FieldAccess;
@@ -1,7 +1,7 @@
1
1
  import {ExecutionContext, Recipe, TreeVisitor, check, not, and} from "@openrewrite/rewrite";
2
2
  import {
3
3
  JavaScriptVisitor,
4
- maybeRemoveImport,
4
+ maybeUnbind,
5
5
  capture,
6
6
  pattern,
7
7
  rewrite,
@@ -12,24 +12,6 @@ import {
12
12
  import {Expression, J} from "@openrewrite/rewrite/java";
13
13
 
14
14
  /**
15
- * Replaces `useContext()` with `use()` for React 19.
16
- *
17
- * In React 19, `useContext` is replaced by the new `use` API.
18
- *
19
- * Before:
20
- * ```tsx
21
- * import { useContext } from 'react';
22
- * const theme = useContext(ThemeContext);
23
- * ```
24
- *
25
- * After:
26
- * ```tsx
27
- * import { use } from 'react';
28
- * const theme = use(ThemeContext);
29
- * ```
30
- *
31
- * Also handles `React.useContext()` → `React.use()`.
32
- *
33
15
  * @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#use-context
34
16
  */
35
17
  export class UseContextHook extends Recipe {
@@ -62,7 +44,7 @@ export class UseContextHook extends Recipe {
62
44
  if (m.typeParameters) return m;
63
45
  const result = await rule.tryOn(this.cursor, m!, {visitor: this});
64
46
  if (result) {
65
- maybeRemoveImport(this, "react", "useContext");
47
+ maybeUnbind(this, {module: "react", member: "useContext"});
66
48
  return result;
67
49
  }
68
50
 
@@ -2,23 +2,11 @@ import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/re
2
2
  import {JavaScriptVisitor, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {isIdentifier, J, Type} from "@openrewrite/rewrite/java";
4
4
  import {create} from "mutative";
5
+ import {reactFunction} from "../util/react-matchers";
6
+
7
+ const USE_REF = reactFunction("useRef");
5
8
 
6
9
  /**
7
- * Adds `undefined` argument to `useRef()` calls with no arguments.
8
- *
9
- * In `@types/react` 19, `useRef()` with no arguments is no longer valid.
10
- * You must pass an explicit initial value, typically `undefined` or `null`.
11
- *
12
- * Before:
13
- * ```tsx
14
- * const ref = useRef();
15
- * ```
16
- *
17
- * After:
18
- * ```tsx
19
- * const ref = useRef(undefined);
20
- * ```
21
- *
22
10
  * @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#useref-requires-argument
23
11
  */
24
12
  export class UseRefRequiredInitial extends Recipe {
@@ -31,8 +19,7 @@ export class UseRefRequiredInitial extends Recipe {
31
19
  override async visitMethodInvocation(method: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
32
20
  let m = await super.visitMethodInvocation(method, ctx) as J.MethodInvocation;
33
21
 
34
- // Match useRef() or React.useRef() with no arguments
35
- if (m.name.simpleName !== 'useRef') return m;
22
+ if (!USE_REF.matches(m.methodType)) return m;
36
23
 
37
24
  // Check it has no arguments (empty args list)
38
25
  const args = m.arguments;
@@ -1,7 +1,7 @@
1
1
  import {ExecutionContext, Recipe, TreeVisitor, check, not, randomId} from "@openrewrite/rewrite";
2
- import {capture, JavaScriptVisitor, pattern, raw, rewrite, template, isVendoredOrBundled, maybeAddImport, maybeRemoveImport, namesDeclaredWithin, namesReferencedWithin} from "@openrewrite/rewrite/javascript";
2
+ import {capture, JavaScriptVisitor, pattern, raw, rewrite, template, isVendoredOrBundled, maybeBind, maybeUnbind, namesDeclaredWithin, namesReferencedWithin} from "@openrewrite/rewrite/javascript";
3
3
  import {J, singleSpace} from "@openrewrite/rewrite/java";
4
- import {baseTypeArguments, unwrapBaseType} from "../util/react-class";
4
+ import {baseTypeArguments, reactComponentSupertype, unwrapBaseType} from "../util/react-class";
5
5
 
6
6
  const LIFECYCLE_METHODS = new Set([
7
7
  'componentWillMount', 'UNSAFE_componentWillMount',
@@ -15,40 +15,12 @@ const LIFECYCLE_METHODS = new Set([
15
15
  ]);
16
16
 
17
17
  /**
18
- * Converts simple class components (render-only) to functional components.
19
- *
20
- * Only transforms class components that:
21
- * - Have only a `render` method (no other instance methods)
22
- * - Have no state
23
- * - Have no lifecycle methods
24
- * - Have no refs
25
- *
26
- * Before:
27
- * ```tsx
28
- * class MyComponent extends React.Component {
29
- * render() {
30
- * return <div>{this.props.name}</div>;
31
- * }
32
- * }
33
- * ```
34
- *
35
- * After:
36
- * ```tsx
37
- * function MyComponent(props) {
38
- * return <div>{props.name}</div>;
39
- * }
40
- * ```
41
- *
42
- * A `PureComponent` becomes `memo(function X(props) {...})` so it still skips renders for shallowly equal
43
- * props, and `export` is kept. A `PureComponent` that is the `export default` of its file is left as a
44
- * class, since the memo form needs a second statement.
45
- *
46
18
  * @see https://github.com/reactjs/react-codemod#pure-component
47
19
  */
48
20
  export class ClassToFunctional extends Recipe {
49
21
  readonly name = "org.openrewrite.react.refactoring.class-to-functional";
50
22
  readonly displayName: string = "Convert class components to functional components";
51
- readonly description: string = "Converts simple render-only class components to functional components. A `PureComponent` becomes a `memo`-wrapped function so it keeps skipping renders for equal props, and `export` is preserved.";
23
+ readonly description: string = "Converts simple render-only class components to functional components. A `PureComponent` becomes a `memo`-wrapped function so it keeps skipping renders for equal props, and `export` is preserved. A `PureComponent` that is the `export default` of its file stays a class, since the `memo` form needs a second statement.";
52
24
 
53
25
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
54
26
  // Rewrite rules for replacing this.props references
@@ -130,10 +102,10 @@ export class ClassToFunctional extends Recipe {
130
102
  let memo = 'React.memo';
131
103
  if (pure === 'bare') {
132
104
  // Print the name the import resolves to, which differs when `memo` is already bound locally.
133
- const local = maybeAddImport(this, {module: 'react', member: 'memo', onlyIfReferenced: false});
105
+ const local = maybeBind(this, {module: 'react', member: 'memo', onlyIfReferenced: false});
134
106
  if (!local) return cd;
135
107
  memo = local;
136
- maybeRemoveImport(this, 'react', 'PureComponent');
108
+ maybeUnbind(this, {module: 'react', member: 'PureComponent'});
137
109
  }
138
110
  const wrapped = await template`const ${raw(className)} = ${raw(memo)}(function ${raw(className)}(${raw(propsParam)}) {});`.apply(cd, this.cursor) as J.VariableDeclarations | undefined;
139
111
  if (!wrapped || !wrapped.modifiers) return cd;
@@ -183,6 +155,10 @@ export class ClassToFunctional extends Recipe {
183
155
  }
184
156
 
185
157
  private extendsReactComponent(cd: J.ClassDeclaration): boolean {
158
+ return reactComponentSupertype(cd) ?? this.extendsReactComponentByName(cd);
159
+ }
160
+
161
+ private extendsReactComponentByName(cd: J.ClassDeclaration): boolean {
186
162
  if (!cd.extends) return false;
187
163
  const extendsType = unwrapBaseType(cd.extends.element)!;
188
164
 
@@ -23,26 +23,12 @@ const CREATE_CLASS_METHODS = new Set(['getDOMNode', 'isMounted', 'replaceProps',
23
23
  const SEMICOLON_KIND = "org.openrewrite.java.marker.Semicolon";
24
24
 
25
25
  /**
26
- * Converts `React.createClass()` to ES6 class syntax.
27
- *
28
- * Handles:
29
- * - `getInitialState()` → class property `state = {...}`
30
- * - `getDefaultProps()` → `static defaultProps = {...}`
31
- * - Static properties (propTypes, contextTypes) → class statics
32
- * - `displayName` → `static displayName`, unless it is the class's name
33
- * - Auto-binding of methods → arrow function class fields
34
- * - Lifecycle methods and render → regular class methods
35
- * - A `createReactClass()` component extends the `Component` of the `react` the file binds, or binds one, and the
36
- * `create-react-class` import goes where nothing else uses it
37
- * - Skips conversion if mixins are present, or a member it has no conversion for, such as
38
- * `render: function() {}` or `statics`
39
- *
40
26
  * @see https://github.com/reactjs/react-codemod#class
41
27
  */
42
28
  export class CreateClassToES6 extends Recipe {
43
29
  readonly name = "org.openrewrite.react.refactoring.create-class-to-es6";
44
30
  readonly displayName: string = "Convert `createClass` to ES6 class";
45
- readonly description: string = "Converts `React.createClass()` and `createReactClass()` calls to ES6 class syntax.";
31
+ readonly description: string = "Converts `React.createClass()` and `createReactClass()` calls to ES6 class syntax, with auto-bound methods as arrow function fields. A component with `mixins`, or with a member there is no conversion for, such as `render: function() {}` or `statics`, is left alone.";
46
32
 
47
33
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
48
34
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
@@ -1,30 +1,11 @@
1
1
  import {ExecutionContext, printer, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
2
  import {isObjectLiteral, JavaScriptVisitor, JS, raw, template, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
- import {J} from "@openrewrite/rewrite/java";
3
+ import {isIdentifier, J} from "@openrewrite/rewrite/java";
4
+ import {reactFunction, typedOrNamedCall} from "../util/react-matchers";
5
+
6
+ const CREATE_ELEMENT = typedOrNamedCall(reactFunction("createElement"), "React", "createElement");
4
7
 
5
8
  /**
6
- * Converts `React.createElement()` calls to JSX syntax.
7
- *
8
- * Handles:
9
- * - String tags: `createElement('div', ...)` → `<div ... />`
10
- * - Component tags: `createElement(MyComponent, ...)` → `<MyComponent ... />`
11
- * - Props objects: `{ className: 'foo' }` → `className="foo"`
12
- * - String children: `'Hello'` → text node
13
- * - Expression children: `{expr}` → `{expr}`
14
- * - Nested createElement calls are handled recursively
15
- *
16
- * Before:
17
- * ```tsx
18
- * React.createElement('div', { className: 'foo' }, 'Hello')
19
- * React.createElement(MyComponent, { name: 'World' })
20
- * ```
21
- *
22
- * After:
23
- * ```tsx
24
- * <div className="foo">Hello</div>
25
- * <MyComponent name="World" />
26
- * ```
27
- *
28
9
  * @see https://github.com/reactjs/react-codemod#create-element-to-jsx
29
10
  */
30
11
  export class CreateElementToJsx extends Recipe {
@@ -69,14 +50,9 @@ export class CreateElementToJsx extends Recipe {
69
50
  }
70
51
 
71
52
  private isCreateElementCall(method: J.MethodInvocation): boolean {
72
- if (method.name.simpleName !== 'createElement') return false;
73
-
74
- // React.createElement(...)
75
- if (method.select?.element?.kind === J.Kind.Identifier) {
76
- return (method.select.element as J.Identifier).simpleName === 'React';
77
- }
78
-
79
- return false;
53
+ // The classic JSX runtime compiles JSX to `React.createElement`, so `React` has to be in scope already
54
+ const select = method.select?.element;
55
+ return isIdentifier(select) && select.simpleName === 'React' && CREATE_ELEMENT(method);
80
56
  }
81
57
 
82
58
  private getTagName(expr: any): string | undefined {
@@ -13,34 +13,6 @@ import {Expression, J} from "@openrewrite/rewrite/java";
13
13
  const EFFECT_HOOKS = ['useEffect', 'useLayoutEffect'];
14
14
 
15
15
  /**
16
- * Wraps the body of an `async` effect callback in an immediately invoked async function.
17
- *
18
- * `useEffect` expects its callback to return nothing or a cleanup function. An `async` callback
19
- * returns a promise, which React warns about and never uses as a cleanup. The effect still runs
20
- * the same code in the same order; only the returned promise goes away.
21
- *
22
- * Before:
23
- * ```tsx
24
- * useEffect(async () => {
25
- * const data = await load();
26
- * setData(data);
27
- * }, []);
28
- * ```
29
- *
30
- * After:
31
- * ```tsx
32
- * useEffect(() => {
33
- * (async () => {
34
- * const data = await load();
35
- * setData(data);
36
- * })();
37
- * }, []);
38
- * ```
39
- *
40
- * Only `async` arrow functions passed directly to `useEffect` or `useLayoutEffect` (bare or as `React.useEffect`) are changed,
41
- * with a block or an expression body. A `return` inside the body now returns from the inner
42
- * function, as it effectively did before, since the outer promise was never a usable cleanup.
43
- *
44
16
  * @see https://react.dev/reference/react/useEffect#fetching-data-with-effects
45
17
  */
46
18
  export class FixAsyncEffect extends Recipe {
@@ -3,29 +3,6 @@ import {JavaScriptVisitor, isVendoredOrBundled} from "@openrewrite/rewrite/javas
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  /**
6
- * Converts manual `.bind(this)` in constructors to class field arrow functions.
7
- *
8
- * Before:
9
- * ```tsx
10
- * class MyComponent extends React.Component {
11
- * constructor(props) {
12
- * super(props);
13
- * this.handleClick = this.handleClick.bind(this);
14
- * }
15
- * handleClick() { ... }
16
- * }
17
- * ```
18
- *
19
- * After:
20
- * ```tsx
21
- * class MyComponent extends React.Component {
22
- * constructor(props) {
23
- * super(props);
24
- * }
25
- * handleClick = () => { ... };
26
- * }
27
- * ```
28
- *
29
6
  * @see https://github.com/reactjs/react-codemod#manual-bind-to-arrow-transform
30
7
  */
31
8
  export class ManualBindToArrow extends Recipe {