@openrewrite/recipes-react 0.26.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 (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,6 +1,7 @@
1
1
  import {Column, DataTable, ExecutionContext, foundSearchResult, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
2
  import {JavaScriptVisitor, JS, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {isIdentifier, J} from "@openrewrite/rewrite/java";
4
+ import {anyOf, typedOrNamedCall} from "../util/react-matchers";
4
5
 
5
6
  class ServerRenderingRow {
6
7
  @Column({displayName: "File path", description: "The file path where the SSR API is used"})
@@ -20,17 +21,13 @@ const SSR_APIS = new Map<string, string>([
20
21
  ['renderToStaticNodeStream', 'Use renderToPipeableStream or renderToReadableStream instead (removed in React 19)'],
21
22
  ]);
22
23
 
23
- /**
24
- * Finds usage of React server-side rendering APIs from `react-dom/server`.
25
- *
26
- * Detects:
27
- * - `renderToString(element)` -- synchronous SSR, consider streaming alternatives
28
- * - `renderToStaticMarkup(element)` -- synchronous static markup, consider streaming
29
- * - `renderToNodeStream(element)` -- removed in React 19, use `renderToPipeableStream`
30
- * - `renderToStaticNodeStream(element)` -- removed in React 19, use streaming APIs
31
- *
32
- * Also detects named imports and namespace calls (ReactDOMServer.renderToString, ReactDOM.renderToString).
33
- */
24
+ const SSR_CALLS = [...SSR_APIS].map(([api, replacement]) => {
25
+ // A namespace or default import of `react-dom/server` is declared on `react-dom` (openrewrite/rewrite#9994)
26
+ const matcher = anyOf(`react-dom/server ${api}(..)`, `react-dom ${api}(..)`);
27
+ const calls = ['ReactDOMServer', 'ReactDOM'].map(receiver => typedOrNamedCall(matcher, receiver, api));
28
+ return {api, replacement, matches: (method: J.MethodInvocation) => calls.some(call => call(method))};
29
+ });
30
+
34
31
  export class FindServerRenderingUsage extends Recipe {
35
32
  readonly name = "org.openrewrite.react.search.find-server-rendering-usage";
36
33
  readonly displayName = "Find server-side rendering API usage";
@@ -48,74 +45,20 @@ export class FindServerRenderingUsage extends Recipe {
48
45
 
49
46
  return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
50
47
  private filePath = "";
51
- private importedSsrApis = new Set<string>();
52
48
 
53
49
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
54
50
  this.filePath = cu.sourcePath ?? "";
55
- this.importedSsrApis.clear();
56
51
  return super.visitJsCompilationUnit(cu, ctx);
57
52
  }
58
53
 
59
- // Detect imports of SSR APIs
60
- override async visitImportSpecifier(spec: JS.ImportSpecifier, ctx: ExecutionContext): Promise<J | undefined> {
61
- const specifier = spec.specifier;
62
-
63
- let importedName: string | undefined;
64
- if (specifier.kind === JS.Kind.Alias) {
65
- const alias = specifier as JS.Alias;
66
- const propName = alias.propertyName.element;
67
- if (isIdentifier(propName)) {
68
- importedName = propName.simpleName;
69
- }
70
- } else if (isIdentifier(specifier)) {
71
- importedName = specifier.simpleName;
72
- }
73
-
74
- const importReplacement = importedName ? SSR_APIS.get(importedName) : undefined;
75
- if (importedName && importReplacement) {
76
- this.importedSsrApis.add(importedName);
77
- dataTable.insertRow(ctx, {
78
- filePath: this.filePath,
79
- apiName: importedName,
80
- replacement: importReplacement
81
- });
82
- return foundSearchResult(spec, `SSR API: ${importedName}`);
83
- }
84
-
85
- return super.visitImportSpecifier(spec, ctx);
86
- }
87
-
88
- // Detect method calls: renderToString(...), ReactDOMServer.renderToString(...), etc.
89
54
  override async visitMethodInvocation(method: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
90
- let m = await super.visitMethodInvocation(method, ctx) as J.MethodInvocation;
91
-
92
- const methodName = m.name.simpleName;
93
-
94
- const replacement = SSR_APIS.get(methodName);
95
- if (!replacement) return m;
96
-
97
- // Direct call from named import: renderToString(...)
98
- if (!m.select && this.importedSsrApis.has(methodName)) {
99
- return foundSearchResult(m, `SSR API: ${methodName}`);
100
- }
101
-
102
- // Namespace call: ReactDOMServer.renderToString(...), ReactDOM.renderToString(...)
103
- if (m.select) {
104
- const select = (m.select as any).element ?? m.select;
105
- if (isIdentifier(select)) {
106
- const ns = select.simpleName;
107
- if (ns === 'ReactDOMServer' || ns === 'ReactDOM') {
108
- dataTable.insertRow(ctx, {
109
- filePath: this.filePath,
110
- apiName: `${ns}.${methodName}`,
111
- replacement
112
- });
113
- return foundSearchResult(m, `SSR API: ${ns}.${methodName}`);
114
- }
115
- }
116
- }
117
-
118
- return m;
55
+ const m = await super.visitMethodInvocation(method, ctx) as J.MethodInvocation;
56
+ const call = SSR_CALLS.find(c => c.matches(m));
57
+ if (!call) return m;
58
+ const select = m.select?.element;
59
+ const apiName = select && isIdentifier(select) ? `${select.simpleName}.${call.api}` : call.api;
60
+ dataTable.insertRow(ctx, {filePath: this.filePath, apiName, replacement: call.replacement});
61
+ return foundSearchResult(m, `SSR API: ${apiName}`);
119
62
  }
120
63
  }());
121
64
  }
@@ -2,14 +2,6 @@ import {ExecutionContext, Recipe, TreeVisitor, check, mapAsync, not, updateIfCha
2
2
  import {JavaScriptVisitor, JS, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
 
5
- /**
6
- * Simplifies object pattern properties where the key and value have the same name.
7
- *
8
- * Examples:
9
- * - `{ x: x }` → `{ x }`
10
- * - `{ ref: ref, ...props }` → `{ ref, ...props }`
11
- * - `{ foo: foo, bar: bar }` → `{ foo, bar }`
12
- */
13
5
  export class SimplifyObjectPatternProperty extends Recipe {
14
6
  readonly name = "org.openrewrite.javascript.cleanup.simplify-object-pattern-property";
15
7
  readonly displayName: string = "Simplify object pattern properties";
@@ -1,5 +1,5 @@
1
1
  import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
- import {JavaScriptVisitor, JS, maybeAddImport, isVendoredOrBundled, namesDeclaredIn} from "@openrewrite/rewrite/javascript";
2
+ import {JavaScriptVisitor, JS, maybeBind, isVendoredOrBundled, namesDeclaredIn} from "@openrewrite/rewrite/javascript";
3
3
  import {J} from "@openrewrite/rewrite/java";
4
4
  import {importBindings} from "./util/module-imports";
5
5
 
@@ -73,26 +73,6 @@ function getReactMethodName(method: J.MethodInvocation): string | undefined {
73
73
  return methodName;
74
74
  }
75
75
 
76
- /**
77
- * Simplifies React namespace usage by converting `React.xxx` to direct imports.
78
- *
79
- * Instead of:
80
- * ```tsx
81
- * import React from 'react';
82
- * const [count, setCount] = React.useState(0);
83
- * ```
84
- *
85
- * This recipe produces:
86
- * ```tsx
87
- * import React, { useState } from 'react';
88
- * const [count, setCount] = useState(0);
89
- * ```
90
- *
91
- * This is a modern best practice that:
92
- * - Reduces bundle size when tree-shaking is applied
93
- * - Makes code more readable
94
- * - Aligns with React team recommendations
95
- */
96
76
  export class SimplifyReactImports extends Recipe {
97
77
  readonly name = "org.openrewrite.react.simplify-react-imports";
98
78
  readonly displayName: string = "Simplify `React.xxx` to direct imports";
@@ -105,7 +85,7 @@ export class SimplifyReactImports extends Recipe {
105
85
 
106
86
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
107
87
  this.usedExports = new Set<string>();
108
- // File-wide rather than in scope, as `maybeAddImport` aliases the import when any binding of the name is declared
88
+ // File-wide rather than in scope, as `maybeBind` aliases the import when any binding of the name is declared
109
89
  this.declaredNames = new Set(namesDeclaredIn(cu));
110
90
  for (const {local, name, module} of importBindings(cu)) {
111
91
  if (module === 'react' && local === name) this.declaredNames.delete(local);
@@ -115,7 +95,7 @@ export class SimplifyReactImports extends Recipe {
115
95
 
116
96
  // Already known to be referenced, since they were just unqualified
117
97
  for (const exportName of this.usedExports) {
118
- maybeAddImport(this, {module: "react", member: exportName, onlyIfReferenced: false});
98
+ maybeBind(this, {module: "react", member: exportName, onlyIfReferenced: false});
119
99
  }
120
100
 
121
101
  return result;
@@ -1,6 +1,6 @@
1
1
  import {JS, JSX, namesReferencedWithin, walk} from "@openrewrite/rewrite/javascript";
2
2
  import {Expression, isIdentifier, J, Type} from "@openrewrite/rewrite/java";
3
- import {COMPONENT_BASES, unwrapBaseType} from "../util/react-class";
3
+ import {COMPONENT_BASES, reactComponentSupertype, unwrapBaseType} from "../util/react-class";
4
4
  import {importBindings, namespaceImports, resolveRelative} from "../util/module-imports";
5
5
 
6
6
  /**
@@ -152,7 +152,8 @@ function reactMember(node: J | undefined, names: ReadonlySet<string>): boolean {
152
152
  /** Whether a class extends `Component` or `PureComponent`, bare or as a member of `React`, so that its `render` is its own. */
153
153
  function reactBaseClass(declaration: J.ClassDeclaration): boolean {
154
154
  const base = unwrapBaseType(declaration.extends?.element);
155
- return base !== undefined && (isIdentifier(base) ? COMPONENT_BASES.has(base.simpleName) : reactMember(base, COMPONENT_BASES));
155
+ return reactComponentSupertype(declaration) ??
156
+ (base !== undefined && (isIdentifier(base) ? COMPONENT_BASES.has(base.simpleName) : reactMember(base, COMPONENT_BASES)));
156
157
  }
157
158
 
158
159
  /** A top-level declaration that can be a component, the export name it has, if any, and the body that renders it. */
@@ -1,6 +1,6 @@
1
- import {and, check, Cursor, DataTable, ExecutionContext, findMarker, MarkersKind, MarkupWarn, not, Option, or, randomId, RecipeRef, ScanningRecipe, SourceFile, Tree, TreePrinters, TreeVisitor} from "@openrewrite/rewrite";
1
+ import {and, check, Cursor, DataTable, ExecutionContext, findMarker, mapAsync, MarkersKind, MarkupWarn, not, Option, or, randomId, RecipeRef, ScanningRecipe, SourceFile, Tree, TreePrinters, TreeVisitor, updateIfChanged} from "@openrewrite/rewrite";
2
2
  import {isPlainText} from "@openrewrite/rewrite/text";
3
- import {AddDependencyOptions, autoFormat, Autodetect, capture, PrettierStyle, deconflict, findNodeResolutionResult, isTypeScript, isVendoredOrBundled, JavaScriptVisitor, JS, maybeAddImport, maybeRemoveImport, moduleBindings, namesUsedIn, pattern, walk, raw, rewrite, scopeOf, StyleKind, Template, template, usesMethod} from "@openrewrite/rewrite/javascript";
3
+ import {AddDependencyOptions, autoFormat, Autodetect, capture, PrettierStyle, deconflict, findNodeResolutionResult, isTypeScript, isVendoredOrBundled, JavaScriptVisitor, JS, maybeBind, maybeUnbind, moduleBindings, namesUsedIn, pattern, walk, raw, rewrite, scopeOf, StyleKind, Template, template, usesMethod} from "@openrewrite/rewrite/javascript";
4
4
  import {Expression, isIdentifier, J, Type, TypedTree} from "@openrewrite/rewrite/java";
5
5
  import {create} from "mutative";
6
6
  import {Json, JsonVisitor} from "@openrewrite/rewrite/json";
@@ -183,7 +183,6 @@ function dependencySteps(forecast: ConversionForecast) {
183
183
  return {rtl, dom18, rtl18: new AddTestingLibraryReact18(forecast, dom18)};
184
184
  }
185
185
 
186
- /** Adds {@link RTL_ADDITION}. */
187
186
  export class AddTestingLibraryReact extends EnzymeTestDependency {
188
187
  readonly name = "org.openrewrite.react.migrate.add-testing-library-react";
189
188
  readonly displayName = "Add `@testing-library/react` where Enzyme tests are migrated";
@@ -194,7 +193,6 @@ export class AddTestingLibraryReact extends EnzymeTestDependency {
194
193
  }
195
194
  }
196
195
 
197
- /** Adds {@link RTL_18_ADDITION}. */
198
196
  export class AddTestingLibraryReact18 extends EnzymeTestDependency {
199
197
  readonly name = "org.openrewrite.react.migrate.add-testing-library-react-18";
200
198
  readonly displayName = "Add `@testing-library/react` 16 where Enzyme tests on React 18 are migrated";
@@ -211,7 +209,6 @@ export class AddTestingLibraryReact18 extends EnzymeTestDependency {
211
209
  }
212
210
  }
213
211
 
214
- /** Adds {@link DOM_18_ADDITION}, the peer of {@link RTL_18_ADDITION}. */
215
212
  export class AddTestingLibraryDom18 extends EnzymeTestDependency {
216
213
  readonly name = "org.openrewrite.react.migrate.add-testing-library-dom-18";
217
214
  readonly displayName = "Add `@testing-library/dom` where Enzyme tests on React 18 are migrated";
@@ -572,31 +569,8 @@ function withoutStatements(block: J.Block, removed: ReadonlySet<string>): J.Bloc
572
569
  }
573
570
 
574
571
  /**
575
- * Converts an Enzyme `mount` wrapper only when all of its uses can be converted together, so no
576
- * partially migrated wrapper can escape. Inline expressions such as
577
- * `mount(<Button />).find('button').length` and `const wrapper = mount(<Button />)` declarations
578
- * whose every reference is a supported DOM read become RTL renders into a detached container.
579
- *
580
- * A `shallow` wrapper converts the same way where the full render cannot differ from the shallow
581
- * one: its component, scanned from the source it is imported from, creates host elements only and
582
- * runs no effects, and receives no component element from the test. `simulate` and `html()` stay
583
- * excluded there, since a shallow render calls a handler without bubbling and prints static markup.
584
- *
585
- * ```tsx
586
- * // before, where `Label` renders `<ul><li>{text}</li></ul>`
587
- * const wrapper = shallow(<Label text="a" />);
588
- * expect(wrapper.find('li').length).toBe(1);
589
- * // after
590
- * const wrapper = render(<Label text="a" />, {container: document.createElement('div')});
591
- * expect(wrapper.container.querySelectorAll('li').length).toBe(1);
592
- * ```
593
- *
594
- * Existing compatible RTL installation and DOM test setup are prerequisites. More complex
595
- * wrapper flows remain in the inventory rather than being guessed at.
596
- *
597
572
  * @see https://testing-library.com/docs/react-testing-library/migrate-from-enzyme/#how-to-migrate-from-enzyme-to-react-testing-library
598
573
  */
599
-
600
574
  export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
601
575
  readonly name: string = "org.openrewrite.react.migrate.enzyme-to-react-testing-library";
602
576
  readonly displayName: string = "Migrate Enzyme to React Testing Library";
@@ -1000,7 +974,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1000
974
  /** The shared wrapper's declaration, typed as RTL's `RenderResult` where it had a type, which an Enzyme type was. */
1001
975
  private async renderResultDeclaration(declaration: J.VariableDeclarations, block: J.Block): Promise<J.VariableDeclarations> {
1002
976
  if (!declaration.typeExpression) return declaration;
1003
- const local = maybeAddImport(this, {module: RTL, member: "RenderResult", typeOnly: true, onlyIfReferenced: false}) ?? "RenderResult";
977
+ const local = maybeBind(this, {module: RTL, member: "RenderResult", typeOnly: true, onlyIfReferenced: false}) ?? "RenderResult";
1004
978
  const name = (declaration.variables[0].element.name as J.Identifier).simpleName;
1005
979
  const typed = await Template.builder().code(`let ${name}: ${local}`).build()
1006
980
  .apply(declaration, new Cursor(declaration, new Cursor(block, this.cursor.parent))) as J.VariableDeclarations | undefined;
@@ -1049,7 +1023,7 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1049
1023
  continue;
1050
1024
  }
1051
1025
  if (cleanup.has(id)) {
1052
- const local = maybeAddImport(outer, {module: RTL, member: "cleanup", onlyIfReferenced: false}) ?? "cleanup";
1026
+ const local = maybeBind(outer, {module: RTL, member: "cleanup", onlyIfReferenced: false}) ?? "cleanup";
1053
1027
  const replaced = await Template.builder().code(`${local}()`).build().apply(statement.element, cursor) as J | undefined;
1054
1028
  if (!replaced) throw new Error("Cannot clean up the shared wrapper");
1055
1029
  cleaned = true;
@@ -1230,21 +1204,12 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1230
1204
  private async withPrettierLayout(block: J.Block, ctx: ExecutionContext): Promise<J.Block> {
1231
1205
  if (this.reformat.size === 0) return block;
1232
1206
  const parent = new Cursor(block, this.cursor.parent);
1233
- const statements: J.Block["statements"][number][] = [];
1234
- let formatted = false;
1235
- for (const statement of block.statements) {
1207
+ return updateIfChanged(block, {statements: await mapAsync(block.statements, async statement => {
1236
1208
  const ids = idsWithin(statement.element, this.reformat);
1237
- if (ids.length === 0) {
1238
- statements.push(statement);
1239
- continue;
1240
- }
1209
+ if (ids.length === 0) return statement;
1241
1210
  ids.forEach(id => this.reformat.delete(id));
1242
- statements.push({...statement, element: await autoFormat(statement.element, ctx, undefined, new Cursor(statement, parent))});
1243
- formatted = true;
1244
- }
1245
- return formatted ? create(block, draft => {
1246
- draft.statements = statements as any;
1247
- }) : block;
1211
+ return {...statement, element: await autoFormat(statement.element, ctx, undefined, new Cursor(statement, parent))};
1212
+ })});
1248
1213
  }
1249
1214
 
1250
1215
  override async visitVariableDeclarations(declarations: J.VariableDeclarations, ctx: ExecutionContext): Promise<J | undefined> {
@@ -1525,8 +1490,8 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1525
1490
  }
1526
1491
 
1527
1492
  private converted(api: string, scope: string, reason: string): void {
1528
- maybeRemoveImport(this, ENZYME);
1529
- if (snapshots) maybeRemoveImport(this, "enzyme-to-json");
1493
+ maybeUnbind(this, ENZYME);
1494
+ if (snapshots) maybeUnbind(this, "enzyme-to-json");
1530
1495
  this.rows.push({sourcePath: this.sourcePath, scope, api, status: "CONVERTED", reason,
1531
1496
  suggestedAction: "Run the migrated test and review whether an accessible RTL query would better express its intent."});
1532
1497
  }
@@ -1540,11 +1505,6 @@ export class EnzymeToReactTestingLibrary extends ScanningRecipe<Scanned> {
1540
1505
  }
1541
1506
  }
1542
1507
 
1543
- /**
1544
- * {@link EnzymeToReactTestingLibrary}, also converting snapshot assertions of the wrappers it converts. RTL
1545
- * snapshots the rendered DOM, which Enzyme's serializer records as a component tree, so every converted
1546
- * snapshot is written anew on the next run with `--updateSnapshot` and should be reviewed then.
1547
- */
1548
1508
  export class EnzymeSnapshotsToReactTestingLibrary extends EnzymeToReactTestingLibrary {
1549
1509
  override readonly name = "org.openrewrite.react.migrate.enzyme-snapshots-to-react-testing-library";
1550
1510
  override readonly displayName = "Migrate Enzyme to React Testing Library, snapshots included";
@@ -56,8 +56,8 @@ export function enzymeModule(value: unknown): value is string {
56
56
  export function enzymeMethod(method: J.MethodInvocation): string | undefined {
57
57
  const type = method.methodType;
58
58
  if (!type) return undefined;
59
- const owner = Type.FullyQualified.getFullyQualifiedName(type.declaringType);
60
- return owner === ENZYME || owner.startsWith(`${ENZYME}.`) ? type.name : undefined;
59
+ return Type.isOfTypeWithName(type.declaringType, false, owner => owner === ENZYME || owner.startsWith(`${ENZYME}.`))
60
+ ? type.name : undefined;
61
61
  }
62
62
 
63
63
  export function enzymeWrapper(type: Type | undefined): boolean {
@@ -1,9 +1,10 @@
1
1
  import {Cursor, ExecutionContext} from "@openrewrite/rewrite";
2
- import {compilationUnitOf, isObjectLiteral, JavaScriptVisitor, JS, JSX, referencesOf, walk} from "@openrewrite/rewrite/javascript";
2
+ import {isObjectLiteral, JavaScriptVisitor, JS, JSX, MethodMatcher, referencesOf, walk} from "@openrewrite/rewrite/javascript";
3
3
  import {emptySpace, Expression, isIdentifier, J} from "@openrewrite/rewrite/java";
4
4
  import {create} from "mutative";
5
5
  import {enzymeMethod, enzymeWrapper} from "./enzyme-usage";
6
- import {importBindings} from "../util/module-imports";
6
+
7
+ const ENZYME_TO_JSON = new MethodMatcher("enzyme-to-json *(..)");
7
8
 
8
9
  const HTML_TAGS = new Set(["a", "abbr", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo",
9
10
  "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "data",
@@ -414,7 +415,6 @@ export function analyzeWrapperScope(block: Cursor, {declaration, name}: WrapperD
414
415
  optInSnapshots?: boolean, optionalChaining?: boolean, constant?: (node: J) => string | undefined,
415
416
  /** Told every reference that rejects the scope, whether it comes after an unmount, and the snapshot assertion it is the subject of. */
416
417
  blocked?: (references: BlockingReference[]) => void}): WrapperScope | undefined {
417
- let serializers: ReadonlySet<string> | undefined;
418
418
  const uses = new Map<string, WrapperRead>();
419
419
  const removedStatements = new Set<string>();
420
420
  const unmounts = new Set<string>();
@@ -457,8 +457,7 @@ export function analyzeWrapperScope(block: Cursor, {declaration, name}: WrapperD
457
457
  const ancestors = ancestorsOf(reference);
458
458
  const first = ancestors[0]?.value as J | undefined;
459
459
  if (snapshots) {
460
- serializers ??= snapshotSerializers(block);
461
- const assertion = snapshotAssertion(identifier, ancestors, serializers);
460
+ const assertion = snapshotAssertion(identifier, ancestors);
462
461
  if (assertion) return record(assertion, {wrapper: identifier, use: "snapshot"});
463
462
  }
464
463
  if (!selectOf(first, identifier)) return false;
@@ -567,9 +566,8 @@ export function analyzeWrapperScope(block: Cursor, {declaration, name}: WrapperD
567
566
  if (!blocked) return undefined;
568
567
  let snapshot: J.MethodInvocation | undefined;
569
568
  if (optInSnapshots && !after && !reference.declares) {
570
- serializers ??= snapshotSerializers(block);
571
569
  const ancestors = ancestorsOf(reference.cursor);
572
- const expectCall = snapshotAssertion(reference.identifier, ancestors, serializers);
570
+ const expectCall = snapshotAssertion(reference.identifier, ancestors);
573
571
  snapshot = expectCall && ancestors.find(c => c.value.kind === J.Kind.MethodInvocation && (c.value as J.MethodInvocation).select?.element === expectCall)?.value;
574
572
  }
575
573
  rejected.push({cursor: reference.cursor, unmounted: after, snapshot});
@@ -582,23 +580,17 @@ export function analyzeWrapperScope(block: Cursor, {declaration, name}: WrapperD
582
580
  return {declaration, name, uses, removedStatements, unmounts};
583
581
  }
584
582
 
585
- /** The local names a source binds to `enzyme-to-json`'s serializers, such as its default export `toJson`. */
586
- function snapshotSerializers(cursor: Cursor): ReadonlySet<string> {
587
- const cu = compilationUnitOf(cursor);
588
- return new Set(cu ? importBindings(cu).filter(({module}) => module === "enzyme-to-json").map(({local}) => local) : []);
589
- }
590
-
591
583
  /**
592
584
  * The `expect(wrapper)` or `expect(toJson(wrapper))` call of a `toMatchSnapshot()` assertion of the
593
585
  * wrapper, with no property matcher and at most a snapshot name.
594
586
  */
595
- function snapshotAssertion(identifier: J.Identifier, ancestors: Cursor[], serializers: ReadonlySet<string>): J.MethodInvocation | undefined {
587
+ function snapshotAssertion(identifier: J.Identifier, ancestors: Cursor[]): J.MethodInvocation | undefined {
596
588
  let k = 0;
597
589
  const onlyArgument = (call: J | undefined, argument: J) => call?.kind === J.Kind.MethodInvocation && !(call as J.MethodInvocation).select &&
598
590
  (call as J.MethodInvocation).arguments.elements.length === 1 && (call as J.MethodInvocation).arguments.elements[0].element === argument;
599
591
  let subject: J = identifier;
600
592
  const serialized = ancestors[k]?.value as J | undefined;
601
- if (onlyArgument(serialized, subject) && serializers.has((serialized as J.MethodInvocation).name.simpleName)) {
593
+ if (onlyArgument(serialized, subject) && ENZYME_TO_JSON.matches((serialized as J.MethodInvocation).methodType)) {
602
594
  subject = serialized!;
603
595
  k++;
604
596
  }
@@ -1,8 +1,9 @@
1
- import {J} from "@openrewrite/rewrite/java";
1
+ import {J, Type} from "@openrewrite/rewrite/java";
2
2
  import {JS} from "@openrewrite/rewrite/javascript";
3
3
 
4
4
  /** The React base classes of a class component. */
5
5
  export const COMPONENT_BASES: ReadonlySet<string> = new Set(['Component', 'PureComponent']);
6
+ const COMPONENT_TYPES: ReadonlySet<string> = new Set(['React.Component', 'React.PureComponent']);
6
7
 
7
8
  /** `Component<P, S>` is a parameterized type (possibly wrapped in a type-tree expression) around the plain name; this returns that name. */
8
9
  export function unwrapBaseType(type: J | undefined): J | undefined {
@@ -33,3 +34,18 @@ export function extendsReactComponentByName(cd: J.ClassDeclaration): boolean {
33
34
  const name = extendedClassName(cd);
34
35
  return !!name && COMPONENT_BASES.has(name);
35
36
  }
37
+
38
+ /**
39
+ * Whether the class directly extends React's `Component` or `PureComponent`, as its supertype says, or `undefined` where
40
+ * the supertype is not attributed, such as in plain JavaScript without `@types/react`.
41
+ */
42
+ export function reactComponentSupertype(cd: J.ClassDeclaration): boolean | undefined {
43
+ const supertype = (cd.type as Type.Class | undefined)?.supertype;
44
+ if (!supertype || supertype.kind === Type.Kind.Unknown) return undefined;
45
+ return Type.isOfTypeWithName(supertype, false, name => COMPONENT_TYPES.has(name));
46
+ }
47
+
48
+ /** Whether the class extends `Component` or `PureComponent`: by its supertype, or by name where that is not attributed. */
49
+ export function extendsReactComponent(cd: J.ClassDeclaration): boolean {
50
+ return reactComponentSupertype(cd) ?? extendsReactComponentByName(cd);
51
+ }
@@ -0,0 +1,34 @@
1
+ import {MethodMatcher} from "@openrewrite/rewrite/javascript";
2
+ import {isIdentifier, J, Type} from "@openrewrite/rewrite/java";
3
+
4
+ export interface CallMatcher {
5
+ matches(method: Type.Method | undefined): boolean;
6
+ }
7
+
8
+ export function anyOf(...patterns: string[]): CallMatcher {
9
+ const matchers = patterns.map(pattern => new MethodMatcher(pattern));
10
+ return {matches: method => matchers.some(matcher => matcher.matches(method))};
11
+ }
12
+
13
+ /**
14
+ * Matches calls of a function `react` exports, such as `reactFunction("useRef")`. `@types/react` declares them on
15
+ * the `React` namespace; in an LST built without it, a call is declared on the module it was imported or required
16
+ * from, `react`.
17
+ */
18
+ export function reactFunction(name: string): CallMatcher {
19
+ return anyOf(`React ${name}(..)`, `react ${name}(..)`);
20
+ }
21
+
22
+ /**
23
+ * Matches `<receiver>.<name>(..)` calls of an API that legacy JavaScript often reaches through a global, such as the
24
+ * UMD build's `ReactDOM`: by type where the call is attributed, and by the receiver's and method's names only where its
25
+ * declaring type is unknown.
26
+ */
27
+ export function typedOrNamedCall(matcher: CallMatcher, receiver: string, name: string): (method: J.MethodInvocation) => boolean {
28
+ return method => {
29
+ const declaringType = method.methodType?.declaringType;
30
+ if (declaringType && declaringType.kind !== Type.Kind.Unknown) return matcher.matches(method.methodType);
31
+ const select = method.select?.element;
32
+ return method.name.simpleName === name && !!select && isIdentifier(select) && select.simpleName === receiver;
33
+ };
34
+ }