@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.
- package/dist/i18n/translate-hard-coded-strings.d.ts.map +1 -1
- package/dist/i18n/translate-hard-coded-strings.js +3 -2
- package/dist/i18n/translate-hard-coded-strings.js.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -18
- package/dist/index.js.map +1 -1
- package/dist/migration/change-component-prop-value.d.ts.map +1 -1
- package/dist/migration/change-component-prop-value.js.map +1 -1
- package/dist/migration/cra-to-vite/add-vite-config.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/add-vite-config.js.map +1 -1
- package/dist/migration/cra-to-vite/cra-to-vite.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/cra-to-vite.js.map +1 -1
- package/dist/migration/cra-to-vite/find-cra-config-blockers.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/find-cra-config-blockers.js.map +1 -1
- package/dist/migration/cra-to-vite/find-cra-env-file-blockers.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/find-cra-env-file-blockers.js.map +1 -1
- package/dist/migration/cra-to-vite/find-cra-source-blockers.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/find-cra-source-blockers.js.map +1 -1
- package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.js.map +1 -1
- package/dist/migration/cra-to-vite/migrate-cra-package.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/migrate-cra-package.js.map +1 -1
- package/dist/migration/cra-to-vite/migrate-cra-svg-imports.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/migrate-cra-svg-imports.js +3 -3
- package/dist/migration/cra-to-vite/migrate-cra-svg-imports.js.map +1 -1
- package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/migrate-cra-tests-to-vitest.js.map +1 -1
- package/dist/migration/cra-to-vite/move-public-index-html.d.ts +1 -1
- package/dist/migration/cra-to-vite/move-public-index-html.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/move-public-index-html.js +1 -1
- package/dist/migration/cra-to-vite/move-public-index-html.js.map +1 -1
- package/dist/migration/cra-to-vite/remove-cra-configuration.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/remove-cra-configuration.js.map +1 -1
- package/dist/migration/cra-to-vite/rename-jsx-files.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/rename-jsx-files.js.map +1 -1
- package/dist/migration/cra-to-vite/rename-process-env-react-app.d.ts +1 -1
- package/dist/migration/cra-to-vite/rename-process-env-react-app.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/rename-process-env-react-app.js +1 -1
- package/dist/migration/cra-to-vite/rename-process-env-react-app.js.map +1 -1
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.d.ts +1 -1
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js +1 -1
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js.map +1 -1
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts +1 -1
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js +1 -1
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js.map +1 -1
- package/dist/migration/cra-to-vite/update-react-app-env-types.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/update-react-app-env-types.js.map +1 -1
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.js.map +1 -1
- package/dist/migration/cra-to-vite/update-tsconfig-for-vite.d.ts.map +1 -1
- package/dist/migration/cra-to-vite/update-tsconfig-for-vite.js.map +1 -1
- package/dist/mui/adapt-v4-theme.d.ts.map +1 -1
- package/dist/mui/adapt-v4-theme.js +1 -1
- package/dist/mui/adapt-v4-theme.js.map +1 -1
- package/dist/mui/add-component-prop.d.ts.map +1 -1
- package/dist/mui/add-component-prop.js.map +1 -1
- package/dist/mui/add-emotion-prepend.d.ts.map +1 -1
- package/dist/mui/add-emotion-prepend.js +3 -16
- package/dist/mui/add-emotion-prepend.js.map +1 -1
- package/dist/mui/convert-mui-imports.d.ts.map +1 -1
- package/dist/mui/convert-mui-imports.js +1 -1
- package/dist/mui/convert-mui-imports.js.map +1 -1
- package/dist/mui/convert-prop-to-sx.d.ts.map +1 -1
- package/dist/mui/convert-prop-to-sx.js +1 -1
- package/dist/mui/convert-prop-to-sx.js.map +1 -1
- package/dist/mui/mark-manual-migration.d.ts.map +1 -1
- package/dist/mui/mark-manual-migration.js.map +1 -1
- package/dist/mui/mark-palette-mode-usage.d.ts.map +1 -1
- package/dist/mui/mark-palette-mode-usage.js.map +1 -1
- package/dist/mui/move-component-prop-to-slot.d.ts.map +1 -1
- package/dist/mui/move-component-prop-to-slot.js.map +1 -1
- package/dist/mui/move-primary-text-to-children.d.ts.map +1 -1
- package/dist/mui/move-primary-text-to-children.js.map +1 -1
- package/dist/mui/move-system-props-to-sx.d.ts.map +1 -1
- package/dist/mui/move-system-props-to-sx.js +1 -1
- package/dist/mui/move-system-props-to-sx.js.map +1 -1
- package/dist/mui/remove-component-prop.d.ts.map +1 -1
- package/dist/mui/remove-component-prop.js.map +1 -1
- package/dist/mui/remove-root-ref.d.ts.map +1 -1
- package/dist/mui/remove-root-ref.js +1 -1
- package/dist/mui/remove-root-ref.js.map +1 -1
- package/dist/mui/remove-spacing-px-suffix.d.ts.map +1 -1
- package/dist/mui/remove-spacing-px-suffix.js +7 -10
- package/dist/mui/remove-spacing-px-suffix.js.map +1 -1
- package/dist/mui/rename-component-prop.d.ts.map +1 -1
- package/dist/mui/rename-component-prop.js.map +1 -1
- package/dist/mui/rename-joy-css-variables.d.ts.map +1 -1
- package/dist/mui/rename-joy-css-variables.js.map +1 -1
- package/dist/mui/rename-theme-palette-type.d.ts.map +1 -1
- package/dist/mui/rename-theme-palette-type.js.map +1 -1
- package/dist/mui/replace-box-border-radius.d.ts.map +1 -1
- package/dist/mui/replace-box-border-radius.js.map +1 -1
- package/dist/mui/replace-breakpoints-width.d.ts.map +1 -1
- package/dist/mui/replace-breakpoints-width.js.map +1 -1
- package/dist/mui/replace-component-class.d.ts.map +1 -1
- package/dist/mui/replace-component-class.js.map +1 -1
- package/dist/mui/replace-components-with-slots.d.ts.map +1 -1
- package/dist/mui/replace-components-with-slots.js.map +1 -1
- package/dist/mui/replace-import-paths.d.ts.map +1 -1
- package/dist/mui/replace-import-paths.js.map +1 -1
- package/dist/mui/replace-in-string-literals.d.ts.map +1 -1
- package/dist/mui/replace-in-string-literals.js.map +1 -1
- package/dist/mui/replace-list-item-button-prop.d.ts.map +1 -1
- package/dist/mui/replace-list-item-button-prop.js +2 -2
- package/dist/mui/replace-list-item-button-prop.js.map +1 -1
- package/dist/mui/replace-tabs-scroll-buttons.d.ts.map +1 -1
- package/dist/mui/replace-tabs-scroll-buttons.js.map +1 -1
- package/dist/mui/replace-theme-color-functions.d.ts.map +1 -1
- package/dist/mui/replace-theme-color-functions.js +7 -21
- package/dist/mui/replace-theme-color-functions.js.map +1 -1
- package/dist/mui/replace-theme-spacing-unit.d.ts.map +1 -1
- package/dist/mui/replace-theme-spacing-unit.js.map +1 -1
- package/dist/mui/replace-typography-round.d.ts.map +1 -1
- package/dist/mui/replace-typography-round.js.map +1 -1
- package/dist/mui/shift-hidden-down-props.d.ts.map +1 -1
- package/dist/mui/shift-hidden-down-props.js +4 -5
- package/dist/mui/shift-hidden-down-props.js.map +1 -1
- package/dist/mui/update-theme-breakpoints.d.ts.map +1 -1
- package/dist/mui/update-theme-breakpoints.js.map +1 -1
- package/dist/mui/upgrade-grid-props.d.ts.map +1 -1
- package/dist/mui/upgrade-grid-props.js +1 -1
- package/dist/mui/upgrade-grid-props.js.map +1 -1
- package/dist/react-native/view-prop-types.d.ts.map +1 -1
- package/dist/react-native/view-prop-types.js +3 -9
- package/dist/react-native/view-prop-types.js.map +1 -1
- package/dist/react16/error-boundaries.d.ts.map +1 -1
- package/dist/react16/error-boundaries.js +1 -1
- package/dist/react16/error-boundaries.js.map +1 -1
- package/dist/react16/find-dom-node.d.ts.map +1 -1
- package/dist/react16/find-dom-node.js.map +1 -1
- package/dist/react16/react-dom-factories.d.ts.map +1 -1
- package/dist/react16/react-dom-factories.js.map +1 -1
- package/dist/react16/react-prop-types.d.ts.map +1 -1
- package/dist/react16/react-prop-types.js +3 -9
- package/dist/react16/react-prop-types.js.map +1 -1
- package/dist/react16/react-to-react-dom.d.ts.map +1 -1
- package/dist/react16/react-to-react-dom.js +2 -2
- package/dist/react16/react-to-react-dom.js.map +1 -1
- package/dist/react17/migrate-deprecated-lifecycles.d.ts +1 -1
- package/dist/react17/migrate-deprecated-lifecycles.d.ts.map +1 -1
- package/dist/react17/migrate-deprecated-lifecycles.js +5 -6
- package/dist/react17/migrate-deprecated-lifecycles.js.map +1 -1
- package/dist/react17/remove-event-persist.d.ts.map +1 -1
- package/dist/react17/remove-event-persist.js +128 -63
- package/dist/react17/remove-event-persist.js.map +1 -1
- package/dist/react17/rename-unsafe-lifecycles.d.ts.map +1 -1
- package/dist/react17/rename-unsafe-lifecycles.js +1 -1
- package/dist/react17/rename-unsafe-lifecycles.js.map +1 -1
- package/dist/react17/update-react-imports.d.ts.map +1 -1
- package/dist/react17/update-react-imports.js +1 -1
- package/dist/react17/update-react-imports.js.map +1 -1
- package/dist/react17/use-new-jsx-transform.d.ts +1 -1
- package/dist/react17/use-new-jsx-transform.d.ts.map +1 -1
- package/dist/react17/use-new-jsx-transform.js +2 -1
- package/dist/react17/use-new-jsx-transform.js.map +1 -1
- package/dist/react18/add-children-to-props.js +1 -1
- package/dist/react18/add-children-to-props.js.map +1 -1
- package/dist/react18/replace-reactdom-render.d.ts.map +1 -1
- package/dist/react18/replace-reactdom-render.js +1 -1
- package/dist/react18/replace-reactdom-render.js.map +1 -1
- package/dist/react18/replace-render-callback.d.ts.map +1 -1
- package/dist/react18/replace-render-callback.js +3 -12
- package/dist/react18/replace-render-callback.js.map +1 -1
- package/dist/react18/replace-unmount-component-at-node.d.ts.map +1 -1
- package/dist/react18/replace-unmount-component-at-node.js +1 -1
- package/dist/react18/replace-unmount-component-at-node.js.map +1 -1
- package/dist/react19/find-context-consumer.d.ts.map +1 -1
- package/dist/react19/find-context-consumer.js.map +1 -1
- package/dist/react19/find-deprecated-reactdom-apis.d.ts.map +1 -1
- package/dist/react19/find-deprecated-reactdom-apis.js +16 -61
- package/dist/react19/find-deprecated-reactdom-apis.js.map +1 -1
- package/dist/react19/find-element-ref.d.ts.map +1 -1
- package/dist/react19/find-element-ref.js.map +1 -1
- package/dist/react19/find-legacy-context-api.d.ts.map +1 -1
- package/dist/react19/find-legacy-context-api.js.map +1 -1
- package/dist/react19/no-implicit-ref-callback-return.d.ts.map +1 -1
- package/dist/react19/no-implicit-ref-callback-return.js +1 -1
- package/dist/react19/no-implicit-ref-callback-return.js.map +1 -1
- package/dist/react19/remove-context-provider.d.ts.map +1 -1
- package/dist/react19/remove-context-provider.js +1 -7
- package/dist/react19/remove-context-provider.js.map +1 -1
- package/dist/react19/remove-forward-ref.d.ts.map +1 -1
- package/dist/react19/remove-forward-ref.js +2 -2
- package/dist/react19/remove-forward-ref.js.map +1 -1
- package/dist/react19/remove-prop-types.d.ts.map +1 -1
- package/dist/react19/remove-prop-types.js.map +1 -1
- package/dist/react19/remove-react-fc.js +2 -2
- package/dist/react19/remove-react-fc.js.map +1 -1
- package/dist/react19/remove-unstable-batched-updates.d.ts +1 -1
- package/dist/react19/remove-unstable-batched-updates.d.ts.map +1 -1
- package/dist/react19/remove-unstable-batched-updates.js +9 -88
- package/dist/react19/remove-unstable-batched-updates.js.map +1 -1
- package/dist/{react16 → react19}/replace-create-factory.d.ts +1 -1
- package/dist/react19/replace-create-factory.d.ts.map +1 -0
- package/dist/{react16 → react19}/replace-create-factory.js +5 -5
- package/dist/react19/replace-create-factory.js.map +1 -0
- package/dist/react19/replace-reactdom-hydrate.d.ts.map +1 -1
- package/dist/react19/replace-reactdom-hydrate.js +1 -1
- package/dist/react19/replace-reactdom-hydrate.js.map +1 -1
- package/dist/react19/replace-string-ref.d.ts.map +1 -1
- package/dist/react19/replace-string-ref.js.map +1 -1
- package/dist/react19/scoped-jsx-namespace.d.ts.map +1 -1
- package/dist/react19/scoped-jsx-namespace.js +2 -6
- package/dist/react19/scoped-jsx-namespace.js.map +1 -1
- package/dist/react19/use-context-hook.d.ts.map +1 -1
- package/dist/react19/use-context-hook.js +1 -1
- package/dist/react19/use-context-hook.js.map +1 -1
- package/dist/react19/use-ref-required-initial.d.ts.map +1 -1
- package/dist/react19/use-ref-required-initial.js +3 -1
- package/dist/react19/use-ref-required-initial.js.map +1 -1
- package/dist/refactoring/class-to-functional.d.ts.map +1 -1
- package/dist/refactoring/class-to-functional.js +7 -3
- package/dist/refactoring/class-to-functional.js.map +1 -1
- package/dist/refactoring/create-class-to-es6.d.ts.map +1 -1
- package/dist/refactoring/create-class-to-es6.js +1 -1
- package/dist/refactoring/create-class-to-es6.js.map +1 -1
- package/dist/refactoring/create-element-to-jsx.d.ts.map +1 -1
- package/dist/refactoring/create-element-to-jsx.js +5 -7
- package/dist/refactoring/create-element-to-jsx.js.map +1 -1
- package/dist/refactoring/fix-async-effect.d.ts.map +1 -1
- package/dist/refactoring/fix-async-effect.js.map +1 -1
- package/dist/refactoring/manual-bind-to-arrow.d.ts.map +1 -1
- package/dist/refactoring/manual-bind-to-arrow.js.map +1 -1
- package/dist/refactoring/prop-types-to-typescript.d.ts +1 -1
- package/dist/refactoring/prop-types-to-typescript.d.ts.map +1 -1
- package/dist/refactoring/prop-types-to-typescript.js +2 -2
- package/dist/refactoring/prop-types-to-typescript.js.map +1 -1
- package/dist/refactoring/pure-render-mixin.d.ts.map +1 -1
- package/dist/refactoring/pure-render-mixin.js +2 -8
- package/dist/refactoring/pure-render-mixin.js.map +1 -1
- package/dist/refactoring/sort-comp.d.ts.map +1 -1
- package/dist/refactoring/sort-comp.js +1 -1
- package/dist/refactoring/sort-comp.js.map +1 -1
- package/dist/search/find-deprecated-lifecycles.d.ts +1 -1
- package/dist/search/find-deprecated-lifecycles.d.ts.map +1 -1
- package/dist/search/find-deprecated-lifecycles.js +2 -2
- package/dist/search/find-deprecated-lifecycles.js.map +1 -1
- package/dist/search/find-effects-without-cleanup.d.ts +1 -1
- package/dist/search/find-effects-without-cleanup.d.ts.map +1 -1
- package/dist/search/find-effects-without-cleanup.js +7 -9
- package/dist/search/find-effects-without-cleanup.js.map +1 -1
- package/dist/search/find-enzyme-usage.d.ts.map +1 -1
- package/dist/search/find-enzyme-usage.js.map +1 -1
- package/dist/search/find-function-component-default-props.d.ts +1 -1
- package/dist/search/find-function-component-default-props.d.ts.map +1 -1
- package/dist/search/find-function-component-default-props.js +2 -2
- package/dist/search/find-function-component-default-props.js.map +1 -1
- package/dist/search/find-hard-coded-strings.d.ts.map +1 -1
- package/dist/search/find-hard-coded-strings.js.map +1 -1
- package/dist/search/find-hook-usage.d.ts.map +1 -1
- package/dist/search/find-hook-usage.js.map +1 -1
- package/dist/search/find-legacy-react-apis.d.ts +1 -1
- package/dist/search/find-legacy-react-apis.d.ts.map +1 -1
- package/dist/search/find-legacy-react-apis.js +1 -1
- package/dist/search/find-legacy-react-apis.js.map +1 -1
- package/dist/search/find-missing-use-client-directive.d.ts.map +1 -1
- package/dist/search/find-missing-use-client-directive.js +11 -10
- package/dist/search/find-missing-use-client-directive.js.map +1 -1
- package/dist/search/find-prop-usage.d.ts.map +1 -1
- package/dist/search/find-prop-usage.js.map +1 -1
- package/dist/search/find-react-component.d.ts.map +1 -1
- package/dist/search/find-react-component.js.map +1 -1
- package/dist/search/find-reactdom-root-apis.d.ts.map +1 -1
- package/dist/search/find-reactdom-root-apis.js +2 -42
- package/dist/search/find-reactdom-root-apis.js.map +1 -1
- package/dist/search/find-redux-stores.d.ts +1 -1
- package/dist/search/find-redux-stores.d.ts.map +1 -1
- package/dist/search/find-redux-stores.js +1 -1
- package/dist/search/find-redux-stores.js.map +1 -1
- package/dist/search/find-server-rendering-usage.d.ts.map +1 -1
- package/dist/search/find-server-rendering-usage.js +13 -54
- package/dist/search/find-server-rendering-usage.js.map +1 -1
- package/dist/simplify-object-pattern-property.d.ts.map +1 -1
- package/dist/simplify-object-pattern-property.js.map +1 -1
- package/dist/simplify-react-imports.d.ts.map +1 -1
- package/dist/simplify-react-imports.js +1 -1
- package/dist/simplify-react-imports.js.map +1 -1
- package/dist/testing/enzyme-host-components.d.ts.map +1 -1
- package/dist/testing/enzyme-host-components.js +2 -2
- package/dist/testing/enzyme-host-components.js.map +1 -1
- package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
- package/dist/testing/enzyme-to-react-testing-library.js +11 -19
- package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
- package/dist/testing/enzyme-usage.js +2 -2
- package/dist/testing/enzyme-usage.js.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.js +5 -12
- package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
- package/dist/util/react-class.d.ts +2 -0
- package/dist/util/react-class.d.ts.map +1 -1
- package/dist/util/react-class.js +14 -0
- package/dist/util/react-class.js.map +1 -1
- package/dist/util/react-matchers.d.ts +8 -0
- package/dist/util/react-matchers.d.ts.map +1 -0
- package/dist/util/react-matchers.js +25 -0
- package/dist/util/react-matchers.js.map +1 -0
- package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
- package/dist/zustand/redux-to-zustand.js +20 -20
- package/dist/zustand/redux-to-zustand.js.map +1 -1
- package/package.json +2 -2
- package/src/i18n/translate-hard-coded-strings.ts +5 -12
- package/src/index.ts +3 -12
- package/src/migration/change-component-prop-value.ts +0 -40
- package/src/migration/cra-to-vite/add-vite-config.ts +0 -10
- package/src/migration/cra-to-vite/cra-to-vite.ts +0 -3
- package/src/migration/cra-to-vite/find-cra-config-blockers.ts +2 -7
- package/src/migration/cra-to-vite/find-cra-env-file-blockers.ts +0 -7
- package/src/migration/cra-to-vite/find-cra-source-blockers.ts +0 -9
- package/src/migration/cra-to-vite/find-cra-to-vite-blockers.ts +0 -4
- package/src/migration/cra-to-vite/migrate-cra-package.ts +0 -1
- package/src/migration/cra-to-vite/migrate-cra-svg-imports.ts +3 -4
- package/src/migration/cra-to-vite/migrate-cra-tests-to-vitest.ts +1 -3
- package/src/migration/cra-to-vite/move-public-index-html.ts +1 -13
- package/src/migration/cra-to-vite/remove-cra-configuration.ts +0 -1
- package/src/migration/cra-to-vite/rename-jsx-files.ts +0 -4
- package/src/migration/cra-to-vite/rename-process-env-react-app.ts +1 -17
- package/src/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.ts +1 -11
- package/src/migration/cra-to-vite/replace-react-scripts-dependency.ts +1 -12
- package/src/migration/cra-to-vite/update-react-app-env-types.ts +0 -9
- package/src/migration/cra-to-vite/update-react-scripts-scripts.ts +0 -15
- package/src/migration/cra-to-vite/update-tsconfig-for-vite.ts +0 -11
- package/src/mui/adapt-v4-theme.ts +2 -7
- package/src/mui/add-component-prop.ts +0 -7
- package/src/mui/add-emotion-prepend.ts +5 -17
- package/src/mui/convert-mui-imports.ts +1 -12
- package/src/mui/convert-prop-to-sx.ts +1 -9
- package/src/mui/mark-manual-migration.ts +0 -6
- package/src/mui/mark-palette-mode-usage.ts +0 -6
- package/src/mui/move-component-prop-to-slot.ts +0 -9
- package/src/mui/move-primary-text-to-children.ts +0 -5
- package/src/mui/move-system-props-to-sx.ts +1 -11
- package/src/mui/remove-component-prop.ts +0 -5
- package/src/mui/remove-root-ref.ts +2 -8
- package/src/mui/remove-spacing-px-suffix.ts +3 -11
- package/src/mui/rename-component-prop.ts +0 -7
- package/src/mui/rename-joy-css-variables.ts +0 -6
- package/src/mui/rename-theme-palette-type.ts +0 -5
- package/src/mui/replace-box-border-radius.ts +0 -5
- package/src/mui/replace-breakpoints-width.ts +0 -2
- package/src/mui/replace-component-class.ts +0 -10
- package/src/mui/replace-components-with-slots.ts +0 -8
- package/src/mui/replace-import-paths.ts +0 -11
- package/src/mui/replace-in-string-literals.ts +0 -7
- package/src/mui/replace-list-item-button-prop.ts +3 -10
- package/src/mui/replace-tabs-scroll-buttons.ts +0 -5
- package/src/mui/replace-theme-color-functions.ts +9 -26
- package/src/mui/replace-theme-spacing-unit.ts +0 -6
- package/src/mui/replace-typography-round.ts +0 -5
- package/src/mui/shift-hidden-down-props.ts +3 -12
- package/src/mui/update-theme-breakpoints.ts +0 -8
- package/src/mui/upgrade-grid-props.ts +1 -9
- package/src/react-native/view-prop-types.ts +4 -26
- package/src/react16/error-boundaries.ts +1 -20
- package/src/react16/find-dom-node.ts +0 -17
- package/src/react16/react-dom-factories.ts +0 -14
- package/src/react16/react-prop-types.ts +4 -29
- package/src/react16/react-to-react-dom.ts +3 -20
- package/src/react17/migrate-deprecated-lifecycles.ts +6 -21
- package/src/react17/remove-event-persist.ts +157 -92
- package/src/react17/rename-unsafe-lifecycles.ts +1 -24
- package/src/react17/update-react-imports.ts +2 -27
- package/src/react17/use-new-jsx-transform.ts +2 -15
- package/src/react18/add-children-to-props.ts +2 -2
- package/src/react18/replace-reactdom-render.ts +2 -24
- package/src/react18/replace-render-callback.ts +5 -31
- package/src/react18/replace-unmount-component-at-node.ts +2 -22
- package/src/react19/find-context-consumer.ts +0 -23
- package/src/react19/find-deprecated-reactdom-apis.ts +20 -80
- package/src/react19/find-element-ref.ts +0 -15
- package/src/react19/find-legacy-context-api.ts +0 -12
- package/src/react19/no-implicit-ref-callback-return.ts +1 -19
- package/src/react19/remove-context-provider.ts +1 -25
- package/src/react19/remove-forward-ref.ts +3 -18
- package/src/react19/remove-prop-types.ts +0 -24
- package/src/react19/remove-react-fc.ts +3 -3
- package/src/react19/remove-unstable-batched-updates.ts +15 -129
- package/src/{react16 → react19}/replace-create-factory.ts +8 -21
- package/src/react19/replace-reactdom-hydrate.ts +2 -19
- package/src/react19/replace-string-ref.ts +0 -14
- package/src/react19/scoped-jsx-namespace.ts +3 -7
- package/src/react19/use-context-hook.ts +2 -20
- package/src/react19/use-ref-required-initial.ts +4 -17
- package/src/refactoring/class-to-functional.ts +9 -33
- package/src/refactoring/create-class-to-es6.ts +1 -15
- package/src/refactoring/create-element-to-jsx.ts +7 -31
- package/src/refactoring/fix-async-effect.ts +0 -28
- package/src/refactoring/manual-bind-to-arrow.ts +0 -23
- package/src/refactoring/prop-types-to-typescript.ts +3 -34
- package/src/refactoring/pure-render-mixin.ts +3 -30
- package/src/refactoring/sort-comp.ts +1 -11
- package/src/search/find-deprecated-lifecycles.ts +3 -6
- package/src/search/find-effects-without-cleanup.ts +5 -15
- package/src/search/find-enzyme-usage.ts +0 -3
- package/src/search/find-function-component-default-props.ts +3 -7
- package/src/search/find-hard-coded-strings.ts +0 -9
- package/src/search/find-hook-usage.ts +0 -10
- package/src/search/find-legacy-react-apis.ts +1 -18
- package/src/search/find-missing-use-client-directive.ts +13 -19
- package/src/search/find-prop-usage.ts +0 -11
- package/src/search/find-react-component.ts +0 -11
- package/src/search/find-reactdom-root-apis.ts +5 -44
- package/src/search/find-redux-stores.ts +1 -9
- package/src/search/find-server-rendering-usage.ts +15 -72
- package/src/simplify-object-pattern-property.ts +0 -8
- package/src/simplify-react-imports.ts +3 -23
- package/src/testing/enzyme-host-components.ts +3 -2
- package/src/testing/enzyme-to-react-testing-library.ts +10 -50
- package/src/testing/enzyme-usage.ts +2 -2
- package/src/testing/enzyme-wrapper-scope.ts +7 -15
- package/src/util/react-class.ts +17 -1
- package/src/util/react-matchers.ts +34 -0
- package/src/zustand/redux-to-zustand.ts +21 -75
- package/dist/react16/replace-create-factory.d.ts.map +0 -1
- package/dist/react16/replace-create-factory.js.map +0 -1
- package/dist/react19/replace-act-import.d.ts +0 -9
- package/dist/react19/replace-act-import.d.ts.map +0 -1
- package/dist/react19/replace-act-import.js +0 -34
- package/dist/react19/replace-act-import.js.map +0 -1
- package/dist/react19/replace-react-shallow-renderer.d.ts +0 -8
- package/dist/react19/replace-react-shallow-renderer.d.ts.map +0 -1
- package/dist/react19/replace-react-shallow-renderer.js +0 -49
- package/dist/react19/replace-react-shallow-renderer.js.map +0 -1
- package/dist/react19/replace-use-form-state.d.ts +0 -8
- package/dist/react19/replace-use-form-state.d.ts.map +0 -1
- package/dist/react19/replace-use-form-state.js +0 -57
- package/dist/react19/replace-use-form-state.js.map +0 -1
- package/src/react19/replace-act-import.ts +0 -36
- package/src/react19/replace-react-shallow-renderer.ts +0 -47
- package/src/react19/replace-use-form-state.ts +0 -69
|
@@ -1,120 +1,185 @@
|
|
|
1
|
-
import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import {Cursor, ExecutionContext, Recipe, Tree, TreeVisitor, check, not} from "@openrewrite/rewrite";
|
|
2
|
+
import {
|
|
3
|
+
JavaScriptVisitor, JS, JSX, MethodMatcher, Reference, compilationUnitOf, identifierOf, isVendoredOrBundled,
|
|
4
|
+
moduleNameOf, present, referencesOf, resolve, walk
|
|
5
|
+
} from "@openrewrite/rewrite/javascript";
|
|
6
|
+
import {J, Type} from "@openrewrite/rewrite/java";
|
|
4
7
|
import {create} from "mutative";
|
|
5
8
|
|
|
9
|
+
const REACT = "react";
|
|
10
|
+
// `@types/react` declares `persist()` on `BaseSyntheticEvent` since 16.7.18, and on `SyntheticEvent` before
|
|
11
|
+
const SYNTHETIC_EVENT_PERSIST = [
|
|
12
|
+
new MethodMatcher("React.BaseSyntheticEvent persist()"),
|
|
13
|
+
new MethodMatcher("React.SyntheticEvent persist()")
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
/** The module an `import` or a `require(...)` call names, as written. */
|
|
17
|
+
function requestedModule(n: Tree): J | undefined {
|
|
18
|
+
if (n.kind === JS.Kind.Import) return (n as JS.Import).moduleSpecifier?.element;
|
|
19
|
+
if (n.kind !== J.Kind.MethodInvocation) return undefined;
|
|
20
|
+
const call = n as J.MethodInvocation;
|
|
21
|
+
return !call.select && call.name.simpleName === "require" ? call.arguments.elements[0]?.element : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Whether the file imports or requires `react`, in any form: default, namespace, named or type-only. */
|
|
25
|
+
function importsReact(cu: JS.CompilationUnit): boolean {
|
|
26
|
+
let found = false;
|
|
27
|
+
walk(cu, n => {
|
|
28
|
+
const module = requestedModule(n);
|
|
29
|
+
found ||= module?.kind === J.Kind.Literal && moduleNameOf(module as J.Literal) === REACT;
|
|
30
|
+
return !found;
|
|
31
|
+
});
|
|
32
|
+
return found;
|
|
33
|
+
}
|
|
34
|
+
|
|
6
35
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
* Whether `receiver` reads a parameter of an event handler, the way a handler reads its event: a parameter named
|
|
37
|
+
* outright, not one destructured from an argument, not shadowed by a local of the same name, and neither
|
|
38
|
+
* assigned to nor redeclared with `var`, either of which can make it hold something else. A parameter
|
|
39
|
+
* annotated with a type has to name an event type, or `any`, since `persistor: Persistor` is no event.
|
|
40
|
+
* Being a parameter is not enough, since `stores.forEach(store => store.persist())` passes no event: the
|
|
41
|
+
* parameter also has to be annotated with an event type, belong to a function passed to a JSX `on*` prop, or
|
|
42
|
+
* be read as an event is, as `e.target` or `e.preventDefault()` read it. What the function is named says
|
|
43
|
+
* nothing, since `onStoreReady(store)` takes no event.
|
|
44
|
+
*/
|
|
45
|
+
function readsParameter(cursor: Cursor, receiver: J.Identifier): boolean {
|
|
46
|
+
const name = receiver.simpleName;
|
|
47
|
+
const fn = resolve(cursor, receiver);
|
|
48
|
+
const parameter = parametersOf(fn).map(p => p.element).find(p => identifierOf(p)?.simpleName === name);
|
|
49
|
+
const annotation = parameter?.kind === J.Kind.VariableDeclarations ? (parameter as J.VariableDeclarations).typeExpression : undefined;
|
|
50
|
+
if (parameter === undefined || (annotation && !namesEventType(annotation))) return false;
|
|
51
|
+
const references = referencesOf(cursor, name);
|
|
52
|
+
return references.filter(r => r.declares || r.writes).length === 1 &&
|
|
53
|
+
(annotation !== undefined && !namesAny(annotation) || isJsxEventProp(cursor, fn!) || readsEventMember(references));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Members of a synthetic event, and of a DOM event, that little else has
|
|
57
|
+
const EVENT_MEMBERS = new Set([
|
|
58
|
+
"target", "currentTarget", "nativeEvent", "preventDefault", "stopPropagation", "isDefaultPrevented",
|
|
59
|
+
"isPropagationStopped"
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
/** Whether a reference reads a member only an event is likely to have, as `e.target` or `e.preventDefault()` do. */
|
|
63
|
+
function readsEventMember(references: Reference[]): boolean {
|
|
64
|
+
return references.some(r => {
|
|
65
|
+
if (r.declares) return false;
|
|
66
|
+
const parent = r.cursor.parentTree()?.value as J | undefined;
|
|
67
|
+
switch (parent?.kind) {
|
|
68
|
+
case J.Kind.FieldAccess:
|
|
69
|
+
return EVENT_MEMBERS.has((parent as J.FieldAccess).name.element.simpleName);
|
|
70
|
+
case J.Kind.MethodInvocation:
|
|
71
|
+
return (parent as J.MethodInvocation).select?.element === r.identifier && EVENT_MEMBERS.has((parent as J.MethodInvocation).name.simpleName);
|
|
72
|
+
default:
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Whether `fn` is passed straight to a JSX `on*` prop, as `onChange={e => …}` passes it. */
|
|
79
|
+
function isJsxEventProp(cursor: Cursor, fn: J): boolean {
|
|
80
|
+
let at: Cursor | undefined = cursor;
|
|
81
|
+
while (at && at.value !== fn) at = at.parent;
|
|
82
|
+
for (let parent = at?.parentTree(); parent; parent = parent.parentTree()) {
|
|
83
|
+
const node = parent.value as J;
|
|
84
|
+
if (node.kind === JS.Kind.JsxEmbeddedExpression || node.kind === J.Kind.Parentheses) continue;
|
|
85
|
+
if (node.kind !== JS.Kind.JsxAttribute) return false;
|
|
86
|
+
const key = (node as JSX.Attribute).key;
|
|
87
|
+
return key.kind === J.Kind.Identifier && /^on[A-Z]/.test(key.simpleName);
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Whether a type annotation is `any`, which says nothing of what the parameter holds. */
|
|
93
|
+
function namesAny(type: J): boolean {
|
|
94
|
+
const typeIdentifier = type.kind === JS.Kind.TypeInfo ? (type as JS.TypeInfo).typeIdentifier : type;
|
|
95
|
+
return typeIdentifier.kind === J.Kind.Identifier && (typeIdentifier as J.Identifier).simpleName === "any";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Whether a type annotation names an event type, such as `React.ChangeEvent<T>`, or `any`, in any member of a union. */
|
|
99
|
+
function namesEventType(type: J): boolean {
|
|
100
|
+
switch (type.kind) {
|
|
101
|
+
case JS.Kind.TypeInfo:
|
|
102
|
+
return namesEventType((type as JS.TypeInfo).typeIdentifier);
|
|
103
|
+
case JS.Kind.Union:
|
|
104
|
+
return (type as JS.Union).types.some(t => namesEventType(t.element));
|
|
105
|
+
case J.Kind.ParameterizedType:
|
|
106
|
+
return namesEventType((type as J.ParameterizedType).class);
|
|
107
|
+
case J.Kind.FieldAccess:
|
|
108
|
+
return namesEventType((type as J.FieldAccess).name.element);
|
|
109
|
+
case J.Kind.Identifier: {
|
|
110
|
+
const simpleName = (type as J.Identifier).simpleName;
|
|
111
|
+
return simpleName === "any" || simpleName.endsWith("Event");
|
|
112
|
+
}
|
|
113
|
+
default:
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function parametersOf(fn: J | undefined): J.RightPadded<J>[] {
|
|
119
|
+
switch (fn?.kind) {
|
|
120
|
+
case J.Kind.MethodDeclaration:
|
|
121
|
+
case JS.Kind.ComputedPropertyMethodDeclaration:
|
|
122
|
+
return (fn as J.MethodDeclaration | JS.ComputedPropertyMethodDeclaration).parameters.elements;
|
|
123
|
+
case JS.Kind.ArrowFunction:
|
|
124
|
+
return (fn as JS.ArrowFunction).lambda.parameters.parameters;
|
|
125
|
+
case J.Kind.Lambda:
|
|
126
|
+
return (fn as J.Lambda).parameters.parameters;
|
|
127
|
+
default:
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Without types, an event handler is recognised by its file's `react` import, so composites run this before
|
|
134
|
+
* `UpdateReactImports`, which can remove that import.
|
|
26
135
|
*
|
|
27
136
|
* @see https://legacy.reactjs.org/blog/2020/08/10/react-v17-rc.html#no-event-pooling
|
|
28
137
|
*/
|
|
29
138
|
export class RemoveEventPersist extends Recipe {
|
|
30
139
|
readonly name = "org.openrewrite.react.17.remove-event-persist";
|
|
31
140
|
readonly displayName: string = "Remove `event.persist()` calls";
|
|
32
|
-
readonly description: string = "Removes `
|
|
141
|
+
readonly description: string = "Removes `persist()` calls on React synthetic events, which do nothing since React 17 removed event pooling. Without type attribution, only a call on an event handler's parameter in a file that imports `react` is removed.";
|
|
33
142
|
|
|
34
143
|
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
35
144
|
return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
|
|
36
|
-
|
|
37
|
-
let result = await super.visitJsCompilationUnit(cu, ctx) as JS.CompilationUnit;
|
|
38
|
-
|
|
39
|
-
const statementsToRemove = new Set<string>();
|
|
40
|
-
|
|
41
|
-
for (const stmt of result.statements) {
|
|
42
|
-
const s = stmt.element;
|
|
43
|
-
if (!s) continue;
|
|
44
|
-
if (this.isPersistCall(s)) {
|
|
45
|
-
statementsToRemove.add((s as any).id);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (statementsToRemove.size === 0) return result;
|
|
145
|
+
private reactImported?: boolean;
|
|
50
146
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
return create(result, draft => {
|
|
57
|
-
draft.statements = filteredStatements as any;
|
|
58
|
-
});
|
|
147
|
+
override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
|
|
148
|
+
this.reactImported = undefined;
|
|
149
|
+
return this.withoutPersistCalls(await super.visitJsCompilationUnit(cu, ctx) as JS.CompilationUnit);
|
|
59
150
|
}
|
|
60
151
|
|
|
61
152
|
override async visitBlock(block: J.Block, ctx: ExecutionContext): Promise<J | undefined> {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const statementsToRemove = new Set<string>();
|
|
65
|
-
|
|
66
|
-
for (const stmt of b.statements) {
|
|
67
|
-
const s = stmt.element;
|
|
68
|
-
if (!s) continue;
|
|
69
|
-
if (this.isPersistCall(s)) {
|
|
70
|
-
statementsToRemove.add((s as any).id);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (statementsToRemove.size === 0) return b;
|
|
75
|
-
|
|
76
|
-
const filteredStatements = b.statements.filter(stmt => {
|
|
77
|
-
const s = stmt.element;
|
|
78
|
-
return !s || !statementsToRemove.has((s as any).id);
|
|
79
|
-
});
|
|
153
|
+
return this.withoutPersistCalls(await super.visitBlock(block, ctx) as J.Block);
|
|
154
|
+
}
|
|
80
155
|
|
|
81
|
-
|
|
82
|
-
|
|
156
|
+
private withoutPersistCalls<T extends JS.CompilationUnit | J.Block>(node: T): T {
|
|
157
|
+
const statements = node.statements.filter(stmt => !stmt.element || !this.isPersistCall(stmt.element));
|
|
158
|
+
if (statements.length === node.statements.length) return node;
|
|
159
|
+
return create(node, draft => {
|
|
160
|
+
draft.statements = statements as any;
|
|
83
161
|
});
|
|
84
162
|
}
|
|
85
163
|
|
|
86
|
-
private isPersistCall(stmt:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (stmt.kind === JS.Kind.ExpressionStatement) {
|
|
90
|
-
expr = (stmt as JS.ExpressionStatement).expression;
|
|
91
|
-
} else if (stmt.kind === J.Kind.MethodInvocation) {
|
|
92
|
-
expr = stmt;
|
|
93
|
-
} else {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!expr || expr.kind !== J.Kind.MethodInvocation) return false;
|
|
164
|
+
private isPersistCall(stmt: J): boolean {
|
|
165
|
+
const expr = stmt.kind === JS.Kind.ExpressionStatement ? (stmt as JS.ExpressionStatement).expression : stmt;
|
|
166
|
+
if (expr?.kind !== J.Kind.MethodInvocation) return false;
|
|
98
167
|
|
|
99
168
|
const method = expr as J.MethodInvocation;
|
|
100
169
|
|
|
101
|
-
|
|
102
|
-
if (!method.select) return false;
|
|
170
|
+
if (!method.select || method.name.simpleName !== 'persist' || present(method.arguments.elements).length > 0) return false;
|
|
103
171
|
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
// Must have no real arguments (may contain J.Empty placeholder)
|
|
108
|
-
if (method.arguments) {
|
|
109
|
-
const args = method.arguments.elements;
|
|
110
|
-
const hasRealArgs = args.some((el: any) => {
|
|
111
|
-
const element = el.element ?? el;
|
|
112
|
-
return element.kind !== J.Kind.Empty;
|
|
113
|
-
});
|
|
114
|
-
if (hasRealArgs) return false;
|
|
172
|
+
const declaringType = method.methodType?.declaringType;
|
|
173
|
+
if (declaringType && declaringType.kind !== Type.Kind.Unknown) {
|
|
174
|
+
return SYNTHETIC_EVENT_PERSIST.some(matcher => matcher.matches(method.methodType));
|
|
115
175
|
}
|
|
116
|
-
|
|
117
|
-
|
|
176
|
+
// Without types, a parameter is only taken for an event in a file that uses React
|
|
177
|
+
const receiver = method.select.element;
|
|
178
|
+
// `resolve` takes a cursor on the call, under the statement that holds it
|
|
179
|
+
const statement = new Cursor(stmt, this.cursor);
|
|
180
|
+
return receiver.kind === J.Kind.Identifier &&
|
|
181
|
+
(this.reactImported ??= importsReact(compilationUnitOf(this)!)) &&
|
|
182
|
+
readsParameter(stmt === method ? statement : new Cursor(method, statement), receiver as J.Identifier);
|
|
118
183
|
}
|
|
119
184
|
}());
|
|
120
185
|
}
|
|
@@ -9,35 +9,12 @@ const UNSAFE_LIFECYCLE_MAP = new Map<string, string>([
|
|
|
9
9
|
]);
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Adds `UNSAFE_` prefix to deprecated lifecycle methods.
|
|
13
|
-
*
|
|
14
|
-
* React 16.3 deprecated `componentWillMount`, `componentWillReceiveProps`,
|
|
15
|
-
* and `componentWillUpdate`. React 17 requires the UNSAFE_ prefix.
|
|
16
|
-
*
|
|
17
|
-
* Before:
|
|
18
|
-
* ```tsx
|
|
19
|
-
* class MyComponent extends React.Component {
|
|
20
|
-
* componentWillMount() { ... }
|
|
21
|
-
* componentWillReceiveProps(nextProps) { ... }
|
|
22
|
-
* componentWillUpdate(nextProps, nextState) { ... }
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* After:
|
|
27
|
-
* ```tsx
|
|
28
|
-
* class MyComponent extends React.Component {
|
|
29
|
-
* UNSAFE_componentWillMount() { ... }
|
|
30
|
-
* UNSAFE_componentWillReceiveProps(nextProps) { ... }
|
|
31
|
-
* UNSAFE_componentWillUpdate(nextProps, nextState) { ... }
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
12
|
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html
|
|
36
13
|
*/
|
|
37
14
|
export class RenameUnsafeLifecycles extends Recipe {
|
|
38
15
|
readonly name = "org.openrewrite.react.17.rename-unsafe-lifecycles";
|
|
39
16
|
readonly displayName: string = "Add `UNSAFE_` prefix to deprecated lifecycle methods";
|
|
40
|
-
readonly description: string = "Renames `componentWillMount`, `componentWillReceiveProps`, and `componentWillUpdate` to their UNSAFE_ prefixed versions.";
|
|
17
|
+
readonly description: string = "Renames `componentWillMount`, `componentWillReceiveProps`, and `componentWillUpdate` to their `UNSAFE_` prefixed versions.";
|
|
41
18
|
|
|
42
19
|
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
43
20
|
return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
|
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
import {ExecutionContext, Option, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
|
|
2
|
-
import {JavaScriptVisitor, JS, JSX,
|
|
2
|
+
import {JavaScriptVisitor, JS, JSX, maybeUnbind, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
|
|
3
3
|
import {J} from "@openrewrite/rewrite/java";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Removes unnecessary `import React from 'react'` default imports.
|
|
7
|
-
*
|
|
8
|
-
* With React 17's new JSX transform, you no longer need to import React
|
|
9
|
-
* in every file that uses JSX. When automaticJsxRuntime is explicitly enabled, this recipe removes the default React
|
|
10
|
-
* import when it's only used for JSX (not for React.xxx API calls).
|
|
11
|
-
*
|
|
12
|
-
* Before:
|
|
13
|
-
* ```tsx
|
|
14
|
-
* import React from 'react';
|
|
15
|
-
*
|
|
16
|
-
* function App() {
|
|
17
|
-
* return <div>Hello</div>;
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* After:
|
|
22
|
-
* ```tsx
|
|
23
|
-
* function App() {
|
|
24
|
-
* return <div>Hello</div>;
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* Note: If `React` is used for API calls (e.g., `React.createElement`,
|
|
29
|
-
* `React.useRef`), the import is preserved.
|
|
30
|
-
*
|
|
31
6
|
* @see https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
|
|
32
7
|
*/
|
|
33
8
|
export class UpdateReactImports extends Recipe {
|
|
@@ -56,7 +31,7 @@ export class UpdateReactImports extends Recipe {
|
|
|
56
31
|
const result = await super.visitJsCompilationUnit(cu, ctx);
|
|
57
32
|
// React's version does not determine which JSX transform the project uses.
|
|
58
33
|
if (automaticJsxRuntime || !this.containsJsx) {
|
|
59
|
-
|
|
34
|
+
maybeUnbind(this, {module: "react", member: "default"});
|
|
60
35
|
}
|
|
61
36
|
return result;
|
|
62
37
|
}
|
|
@@ -47,26 +47,13 @@ function turnRuleOff(value: Json.Value): Json.Value {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* Moves JSX configuration to the new JSX transform introduced with React 17 (and backported
|
|
51
|
-
* to 16.14), which compiles JSX without `React` in scope.
|
|
52
|
-
*
|
|
53
|
-
* - `tsconfig.json`/`jsconfig.json`: `"jsx": "react"` becomes `"react-jsx"` and
|
|
54
|
-
* `"react-dev"` becomes `"react-jsxdev"`.
|
|
55
|
-
* It is skipped when `jsxFactory` or `jsxFragmentFactory` is set, which TypeScript rejects
|
|
56
|
-
* with `react-jsx` (TS5089).
|
|
57
|
-
* - Babel JSON config: `"runtime": "classic"` on `@babel/preset-react` becomes `"automatic"`,
|
|
58
|
-
* unless `pragma` or `pragmaFrag` is set, which the automatic runtime rejects.
|
|
59
|
-
* - ESLint JSON config: `react/react-in-jsx-scope` and `react/jsx-uses-react` are turned off.
|
|
60
|
-
*
|
|
61
|
-
* Only values that are explicitly configured are changed. Configuration that is absent, or
|
|
62
|
-
* written in JavaScript, is left alone.
|
|
63
|
-
*
|
|
64
50
|
* @see https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
|
|
65
51
|
*/
|
|
66
52
|
export class UseNewJsxTransform extends Recipe {
|
|
67
53
|
readonly name = "org.openrewrite.react.17.use-new-jsx-transform";
|
|
68
54
|
readonly displayName = "Use the new JSX transform";
|
|
69
|
-
readonly description = "
|
|
55
|
+
readonly description = "Switches `tsconfig.json`, `jsconfig.json`, Babel and ESLint JSON configuration to the new JSX transform introduced in React 17, so JSX no longer needs `React` in scope: `\"jsx\": \"react\"` becomes `\"react-jsx\"`, Babel's `\"runtime\": \"classic\"` becomes `\"automatic\"`, and `react/react-in-jsx-scope` and `react/jsx-uses-react` are turned off. " +
|
|
56
|
+
"Only values that are set explicitly in JSON are changed, and a `tsconfig.json` with `jsxFactory` or a Babel preset with `pragma`, which the new transform rejects, is left alone.";
|
|
70
57
|
|
|
71
58
|
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
72
59
|
return new class extends JsonVisitor<ExecutionContext> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ExecutionContext, Recipe, TreeVisitor, check, not, randomId} from "@openrewrite/rewrite";
|
|
2
|
-
import {isVendoredOrBundled, JavaScriptVisitor, JS,
|
|
2
|
+
import {isVendoredOrBundled, JavaScriptVisitor, JS, maybeBind, template} from "@openrewrite/rewrite/javascript";
|
|
3
3
|
import {J, Statement} from "@openrewrite/rewrite/java";
|
|
4
4
|
import {create} from "mutative";
|
|
5
5
|
import {baseTypeArguments, extendsReactComponentByName} from "../util/react-class";
|
|
@@ -178,7 +178,7 @@ export class AddChildrenToProps extends Recipe {
|
|
|
178
178
|
if (declares) return block;
|
|
179
179
|
|
|
180
180
|
// Import `ReactNode` and use the name the import ends up with, which differs when `ReactNode` is already taken locally.
|
|
181
|
-
this.reactNode ??=
|
|
181
|
+
this.reactNode ??= maybeBind(this, {module: 'react', member: 'ReactNode', onlyIfReferenced: false}) ?? 'ReactNode';
|
|
182
182
|
// `template` yields real, parsed members: the first carries the separator marker (`;`) and the second is `children`.
|
|
183
183
|
this.sample ??= await this.sampleMembers(block, this.reactNode);
|
|
184
184
|
if (statements.length === 0) return this.intoEmpty(block, this.sample.member);
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
isVendoredOrBundled,
|
|
6
6
|
JavaScriptVisitor,
|
|
7
7
|
JS,
|
|
8
|
-
|
|
8
|
+
maybeUnbind,
|
|
9
9
|
pattern,
|
|
10
10
|
raw,
|
|
11
11
|
rewrite,
|
|
@@ -21,28 +21,6 @@ const ONE_ROOT_PER_CONTAINER = `Create the root once per container and call \`ro
|
|
|
21
21
|
const RESULT_IS_USED = `\`root.render()\` returns \`void\`, not the component instance. See ${GUIDE}`;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Replaces `ReactDOM.render()` with `createRoot()` and `root.render()`.
|
|
25
|
-
*
|
|
26
|
-
* In React 18, `ReactDOM.render()` is deprecated in favor of `createRoot()` from `react-dom/client`.
|
|
27
|
-
* A root must be created once per container and reused for every render, so only a top-level
|
|
28
|
-
* statement that renders a container once is rewritten. A call inside a function (it may run again
|
|
29
|
-
* and would create a second root), a call whose result is used (`root.render()` returns `void`),
|
|
30
|
-
* a container rendered twice, and a file that already uses the name `root` are marked instead.
|
|
31
|
-
* Only the first container in a file is rewritten, as the next one would redeclare `root`.
|
|
32
|
-
*
|
|
33
|
-
* Before:
|
|
34
|
-
* ```tsx
|
|
35
|
-
* import ReactDOM from 'react-dom';
|
|
36
|
-
* ReactDOM.render(<App />, document.getElementById('root'));
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* After:
|
|
40
|
-
* ```tsx
|
|
41
|
-
* import { createRoot } from 'react-dom/client';
|
|
42
|
-
* const root = createRoot(document.getElementById('root'));
|
|
43
|
-
* root.render(<App />);
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
24
|
* @see https://react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis
|
|
47
25
|
*/
|
|
48
26
|
export class ReplaceReactDomRender extends Recipe {
|
|
@@ -104,7 +82,7 @@ export class ReplaceReactDomRender extends Recipe {
|
|
|
104
82
|
if (!result) {
|
|
105
83
|
return m;
|
|
106
84
|
}
|
|
107
|
-
|
|
85
|
+
maybeUnbind(this, {module: "react-dom", member: "render"});
|
|
108
86
|
this.rootNameTaken = true;
|
|
109
87
|
this.inlinedBlocks.add(result.id);
|
|
110
88
|
return result;
|
|
@@ -1,27 +1,12 @@
|
|
|
1
1
|
import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
|
|
2
2
|
import {JavaScriptVisitor, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
|
|
3
|
-
import {
|
|
3
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
4
4
|
import {create} from "mutative";
|
|
5
|
+
import {anyOf, typedOrNamedCall} from "../util/react-matchers";
|
|
6
|
+
|
|
7
|
+
const RENDER = typedOrNamedCall(anyOf("react-dom render(..)"), "ReactDOM", "render");
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
|
-
* Removes the third callback argument from `ReactDOM.render()` calls.
|
|
8
|
-
*
|
|
9
|
-
* In React 18, `ReactDOM.render()` is deprecated in favor of `createRoot()`,
|
|
10
|
-
* which does not support a callback argument. This recipe strips the callback
|
|
11
|
-
* to prepare code for the migration.
|
|
12
|
-
*
|
|
13
|
-
* Before:
|
|
14
|
-
* ```tsx
|
|
15
|
-
* ReactDOM.render(<App />, document.getElementById('root'), () => {
|
|
16
|
-
* console.log('rendered');
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* After:
|
|
21
|
-
* ```tsx
|
|
22
|
-
* ReactDOM.render(<App />, document.getElementById('root'));
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
10
|
* @see https://react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis
|
|
26
11
|
*/
|
|
27
12
|
export class ReplaceRenderCallback extends Recipe {
|
|
@@ -34,18 +19,7 @@ export class ReplaceRenderCallback extends Recipe {
|
|
|
34
19
|
override async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
35
20
|
let m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
|
|
36
21
|
|
|
37
|
-
if (m
|
|
38
|
-
|
|
39
|
-
// Check for ReactDOM.render (namespace call)
|
|
40
|
-
const isReactDomRender = (() => {
|
|
41
|
-
if (m.select) {
|
|
42
|
-
const select = (m.select as any).element ?? m.select;
|
|
43
|
-
return isIdentifier(select) && select.simpleName === 'ReactDOM';
|
|
44
|
-
}
|
|
45
|
-
return false;
|
|
46
|
-
})();
|
|
47
|
-
|
|
48
|
-
if (!isReactDomRender) return m;
|
|
22
|
+
if (!RENDER(m)) return m;
|
|
49
23
|
|
|
50
24
|
// Only transform when there are exactly 3 arguments (element, container, callback)
|
|
51
25
|
const args = m.arguments?.elements;
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
JavaScriptVisitor,
|
|
6
6
|
isVendoredOrBundled,
|
|
7
7
|
JS,
|
|
8
|
-
|
|
8
|
+
maybeUnbind,
|
|
9
9
|
namesReferencedWithin,
|
|
10
10
|
pattern,
|
|
11
11
|
raw,
|
|
@@ -20,26 +20,6 @@ const NO_ROOT_MESSAGE = `No \`root\` for this container is in scope. Call \`unmo
|
|
|
20
20
|
const VALUE_USED_MESSAGE = `The result of \`unmountComponentAtNode\` is used, but \`root.unmount()\` returns \`void\`: ${GUIDE}`;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Replaces `unmountComponentAtNode(container)` with `root.unmount()` when the
|
|
24
|
-
* `root` returned by `createRoot(container)` for the same container is in scope.
|
|
25
|
-
*
|
|
26
|
-
* `createRoot(container).unmount()` would unmount a new, empty root and leave the
|
|
27
|
-
* mounted tree alive, so without a root in scope the call is kept and marked.
|
|
28
|
-
* It is also kept and marked when its `boolean` result is used, because
|
|
29
|
-
* `unmount()` returns `void`.
|
|
30
|
-
*
|
|
31
|
-
* Before:
|
|
32
|
-
* ```tsx
|
|
33
|
-
* const root = createRoot(container);
|
|
34
|
-
* unmountComponentAtNode(container);
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* After:
|
|
38
|
-
* ```tsx
|
|
39
|
-
* const root = createRoot(container);
|
|
40
|
-
* root.unmount();
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
23
|
* @see https://react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis
|
|
44
24
|
*/
|
|
45
25
|
export class ReplaceUnmountComponentAtNode extends Recipe {
|
|
@@ -76,7 +56,7 @@ export class ReplaceUnmountComponentAtNode extends Recipe {
|
|
|
76
56
|
return foundSearchResult(m, NO_ROOT_MESSAGE);
|
|
77
57
|
}
|
|
78
58
|
|
|
79
|
-
|
|
59
|
+
maybeUnbind(this, {module: "react-dom", member: "unmountComponentAtNode"});
|
|
80
60
|
return await template`${raw(root)}.unmount()`.apply(m, this.cursor);
|
|
81
61
|
}
|
|
82
62
|
|
|
@@ -14,29 +14,6 @@ class ContextConsumerRow {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Finds usage of the deprecated `<Context.Consumer>` pattern.
|
|
18
|
-
*
|
|
19
|
-
* In React 19, `Context.Consumer` is deprecated in favor of the
|
|
20
|
-
* `use()` hook for reading context in function components.
|
|
21
|
-
*
|
|
22
|
-
* Detects:
|
|
23
|
-
* - `<ThemeContext.Consumer>` JSX elements
|
|
24
|
-
* - `<SomeContext.Consumer>` with any context name
|
|
25
|
-
*
|
|
26
|
-
* Before:
|
|
27
|
-
* ```tsx
|
|
28
|
-
* <ThemeContext.Consumer>
|
|
29
|
-
* {theme => <div className={theme}>Hello</div>}
|
|
30
|
-
* </ThemeContext.Consumer>
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* Recommended replacement:
|
|
34
|
-
* ```tsx
|
|
35
|
-
* import { use } from 'react';
|
|
36
|
-
* const theme = use(ThemeContext);
|
|
37
|
-
* return <div className={theme}>Hello</div>;
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
17
|
* @see https://react.dev/blog/2024/12/05/react-19#context-as-a-provider
|
|
41
18
|
*/
|
|
42
19
|
export class FindContextConsumer extends Recipe {
|