@openrewrite/recipes-react 0.25.0 → 0.27.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 (432) 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 +128 -63
  148. package/dist/react17/remove-event-persist.js.map +1 -1
  149. package/dist/react17/rename-unsafe-lifecycles.d.ts.map +1 -1
  150. package/dist/react17/rename-unsafe-lifecycles.js +1 -1
  151. package/dist/react17/rename-unsafe-lifecycles.js.map +1 -1
  152. package/dist/react17/update-react-imports.d.ts.map +1 -1
  153. package/dist/react17/update-react-imports.js +1 -1
  154. package/dist/react17/update-react-imports.js.map +1 -1
  155. package/dist/react17/use-new-jsx-transform.d.ts +1 -1
  156. package/dist/react17/use-new-jsx-transform.d.ts.map +1 -1
  157. package/dist/react17/use-new-jsx-transform.js +2 -1
  158. package/dist/react17/use-new-jsx-transform.js.map +1 -1
  159. package/dist/react18/add-children-to-props.js +1 -1
  160. package/dist/react18/add-children-to-props.js.map +1 -1
  161. package/dist/react18/replace-reactdom-render.d.ts.map +1 -1
  162. package/dist/react18/replace-reactdom-render.js +1 -1
  163. package/dist/react18/replace-reactdom-render.js.map +1 -1
  164. package/dist/react18/replace-render-callback.d.ts.map +1 -1
  165. package/dist/react18/replace-render-callback.js +3 -12
  166. package/dist/react18/replace-render-callback.js.map +1 -1
  167. package/dist/react18/replace-unmount-component-at-node.d.ts.map +1 -1
  168. package/dist/react18/replace-unmount-component-at-node.js +1 -1
  169. package/dist/react18/replace-unmount-component-at-node.js.map +1 -1
  170. package/dist/react19/find-context-consumer.d.ts.map +1 -1
  171. package/dist/react19/find-context-consumer.js.map +1 -1
  172. package/dist/react19/find-deprecated-reactdom-apis.d.ts.map +1 -1
  173. package/dist/react19/find-deprecated-reactdom-apis.js +16 -61
  174. package/dist/react19/find-deprecated-reactdom-apis.js.map +1 -1
  175. package/dist/react19/find-element-ref.d.ts.map +1 -1
  176. package/dist/react19/find-element-ref.js.map +1 -1
  177. package/dist/react19/find-legacy-context-api.d.ts.map +1 -1
  178. package/dist/react19/find-legacy-context-api.js.map +1 -1
  179. package/dist/react19/no-implicit-ref-callback-return.d.ts.map +1 -1
  180. package/dist/react19/no-implicit-ref-callback-return.js +1 -1
  181. package/dist/react19/no-implicit-ref-callback-return.js.map +1 -1
  182. package/dist/react19/remove-context-provider.d.ts.map +1 -1
  183. package/dist/react19/remove-context-provider.js +1 -7
  184. package/dist/react19/remove-context-provider.js.map +1 -1
  185. package/dist/react19/remove-forward-ref.d.ts.map +1 -1
  186. package/dist/react19/remove-forward-ref.js +2 -2
  187. package/dist/react19/remove-forward-ref.js.map +1 -1
  188. package/dist/react19/remove-prop-types.d.ts.map +1 -1
  189. package/dist/react19/remove-prop-types.js.map +1 -1
  190. package/dist/react19/remove-react-fc.js +2 -2
  191. package/dist/react19/remove-react-fc.js.map +1 -1
  192. package/dist/react19/remove-unstable-batched-updates.d.ts +1 -1
  193. package/dist/react19/remove-unstable-batched-updates.d.ts.map +1 -1
  194. package/dist/react19/remove-unstable-batched-updates.js +9 -88
  195. package/dist/react19/remove-unstable-batched-updates.js.map +1 -1
  196. package/dist/{react16 → react19}/replace-create-factory.d.ts +1 -1
  197. package/dist/react19/replace-create-factory.d.ts.map +1 -0
  198. package/dist/{react16 → react19}/replace-create-factory.js +5 -5
  199. package/dist/react19/replace-create-factory.js.map +1 -0
  200. package/dist/react19/replace-reactdom-hydrate.d.ts.map +1 -1
  201. package/dist/react19/replace-reactdom-hydrate.js +1 -1
  202. package/dist/react19/replace-reactdom-hydrate.js.map +1 -1
  203. package/dist/react19/replace-string-ref.d.ts.map +1 -1
  204. package/dist/react19/replace-string-ref.js.map +1 -1
  205. package/dist/react19/scoped-jsx-namespace.d.ts.map +1 -1
  206. package/dist/react19/scoped-jsx-namespace.js +2 -6
  207. package/dist/react19/scoped-jsx-namespace.js.map +1 -1
  208. package/dist/react19/use-context-hook.d.ts.map +1 -1
  209. package/dist/react19/use-context-hook.js +1 -1
  210. package/dist/react19/use-context-hook.js.map +1 -1
  211. package/dist/react19/use-ref-required-initial.d.ts.map +1 -1
  212. package/dist/react19/use-ref-required-initial.js +3 -1
  213. package/dist/react19/use-ref-required-initial.js.map +1 -1
  214. package/dist/refactoring/class-to-functional.d.ts.map +1 -1
  215. package/dist/refactoring/class-to-functional.js +7 -3
  216. package/dist/refactoring/class-to-functional.js.map +1 -1
  217. package/dist/refactoring/create-class-to-es6.d.ts.map +1 -1
  218. package/dist/refactoring/create-class-to-es6.js +1 -1
  219. package/dist/refactoring/create-class-to-es6.js.map +1 -1
  220. package/dist/refactoring/create-element-to-jsx.d.ts.map +1 -1
  221. package/dist/refactoring/create-element-to-jsx.js +5 -7
  222. package/dist/refactoring/create-element-to-jsx.js.map +1 -1
  223. package/dist/refactoring/fix-async-effect.d.ts.map +1 -1
  224. package/dist/refactoring/fix-async-effect.js.map +1 -1
  225. package/dist/refactoring/manual-bind-to-arrow.d.ts.map +1 -1
  226. package/dist/refactoring/manual-bind-to-arrow.js.map +1 -1
  227. package/dist/refactoring/prop-types-to-typescript.d.ts +1 -1
  228. package/dist/refactoring/prop-types-to-typescript.d.ts.map +1 -1
  229. package/dist/refactoring/prop-types-to-typescript.js +2 -2
  230. package/dist/refactoring/prop-types-to-typescript.js.map +1 -1
  231. package/dist/refactoring/pure-render-mixin.d.ts.map +1 -1
  232. package/dist/refactoring/pure-render-mixin.js +2 -8
  233. package/dist/refactoring/pure-render-mixin.js.map +1 -1
  234. package/dist/refactoring/sort-comp.d.ts.map +1 -1
  235. package/dist/refactoring/sort-comp.js +1 -1
  236. package/dist/refactoring/sort-comp.js.map +1 -1
  237. package/dist/search/find-deprecated-lifecycles.d.ts +1 -1
  238. package/dist/search/find-deprecated-lifecycles.d.ts.map +1 -1
  239. package/dist/search/find-deprecated-lifecycles.js +2 -2
  240. package/dist/search/find-deprecated-lifecycles.js.map +1 -1
  241. package/dist/search/find-effects-without-cleanup.d.ts +1 -1
  242. package/dist/search/find-effects-without-cleanup.d.ts.map +1 -1
  243. package/dist/search/find-effects-without-cleanup.js +7 -9
  244. package/dist/search/find-effects-without-cleanup.js.map +1 -1
  245. package/dist/search/find-enzyme-usage.d.ts.map +1 -1
  246. package/dist/search/find-enzyme-usage.js.map +1 -1
  247. package/dist/search/find-function-component-default-props.d.ts +1 -1
  248. package/dist/search/find-function-component-default-props.d.ts.map +1 -1
  249. package/dist/search/find-function-component-default-props.js +2 -2
  250. package/dist/search/find-function-component-default-props.js.map +1 -1
  251. package/dist/search/find-hard-coded-strings.d.ts.map +1 -1
  252. package/dist/search/find-hard-coded-strings.js.map +1 -1
  253. package/dist/search/find-hook-usage.d.ts.map +1 -1
  254. package/dist/search/find-hook-usage.js.map +1 -1
  255. package/dist/search/find-legacy-react-apis.d.ts +1 -1
  256. package/dist/search/find-legacy-react-apis.d.ts.map +1 -1
  257. package/dist/search/find-legacy-react-apis.js +1 -1
  258. package/dist/search/find-legacy-react-apis.js.map +1 -1
  259. package/dist/search/find-missing-use-client-directive.d.ts.map +1 -1
  260. package/dist/search/find-missing-use-client-directive.js +11 -10
  261. package/dist/search/find-missing-use-client-directive.js.map +1 -1
  262. package/dist/search/find-prop-usage.d.ts.map +1 -1
  263. package/dist/search/find-prop-usage.js.map +1 -1
  264. package/dist/search/find-react-component.d.ts.map +1 -1
  265. package/dist/search/find-react-component.js.map +1 -1
  266. package/dist/search/find-reactdom-root-apis.d.ts.map +1 -1
  267. package/dist/search/find-reactdom-root-apis.js +2 -42
  268. package/dist/search/find-reactdom-root-apis.js.map +1 -1
  269. package/dist/search/find-redux-stores.d.ts +1 -1
  270. package/dist/search/find-redux-stores.d.ts.map +1 -1
  271. package/dist/search/find-redux-stores.js +1 -1
  272. package/dist/search/find-redux-stores.js.map +1 -1
  273. package/dist/search/find-server-rendering-usage.d.ts.map +1 -1
  274. package/dist/search/find-server-rendering-usage.js +13 -54
  275. package/dist/search/find-server-rendering-usage.js.map +1 -1
  276. package/dist/simplify-object-pattern-property.d.ts.map +1 -1
  277. package/dist/simplify-object-pattern-property.js.map +1 -1
  278. package/dist/simplify-react-imports.d.ts.map +1 -1
  279. package/dist/simplify-react-imports.js +1 -1
  280. package/dist/simplify-react-imports.js.map +1 -1
  281. package/dist/testing/enzyme-host-components.d.ts.map +1 -1
  282. package/dist/testing/enzyme-host-components.js +2 -2
  283. package/dist/testing/enzyme-host-components.js.map +1 -1
  284. package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
  285. package/dist/testing/enzyme-to-react-testing-library.js +11 -19
  286. package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
  287. package/dist/testing/enzyme-usage.js +2 -2
  288. package/dist/testing/enzyme-usage.js.map +1 -1
  289. package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
  290. package/dist/testing/enzyme-wrapper-scope.js +5 -12
  291. package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
  292. package/dist/util/react-class.d.ts +2 -0
  293. package/dist/util/react-class.d.ts.map +1 -1
  294. package/dist/util/react-class.js +14 -0
  295. package/dist/util/react-class.js.map +1 -1
  296. package/dist/util/react-matchers.d.ts +8 -0
  297. package/dist/util/react-matchers.d.ts.map +1 -0
  298. package/dist/util/react-matchers.js +25 -0
  299. package/dist/util/react-matchers.js.map +1 -0
  300. package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
  301. package/dist/zustand/redux-to-zustand.js +20 -20
  302. package/dist/zustand/redux-to-zustand.js.map +1 -1
  303. package/package.json +2 -2
  304. package/src/i18n/translate-hard-coded-strings.ts +5 -12
  305. package/src/index.ts +3 -12
  306. package/src/migration/change-component-prop-value.ts +0 -40
  307. package/src/migration/cra-to-vite/add-vite-config.ts +0 -10
  308. package/src/migration/cra-to-vite/cra-to-vite.ts +0 -3
  309. package/src/migration/cra-to-vite/find-cra-config-blockers.ts +2 -7
  310. package/src/migration/cra-to-vite/find-cra-env-file-blockers.ts +0 -7
  311. package/src/migration/cra-to-vite/find-cra-source-blockers.ts +0 -9
  312. package/src/migration/cra-to-vite/find-cra-to-vite-blockers.ts +0 -4
  313. package/src/migration/cra-to-vite/migrate-cra-package.ts +0 -1
  314. package/src/migration/cra-to-vite/migrate-cra-svg-imports.ts +3 -4
  315. package/src/migration/cra-to-vite/migrate-cra-tests-to-vitest.ts +1 -3
  316. package/src/migration/cra-to-vite/move-public-index-html.ts +1 -13
  317. package/src/migration/cra-to-vite/remove-cra-configuration.ts +0 -1
  318. package/src/migration/cra-to-vite/rename-jsx-files.ts +0 -4
  319. package/src/migration/cra-to-vite/rename-process-env-react-app.ts +1 -17
  320. package/src/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.ts +1 -11
  321. package/src/migration/cra-to-vite/replace-react-scripts-dependency.ts +1 -12
  322. package/src/migration/cra-to-vite/update-react-app-env-types.ts +0 -9
  323. package/src/migration/cra-to-vite/update-react-scripts-scripts.ts +0 -15
  324. package/src/migration/cra-to-vite/update-tsconfig-for-vite.ts +0 -11
  325. package/src/mui/adapt-v4-theme.ts +2 -7
  326. package/src/mui/add-component-prop.ts +0 -7
  327. package/src/mui/add-emotion-prepend.ts +5 -17
  328. package/src/mui/convert-mui-imports.ts +1 -12
  329. package/src/mui/convert-prop-to-sx.ts +1 -9
  330. package/src/mui/mark-manual-migration.ts +0 -6
  331. package/src/mui/mark-palette-mode-usage.ts +0 -6
  332. package/src/mui/move-component-prop-to-slot.ts +0 -9
  333. package/src/mui/move-primary-text-to-children.ts +0 -5
  334. package/src/mui/move-system-props-to-sx.ts +1 -11
  335. package/src/mui/remove-component-prop.ts +0 -5
  336. package/src/mui/remove-root-ref.ts +2 -8
  337. package/src/mui/remove-spacing-px-suffix.ts +3 -11
  338. package/src/mui/rename-component-prop.ts +0 -7
  339. package/src/mui/rename-joy-css-variables.ts +0 -6
  340. package/src/mui/rename-theme-palette-type.ts +0 -5
  341. package/src/mui/replace-box-border-radius.ts +0 -5
  342. package/src/mui/replace-breakpoints-width.ts +0 -2
  343. package/src/mui/replace-component-class.ts +0 -10
  344. package/src/mui/replace-components-with-slots.ts +0 -8
  345. package/src/mui/replace-import-paths.ts +0 -11
  346. package/src/mui/replace-in-string-literals.ts +0 -7
  347. package/src/mui/replace-list-item-button-prop.ts +3 -10
  348. package/src/mui/replace-tabs-scroll-buttons.ts +0 -5
  349. package/src/mui/replace-theme-color-functions.ts +9 -26
  350. package/src/mui/replace-theme-spacing-unit.ts +0 -6
  351. package/src/mui/replace-typography-round.ts +0 -5
  352. package/src/mui/shift-hidden-down-props.ts +3 -12
  353. package/src/mui/update-theme-breakpoints.ts +0 -8
  354. package/src/mui/upgrade-grid-props.ts +1 -9
  355. package/src/react-native/view-prop-types.ts +4 -26
  356. package/src/react16/error-boundaries.ts +1 -20
  357. package/src/react16/find-dom-node.ts +0 -17
  358. package/src/react16/react-dom-factories.ts +0 -14
  359. package/src/react16/react-prop-types.ts +4 -29
  360. package/src/react16/react-to-react-dom.ts +3 -20
  361. package/src/react17/migrate-deprecated-lifecycles.ts +6 -21
  362. package/src/react17/remove-event-persist.ts +157 -92
  363. package/src/react17/rename-unsafe-lifecycles.ts +1 -24
  364. package/src/react17/update-react-imports.ts +2 -27
  365. package/src/react17/use-new-jsx-transform.ts +2 -15
  366. package/src/react18/add-children-to-props.ts +2 -2
  367. package/src/react18/replace-reactdom-render.ts +2 -24
  368. package/src/react18/replace-render-callback.ts +5 -31
  369. package/src/react18/replace-unmount-component-at-node.ts +2 -22
  370. package/src/react19/find-context-consumer.ts +0 -23
  371. package/src/react19/find-deprecated-reactdom-apis.ts +20 -80
  372. package/src/react19/find-element-ref.ts +0 -15
  373. package/src/react19/find-legacy-context-api.ts +0 -12
  374. package/src/react19/no-implicit-ref-callback-return.ts +1 -19
  375. package/src/react19/remove-context-provider.ts +1 -25
  376. package/src/react19/remove-forward-ref.ts +3 -18
  377. package/src/react19/remove-prop-types.ts +0 -24
  378. package/src/react19/remove-react-fc.ts +3 -3
  379. package/src/react19/remove-unstable-batched-updates.ts +15 -129
  380. package/src/{react16 → react19}/replace-create-factory.ts +8 -21
  381. package/src/react19/replace-reactdom-hydrate.ts +2 -19
  382. package/src/react19/replace-string-ref.ts +0 -14
  383. package/src/react19/scoped-jsx-namespace.ts +3 -7
  384. package/src/react19/use-context-hook.ts +2 -20
  385. package/src/react19/use-ref-required-initial.ts +4 -17
  386. package/src/refactoring/class-to-functional.ts +9 -33
  387. package/src/refactoring/create-class-to-es6.ts +1 -15
  388. package/src/refactoring/create-element-to-jsx.ts +7 -31
  389. package/src/refactoring/fix-async-effect.ts +0 -28
  390. package/src/refactoring/manual-bind-to-arrow.ts +0 -23
  391. package/src/refactoring/prop-types-to-typescript.ts +3 -34
  392. package/src/refactoring/pure-render-mixin.ts +3 -30
  393. package/src/refactoring/sort-comp.ts +1 -11
  394. package/src/search/find-deprecated-lifecycles.ts +3 -6
  395. package/src/search/find-effects-without-cleanup.ts +5 -15
  396. package/src/search/find-enzyme-usage.ts +0 -3
  397. package/src/search/find-function-component-default-props.ts +3 -7
  398. package/src/search/find-hard-coded-strings.ts +0 -9
  399. package/src/search/find-hook-usage.ts +0 -10
  400. package/src/search/find-legacy-react-apis.ts +1 -18
  401. package/src/search/find-missing-use-client-directive.ts +13 -19
  402. package/src/search/find-prop-usage.ts +0 -11
  403. package/src/search/find-react-component.ts +0 -11
  404. package/src/search/find-reactdom-root-apis.ts +5 -44
  405. package/src/search/find-redux-stores.ts +1 -9
  406. package/src/search/find-server-rendering-usage.ts +15 -72
  407. package/src/simplify-object-pattern-property.ts +0 -8
  408. package/src/simplify-react-imports.ts +3 -23
  409. package/src/testing/enzyme-host-components.ts +3 -2
  410. package/src/testing/enzyme-to-react-testing-library.ts +10 -50
  411. package/src/testing/enzyme-usage.ts +2 -2
  412. package/src/testing/enzyme-wrapper-scope.ts +7 -15
  413. package/src/util/react-class.ts +17 -1
  414. package/src/util/react-matchers.ts +34 -0
  415. package/src/zustand/redux-to-zustand.ts +21 -75
  416. package/dist/react16/replace-create-factory.d.ts.map +0 -1
  417. package/dist/react16/replace-create-factory.js.map +0 -1
  418. package/dist/react19/replace-act-import.d.ts +0 -9
  419. package/dist/react19/replace-act-import.d.ts.map +0 -1
  420. package/dist/react19/replace-act-import.js +0 -34
  421. package/dist/react19/replace-act-import.js.map +0 -1
  422. package/dist/react19/replace-react-shallow-renderer.d.ts +0 -8
  423. package/dist/react19/replace-react-shallow-renderer.d.ts.map +0 -1
  424. package/dist/react19/replace-react-shallow-renderer.js +0 -49
  425. package/dist/react19/replace-react-shallow-renderer.js.map +0 -1
  426. package/dist/react19/replace-use-form-state.d.ts +0 -8
  427. package/dist/react19/replace-use-form-state.d.ts.map +0 -1
  428. package/dist/react19/replace-use-form-state.js +0 -57
  429. package/dist/react19/replace-use-form-state.js.map +0 -1
  430. package/src/react19/replace-act-import.ts +0 -36
  431. package/src/react19/replace-react-shallow-renderer.ts +0 -47
  432. package/src/react19/replace-use-form-state.ts +0 -69
@@ -4,11 +4,6 @@ import {literalEditor} from "./replace-in-string-literals";
4
4
  const capitalize = (s: string): string => s ? s[0].toUpperCase() + s.slice(1) : s;
5
5
 
6
6
  /**
7
- * Points the `material-ui/svg-icons/<set>/<icon-name>` imports of v0.x at `@material-ui/icons/<IconName>`.
8
- *
9
- * Before: `import AccessAlarm from 'material-ui/svg-icons/device/access-alarm';`
10
- * After: `import AccessAlarm from '@material-ui/icons/AccessAlarm';`
11
- *
12
7
  * @see https://github.com/mui/material-ui/tree/master/packages/mui-codemod/src/v1.0.0/svg-icon-imports
13
8
  */
14
9
  export class ReplaceSvgIconImports extends Recipe {
@@ -80,12 +75,6 @@ const PATH_CONVERSION: Record<string, string> = {
80
75
  };
81
76
 
82
77
  /**
83
- * Moves the `material-ui/lib/*` and `material-ui/src/*` imports of v0.15 to the module paths of v0.15's later
84
- * layout, such as `material-ui/lib/app-bar` to `material-ui/AppBar`.
85
- *
86
- * Before: `import AppBar from 'material-ui/lib/app-bar';`
87
- * After: `import AppBar from 'material-ui/AppBar';`
88
- *
89
78
  * @see https://github.com/mui/material-ui/tree/master/packages/mui-codemod/src/v0.15.0/import-path
90
79
  */
91
80
  export class ReplaceMaterialUiImportPaths extends Recipe {
@@ -14,13 +14,6 @@ export async function literalEditor(change: (text: string) => string): Promise<T
14
14
  }());
15
15
  }
16
16
 
17
- /**
18
- * Replaces text in the string literals of a file with a regular expression, for names that live in strings, such as
19
- * style selectors.
20
- *
21
- * Before: `'& .JoyButton-root'`
22
- * After: `'& .MuiButton-root'`
23
- */
24
17
  export class ReplaceInStringLiterals extends Recipe {
25
18
  readonly name = "org.openrewrite.react.mui.replace-in-string-literals";
26
19
  readonly displayName: string = "Replace text in string literals";
@@ -1,5 +1,5 @@
1
1
  import {ExecutionContext, Option, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, JSX, isVendoredOrBundled, maybeAddImport, maybeRemoveImport} from "@openrewrite/rewrite/javascript";
2
+ import {JavaScriptVisitor, JS, JSX, isVendoredOrBundled, maybeBind, maybeUnbind} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
  import {importBindings} from "../util/module-imports";
5
5
  import {findAttribute, renameTag, replaceAttribute} from "./jsx-attributes";
@@ -7,13 +7,6 @@ import {muiComponents, tagComponent} from "./mui-components";
7
7
  import {packagePattern} from "./mui-tag-visitor";
8
8
 
9
9
  /**
10
- * Replaces `<ListItem button>` with `<ListItemButton>`, since v6 removes the `button` prop of `ListItem`.
11
- *
12
- * Before: `<ListItem button onClick={go}>x</ListItem>`
13
- * After: `<ListItemButton onClick={go}>x</ListItemButton>`
14
- *
15
- * The import of `ListItemButton` is added next to the one of `ListItem`, which goes when nothing else uses it.
16
- *
17
10
  * @see https://mui.com/material-ui/migration/upgrade-to-v6/#listitem
18
11
  */
19
12
  export class ReplaceListItemButtonProp extends Recipe {
@@ -50,8 +43,8 @@ export class ReplaceListItemButtonProp extends Recipe {
50
43
  const isOn = button && (!value || (value.kind === JS.Kind.JsxEmbeddedExpression
51
44
  && ((value as JSX.EmbeddedExpression).expression.element as J.Literal).value === true));
52
45
  if (!button || !isOn) return visited;
53
- const local = maybeAddImport(this, {module: this.module, member: "ListItemButton"}) ?? "ListItemButton";
54
- maybeRemoveImport(this, this.module, "ListItem");
46
+ const local = maybeBind(this, {module: this.module, member: "ListItemButton"}) ?? "ListItemButton";
47
+ maybeUnbind(this, {module: this.module, member: "ListItem"});
55
48
  return renameTag(replaceAttribute(visited, button, undefined), local);
56
49
  }
57
50
  }());
@@ -5,11 +5,6 @@ import {attributeString} from "./mui-components";
5
5
  import {muiTagEditor} from "./mui-tag-visitor";
6
6
 
7
7
  /**
8
- * Replaces the string values of the `scrollButtons` prop of `Tabs` with the booleans of v5.
9
- *
10
- * Before: `<Tabs scrollButtons="on" />`, `<Tabs scrollButtons="desktop" />`, `<Tabs scrollButtons="off" />`
11
- * After: `<Tabs scrollButtons allowScrollButtonsMobile />`, `<Tabs scrollButtons />`, `<Tabs scrollButtons={false} />`
12
- *
13
8
  * @see https://mui.com/material-ui/migration/v5-component-changes/#tabs
14
9
  */
15
10
  export class ReplaceTabsScrollButtons extends Recipe {
@@ -1,10 +1,9 @@
1
1
  import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, isVendoredOrBundled, maybeRemoveImport, raw, template} from "@openrewrite/rewrite/javascript";
3
- import {isIdentifier, J} from "@openrewrite/rewrite/java";
4
- import {importBindings} from "../util/module-imports";
2
+ import {JavaScriptVisitor, isVendoredOrBundled, maybeUnbind, MethodMatcher, raw, template} from "@openrewrite/rewrite/javascript";
3
+ import {isIdentifier, J, Type} from "@openrewrite/rewrite/java";
5
4
 
6
- const FUNCTIONS = new Set(["alpha", "lighten", "darken"]);
7
- const MODULES = /^@mui\/(system|material|system\/colorManipulator|material\/styles)$/;
5
+ const COLOR_FUNCTIONS = ["@mui/system", "@mui/material", "@mui/system/colorManipulator", "@mui/material/styles"]
6
+ .flatMap(module => ["alpha", "lighten", "darken"].map(fn => new MethodMatcher(`${module} ${fn}(..)`)));
8
7
 
9
8
  const rootOf = (e: J): string | undefined => {
10
9
  let current: J = e;
@@ -13,15 +12,6 @@ const rootOf = (e: J): string | undefined => {
13
12
  };
14
13
 
15
14
  /**
16
- * Replaces the color functions `alpha()`, `lighten()` and `darken()` with the ones on the theme, which understand
17
- * CSS variables.
18
- *
19
- * Before: `alpha(theme.palette.primary.main, 0.8)`
20
- * After: `theme.alpha(theme.palette.primary.main, 0.8)`
21
- *
22
- * Only a call whose color is read from a variable called `theme` is rewritten, since the call has to be made on
23
- * a theme that is in scope. The import goes when nothing else uses the function.
24
- *
25
15
  * @see https://mui.com/material-ui/migration/upgrade-to-native-color/
26
16
  */
27
17
  export class ReplaceThemeColorFunctions extends Recipe {
@@ -31,23 +21,16 @@ export class ReplaceThemeColorFunctions extends Recipe {
31
21
 
32
22
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
33
23
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
34
- private functions = new Map<string, {name: string; module: string}>();
35
-
36
- override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
37
- this.functions = new Map(importBindings(cu).filter(b => MODULES.test(b.module) && FUNCTIONS.has(b.name)).map(b => [b.local, {name: b.name, module: b.module}]));
38
- return this.functions.size ? super.visitJsCompilationUnit(cu, ctx) : cu;
39
- }
40
-
41
24
  override async visitMethodInvocation(invocation: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
42
25
  const visited = await super.visitMethodInvocation(invocation, ctx) as J.MethodInvocation;
43
- const fn = this.functions.get(visited.name.simpleName);
44
26
  const [color, ...rest] = visited.arguments.elements;
45
- if (visited.select || !fn || !color || rootOf(color.element) !== "theme") return visited;
27
+ const type = visited.methodType;
28
+ if (visited.select || !type || !COLOR_FUNCTIONS.some(fn => fn.matches(type)) || !color || rootOf(color.element) !== "theme") return visited;
46
29
  const replaced = rest.length
47
- ? await template`theme.${raw(fn.name)}(${color.element}, ${rest[0].element})`.apply(visited, this.cursor)
48
- : await template`theme.${raw(fn.name)}(${color.element})`.apply(visited, this.cursor);
30
+ ? await template`theme.${raw(type.name)}(${color.element}, ${rest[0].element})`.apply(visited, this.cursor)
31
+ : await template`theme.${raw(type.name)}(${color.element})`.apply(visited, this.cursor);
49
32
  if (!replaced) return visited;
50
- maybeRemoveImport(this, fn.module, fn.name);
33
+ maybeUnbind(this, {module: Type.FullyQualified.getFullyQualifiedName(type.declaringType), member: type.name});
51
34
  return {...replaced, prefix: visited.prefix} as J;
52
35
  }
53
36
  }());
@@ -17,12 +17,6 @@ async function spacingCall(unit: J.FieldAccess, argument: string, anchor: J, cur
17
17
  }
18
18
 
19
19
  /**
20
- * Replaces `theme.spacing.unit`, which v4 removed, with the `theme.spacing()` function, folding a multiplication or
21
- * division by a number into its argument.
22
- *
23
- * Before: `theme.spacing.unit`, `theme.spacing.unit * 5`, `theme.spacing.unit / 5`
24
- * After: `theme.spacing(1)`, `theme.spacing(5)`, `theme.spacing(0.2)`
25
- *
26
20
  * @see https://mui.com/material-ui/migration/migration-v3/#theme
27
21
  */
28
22
  export class ReplaceThemeSpacingUnit extends Recipe {
@@ -4,11 +4,6 @@ import {J} from "@openrewrite/rewrite/java";
4
4
  import {endsWithName} from "./theme-access";
5
5
 
6
6
  /**
7
- * Replaces `theme.typography.round(x)`, which v5 removed, with its definition.
8
- *
9
- * Before: `theme.typography.round(16 / 14)`
10
- * After: `Math.round(16 / 14 * 1e5) / 1e5`
11
- *
12
7
  * @see https://mui.com/material-ui/migration/v5-component-changes/#theme
13
8
  */
14
9
  export class ReplaceTypographyRound extends Recipe {
@@ -1,4 +1,4 @@
1
- import {ExecutionContext, TreeVisitor} from "@openrewrite/rewrite";
1
+ import {ExecutionContext, mapAsync, TreeVisitor} from "@openrewrite/rewrite";
2
2
  import {PreV5Recipe} from "./pre-v5-recipe";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
  import {attributeName} from "./mui-components";
@@ -7,13 +7,6 @@ import {muiTagEditor} from "./mui-tag-visitor";
7
7
  const SHIFT: Record<string, string> = {xsDown: "smDown", smDown: "mdDown", mdDown: "lgDown", lgDown: "xlDown"};
8
8
 
9
9
  /**
10
- * Shifts the `...Down` props of `Hidden` one breakpoint up, since v5 reads them as "below" where v4 read "up to".
11
- *
12
- * Before: `<Hidden xsDown />`, `<Hidden lgDown />`
13
- * After: `<Hidden smDown />`, `<Hidden xlDown />`
14
- *
15
- * Every prop of a tag is shifted once, in one step, so that `smDown` that was `xsDown` is not shifted again.
16
- *
17
10
  * @see https://mui.com/material-ui/migration/v5-component-changes/#hidden
18
11
  */
19
12
  export class ShiftHiddenDownProps extends PreV5Recipe {
@@ -28,15 +21,13 @@ export class ShiftHiddenDownProps extends PreV5Recipe {
28
21
  const shifted = this.shifted;
29
22
  return muiTagEditor("Hidden", undefined, async tag => {
30
23
  if (shifted.has(tag.id)) return tag;
31
- let changed = false;
32
- const attributes = tag.attributes.map(a => {
24
+ const attributes = await mapAsync(tag.attributes, async a => {
33
25
  const name = attributeName(a.element);
34
26
  if (!name || !(name in SHIFT) || a.element.kind !== "org.openrewrite.javascript.tree.JSX$Attribute") return a;
35
- changed = true;
36
27
  const attribute = a.element as any;
37
28
  return {...a, element: {...attribute, key: {...(attribute.key as J.Identifier), simpleName: SHIFT[name]}}};
38
29
  });
39
- if (!changed) return tag;
30
+ if (attributes === tag.attributes) return tag;
40
31
  shifted.add(tag.id);
41
32
  return {...tag, attributes} as typeof tag;
42
33
  });
@@ -7,14 +7,6 @@ import {endsWithName, stringValue, withString} from "./theme-access";
7
7
  const NEXT = new Map([["xs", "sm"], ["sm", "md"], ["md", "lg"], ["lg", "xl"], ["xl", "xl"]]);
8
8
 
9
9
  /**
10
- * Moves the breakpoint values of `theme.breakpoints.down()` and the end of `between()` up one step, since v5 reads
11
- * them as exclusive.
12
- *
13
- * Before: `theme.breakpoints.down('sm')`, `theme.breakpoints.between('sm', 'md')`
14
- * After: `theme.breakpoints.down('md')`, `theme.breakpoints.between('sm', 'lg')`
15
- *
16
- * It is not idempotent: run it once.
17
- *
18
10
  * @see https://mui.com/material-ui/migration/v5-component-changes/#theme
19
11
  */
20
12
  export class UpdateThemeBreakpoints extends PreV5Recipe {
@@ -10,20 +10,12 @@ import {muiTagEditor} from "./mui-tag-visitor";
10
10
  const DEFAULT_BREAKPOINTS = ["xs", "sm", "md", "lg", "xl"];
11
11
 
12
12
  /**
13
- * Moves the breakpoint props of the responsive `Grid` into its `size` and `offset` props, and drops `item` and
14
- * `zeroMinWidth`.
15
- *
16
- * Before: `<Grid item xs={12} sm={6} xsOffset={2} />`
17
- * After: `<Grid size={{ xs: 12, sm: 6 }} offset={2} />`
18
- *
19
- * A prop without a value, such as a bare `xs`, becomes `"grow"`. A tag with a spread attribute is left alone.
20
- *
21
13
  * @see https://mui.com/material-ui/migration/upgrade-to-grid-v2/
22
14
  */
23
15
  export class UpgradeGridProps extends Recipe {
24
16
  readonly name = "org.openrewrite.react.mui.upgrade-grid-props";
25
17
  readonly displayName: string = "Upgrade the props of Grid to `size` and `offset`";
26
- readonly description: string = "Moves the breakpoint props of the responsive Grid, `xs={12}` and `xsOffset={2}`, into its `size` and `offset` props, and removes `item` and `zeroMinWidth`. Tags with a spread attribute are left alone.";
18
+ readonly description: string = "Moves the breakpoint props of the responsive Grid, `xs={12}` and `xsOffset={2}`, into its `size` and `offset` props, and removes `item` and `zeroMinWidth`. A breakpoint prop without a value, such as a bare `xs`, becomes `\"grow\"`. Tags with a spread attribute are left alone.";
27
19
 
28
20
  @Option({displayName: "Component name", description: "The Grid component, `Grid` or `Grid2`.", example: "Grid"})
29
21
  componentName!: string;
@@ -1,25 +1,8 @@
1
1
  import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, maybeAddImport, maybeRemoveImport, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
2
+ import {JavaScriptVisitor, maybeBind, maybeUnbind, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  /**
6
- * Replaces `View.propTypes` with `ViewPropTypes` from the `deprecated-react-native-prop-types` package.
7
- *
8
- * React Native removed `View.propTypes` in newer versions. This recipe
9
- * replaces references to `View.propTypes` with the `ViewPropTypes` export.
10
- *
11
- * Before:
12
- * ```tsx
13
- * import { View } from 'react-native';
14
- * const styles = View.propTypes;
15
- * ```
16
- *
17
- * After:
18
- * ```tsx
19
- * import { ViewPropTypes } from 'deprecated-react-native-prop-types';
20
- * const styles = ViewPropTypes;
21
- * ```
22
- *
23
6
  * @see https://github.com/reactjs/react-codemod#reactnative-view-proptypes
24
7
  */
25
8
  export class ViewPropTypes extends Recipe {
@@ -29,14 +12,11 @@ export class ViewPropTypes extends Recipe {
29
12
 
30
13
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
31
14
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
32
- private transformed = false;
33
-
34
15
  override async visitJsCompilationUnit(cu: any, ctx: ExecutionContext): Promise<J | undefined> {
35
- this.transformed = false;
36
16
  let result = await super.visitJsCompilationUnit(cu, ctx);
37
- if (this.transformed) {
38
- maybeAddImport(this, {module: "deprecated-react-native-prop-types", member: "ViewPropTypes", onlyIfReferenced: false});
39
- maybeRemoveImport(this, "react-native", "View");
17
+ if (result !== cu) {
18
+ maybeBind(this, {module: "deprecated-react-native-prop-types", member: "ViewPropTypes", onlyIfReferenced: false});
19
+ maybeUnbind(this, {module: "react-native", member: "View"});
40
20
  }
41
21
  return result;
42
22
  }
@@ -49,8 +29,6 @@ export class ViewPropTypes extends Recipe {
49
29
  if ((fa.target as J.Identifier).simpleName !== 'View') return fa;
50
30
  if (fa.name.element.simpleName !== 'propTypes') return fa;
51
31
 
52
- this.transformed = true;
53
-
54
32
  // Replace View.propTypes with just ViewPropTypes
55
33
  return {
56
34
  ...fa.target,
@@ -3,31 +3,12 @@ import {JavaScriptVisitor, isVendoredOrBundled} from "@openrewrite/rewrite/javas
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  /**
6
- * Renames `unstable_handleError` to `componentDidCatch`.
7
- *
8
- * React 16 introduced error boundaries with a stable API. This recipe
9
- * renames the unstable API to the official one.
10
- *
11
- * Before:
12
- * ```tsx
13
- * class ErrorBoundary extends React.Component {
14
- * unstable_handleError(error) { ... }
15
- * }
16
- * ```
17
- *
18
- * After:
19
- * ```tsx
20
- * class ErrorBoundary extends React.Component {
21
- * componentDidCatch(error) { ... }
22
- * }
23
- * ```
24
- *
25
6
  * @see https://legacy.reactjs.org/blog/2017/09/26/react-v16.0.html#breaking-changes
26
7
  */
27
8
  export class ErrorBoundaries extends Recipe {
28
9
  readonly name = "org.openrewrite.react.16.error-boundaries";
29
10
  readonly displayName: string = "Rename `unstable_handleError` to `componentDidCatch`";
30
- readonly description: string = "Renames the unstable error boundary method to the official `componentDidCatch` API introduced in React 16.";
11
+ readonly description: string = "Renames the unstable error boundary method `unstable_handleError` to `componentDidCatch`, the API React 16 made official.";
31
12
 
32
13
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
33
14
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
@@ -10,23 +10,6 @@ import {
10
10
  import {Expression, J} from "@openrewrite/rewrite/java";
11
11
 
12
12
  /**
13
- * Replaces `this.getDOMNode()` with `React.findDOMNode(this)`.
14
- *
15
- * In React 0.13+, `getDOMNode()` on component instances was deprecated
16
- * in favor of `React.findDOMNode()`.
17
- *
18
- * Before:
19
- * ```tsx
20
- * this.getDOMNode()
21
- * this.refs.myRef.getDOMNode()
22
- * ```
23
- *
24
- * After:
25
- * ```tsx
26
- * React.findDOMNode(this)
27
- * React.findDOMNode(this.refs.myRef)
28
- * ```
29
- *
30
13
  * @see https://legacy.reactjs.org/blog/2015/10/07/react-v0.14.html#dom-node-refs
31
14
  */
32
15
  export class FindDomNode extends Recipe {
@@ -10,20 +10,6 @@ import {
10
10
  import {emptySpace, J, rightPadded, singleSpace, Type} from "@openrewrite/rewrite/java";
11
11
 
12
12
  /**
13
- * Converts `React.DOM.xxx()` factory calls to `React.createElement('xxx', ...)`.
14
- *
15
- * React.DOM factories were deprecated in React 15.6 and removed in React 16.
16
- *
17
- * Before:
18
- * ```tsx
19
- * React.DOM.div({ className: 'foo' }, 'Hello')
20
- * ```
21
- *
22
- * After:
23
- * ```tsx
24
- * React.createElement('div', { className: 'foo' }, 'Hello')
25
- * ```
26
- *
27
13
  * @see https://legacy.reactjs.org/blog/2017/09/26/react-v16.0.html#packaging
28
14
  */
29
15
  export class ReactDomFactories extends Recipe {
@@ -1,29 +1,8 @@
1
1
  import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, maybeAddImport, maybeRemoveImport, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
2
+ import {JavaScriptVisitor, maybeBind, maybeUnbind, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  /**
6
- * Moves `React.PropTypes` to the separate `prop-types` package.
7
- *
8
- * Starting with React 15.5, PropTypes was extracted into its own package.
9
- *
10
- * Before:
11
- * ```tsx
12
- * import React from 'react';
13
- * MyComponent.propTypes = {
14
- * name: React.PropTypes.string
15
- * };
16
- * ```
17
- *
18
- * After:
19
- * ```tsx
20
- * import React from 'react';
21
- * import PropTypes from 'prop-types';
22
- * MyComponent.propTypes = {
23
- * name: PropTypes.string
24
- * };
25
- * ```
26
- *
27
6
  * @see https://legacy.reactjs.org/blog/2017/09/26/react-v16.0.html#packaging
28
7
  */
29
8
  export class ReactPropTypes extends Recipe {
@@ -33,8 +12,6 @@ export class ReactPropTypes extends Recipe {
33
12
 
34
13
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
35
14
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
36
- private transformed = false;
37
-
38
15
  override async visitFieldAccess(fieldAccess: J.FieldAccess, ctx: ExecutionContext): Promise<J | undefined> {
39
16
  let fa = await super.visitFieldAccess(fieldAccess, ctx) as J.FieldAccess;
40
17
 
@@ -49,11 +26,10 @@ export class ReactPropTypes extends Recipe {
49
26
  return fa;
50
27
  }
51
28
 
52
- const local = maybeAddImport(this, {module: "prop-types", member: "default", preferredName: "PropTypes", onlyIfReferenced: false});
29
+ const local = maybeBind(this, {module: "prop-types", member: "default", preferredName: "PropTypes", onlyIfReferenced: false});
53
30
  if (!local) {
54
31
  return fa;
55
32
  }
56
- this.transformed = true;
57
33
 
58
34
  return {
59
35
  ...fa.name.element,
@@ -63,10 +39,9 @@ export class ReactPropTypes extends Recipe {
63
39
  }
64
40
 
65
41
  override async visitJsCompilationUnit(cu: any, ctx: ExecutionContext): Promise<J | undefined> {
66
- this.transformed = false;
67
42
  let result = await super.visitJsCompilationUnit(cu, ctx);
68
- if (this.transformed) {
69
- maybeRemoveImport(this, "react", "PropTypes");
43
+ if (result !== cu) {
44
+ maybeUnbind(this, {module: "react", member: "PropTypes"});
70
45
  }
71
46
  return result;
72
47
  }
@@ -1,5 +1,5 @@
1
1
  import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, maybeAddImport, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
2
+ import {JavaScriptVisitor, maybeBind, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
5
  const SERVER_METHODS = new Set(['renderToString', 'renderToStaticMarkup']);
@@ -13,23 +13,6 @@ const DOM_METHODS = new Set([
13
13
  ]);
14
14
 
15
15
  /**
16
- * Splits `React.render()` and other DOM methods to `ReactDOM`.
17
- *
18
- * In React 0.14+, DOM-specific methods were moved to the `react-dom` package.
19
- *
20
- * Before:
21
- * ```tsx
22
- * import React from 'react';
23
- * React.render(<App />, document.getElementById('root'));
24
- * ```
25
- *
26
- * After:
27
- * ```tsx
28
- * import React from 'react';
29
- * import ReactDOM from 'react-dom';
30
- * ReactDOM.render(<App />, document.getElementById('root'));
31
- * ```
32
- *
33
16
  * @see https://legacy.reactjs.org/blog/2015/10/07/react-v0.14.html#two-packages-react-and-react-dom
34
17
  */
35
18
  export class ReactToReactDom extends Recipe {
@@ -41,8 +24,8 @@ export class ReactToReactDom extends Recipe {
41
24
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
42
25
  private destination(methodName: string): string | undefined {
43
26
  return SERVER_METHODS.has(methodName)
44
- ? maybeAddImport(this, {module: 'react-dom/server', member: '*', preferredName: 'ReactDOMServer', onlyIfReferenced: false})
45
- : maybeAddImport(this, {module: 'react-dom', member: 'default', preferredName: 'ReactDOM', onlyIfReferenced: false});
27
+ ? maybeBind(this, {module: 'react-dom/server', member: '*', preferredName: 'ReactDOMServer', onlyIfReferenced: false})
28
+ : maybeBind(this, {module: 'react-dom', member: 'default', preferredName: 'ReactDOM', onlyIfReferenced: false});
46
29
  }
47
30
 
48
31
  override async visitFieldAccess(fieldAccess: J.FieldAccess, ctx: ExecutionContext): Promise<J | undefined> {
@@ -2,7 +2,7 @@ import {ExecutionContext, Recipe, TreeVisitor, check, not, randomId} from "@open
2
2
  import {isObjectLiteral, isVendoredOrBundled, JavaScriptVisitor, JS, namesDeclaredWithin, namesUsedWithin, template} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
  import {anyNode, isThis} from "../util/tree-search";
5
- import {extendsReactComponentByName} from "../util/react-class";
5
+ import {extendsReactComponent} from "../util/react-class";
6
6
 
7
7
  /** The lifecycle name without the `UNSAFE_` prefix. */
8
8
  function lifecycleName(method: J.MethodDeclaration): string {
@@ -71,32 +71,18 @@ const readsThisProps = (n: J) => n.kind === J.Kind.FieldAccess && isThis((n as J
71
71
  && (n as J.FieldAccess).name.element.simpleName === 'props';
72
72
 
73
73
  /**
74
- * Migrates the deprecated `componentWillMount` and `componentWillReceiveProps` lifecycles where that
75
- * is safe, and leaves everything else for the `UNSAFE_` prefix.
76
- *
77
- * - `componentWillMount() { this.setState({...}) }` becomes a `state = {...}` class field.
78
- * - A `componentWillMount` that neither touches `this.state` nor calls `setState` or `return`s moves to
79
- * `componentDidMount`, ahead of the existing body when there is one. It then runs after the first
80
- * render instead of before it, which is the move React recommends for side effects.
81
- * - A `componentWillReceiveProps(next)` whose whole body is one `if` comparing `next` with `this.props`
82
- * and that never calls `setState` becomes `componentDidUpdate(prevProps)`, with `next` and `this.props`
83
- * swapped. The guard keeps it from running on state-only updates, which `componentDidUpdate` also sees.
84
- *
85
- * A class that already has a constructor, a `state` field or a `componentDidUpdate` is not changed for the
86
- * case that would collide with it.
87
- *
88
74
  * @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html
89
75
  */
90
76
  export class MigrateDeprecatedLifecycles extends Recipe {
91
77
  readonly name = "org.openrewrite.react.17.migrate-deprecated-lifecycles";
92
78
  readonly displayName = "Migrate deprecated lifecycles where it is safe";
93
- readonly description = "Moves `componentWillMount` to a `state` field or `componentDidMount`, and a guarded `componentWillReceiveProps` to `componentDidUpdate`, when the move does not change what the component does. Everything else is left for the `UNSAFE_` prefix.";
79
+ readonly description = "Moves `componentWillMount` to a `state` field or `componentDidMount`, and a guarded `componentWillReceiveProps` to `componentDidUpdate`, when the move does not change what the component does. Everything else is left for the `UNSAFE_` prefix, as is a move that would collide with an existing constructor, `state` field or `componentDidUpdate`.";
94
80
 
95
81
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
96
82
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
97
83
  override async visitClassDeclaration(decl: J.ClassDeclaration, ctx: ExecutionContext): Promise<J | undefined> {
98
84
  const cd = await super.visitClassDeclaration(decl, ctx) as J.ClassDeclaration;
99
- if (!extendsReactComponentByName(cd)) return cd;
85
+ if (!extendsReactComponent(cd)) return cd;
100
86
  // React never calls the legacy lifecycles on a class with these, so moving them would make dead code live.
101
87
  if (cd.body.statements.some(s => s.element.kind === J.Kind.MethodDeclaration
102
88
  && ['getDerivedStateFromProps', 'getSnapshotBeforeUpdate'].includes((s.element as J.MethodDeclaration).name.simpleName))) return cd;
@@ -105,14 +91,12 @@ export class MigrateDeprecatedLifecycles extends Recipe {
105
91
  const find = (name: string) => statements.findIndex(s =>
106
92
  s.element.kind === J.Kind.MethodDeclaration && lifecycleName(s.element as J.MethodDeclaration) === name);
107
93
  const method = (i: number) => statements[i].element as J.MethodDeclaration;
108
- let changed = false;
109
94
 
110
95
  const willMount = find('componentWillMount');
111
96
  if (willMount >= 0 && method(willMount).body) {
112
97
  const replaced = await this.migrateWillMount(cd, statements, willMount, find('componentDidMount'));
113
98
  if (replaced) {
114
99
  statements = replaced;
115
- changed = true;
116
100
  }
117
101
  }
118
102
 
@@ -122,11 +106,12 @@ export class MigrateDeprecatedLifecycles extends Recipe {
122
106
  const migrated = await this.migrateWillReceiveProps(method(willReceive));
123
107
  if (migrated) {
124
108
  statements[willReceive] = {...statements[willReceive], element: migrated};
125
- changed = true;
126
109
  }
127
110
  }
128
111
 
129
- return changed ? {...cd, body: {...cd.body, statements}} as J.ClassDeclaration : cd;
112
+ return statements.length === cd.body.statements.length && statements.every((s, i) => s === cd.body.statements[i])
113
+ ? cd
114
+ : {...cd, body: {...cd.body, statements}} as J.ClassDeclaration;
130
115
  }
131
116
 
132
117
  /** The class members after moving `componentWillMount`, or `undefined` if it cannot be moved safely. */