@openrewrite/recipes-react 0.21.0 → 0.23.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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -0
- 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 +14 -4
- package/dist/migration/change-component-prop-value.js.map +1 -1
- package/dist/mui/adapt-v4-theme.d.ts +8 -0
- package/dist/mui/adapt-v4-theme.d.ts.map +1 -0
- package/dist/mui/adapt-v4-theme.js +65 -0
- package/dist/mui/adapt-v4-theme.js.map +1 -0
- package/dist/mui/add-component-prop.d.ts +18 -0
- package/dist/mui/add-component-prop.d.ts.map +1 -0
- package/dist/mui/add-component-prop.js +53 -0
- package/dist/mui/add-component-prop.js.map +1 -0
- package/dist/mui/add-emotion-prepend.d.ts +8 -0
- package/dist/mui/add-emotion-prepend.d.ts.map +1 -0
- package/dist/mui/add-emotion-prepend.js +71 -0
- package/dist/mui/add-emotion-prepend.js.map +1 -0
- package/dist/mui/change-module-specifier.d.ts +14 -0
- package/dist/mui/change-module-specifier.d.ts.map +1 -0
- package/dist/mui/change-module-specifier.js +95 -0
- package/dist/mui/change-module-specifier.js.map +1 -0
- package/dist/mui/convert-mui-imports.d.ts +14 -0
- package/dist/mui/convert-mui-imports.d.ts.map +1 -0
- package/dist/mui/convert-mui-imports.js +195 -0
- package/dist/mui/convert-mui-imports.js.map +1 -0
- package/dist/mui/convert-prop-to-sx.d.ts +22 -0
- package/dist/mui/convert-prop-to-sx.d.ts.map +1 -0
- package/dist/mui/convert-prop-to-sx.js +99 -0
- package/dist/mui/convert-prop-to-sx.js.map +1 -0
- package/dist/mui/index.d.ts +32 -0
- package/dist/mui/index.d.ts.map +1 -0
- package/dist/mui/index.js +67 -0
- package/dist/mui/index.js.map +1 -0
- package/dist/mui/jsx-attributes.d.ts +27 -0
- package/dist/mui/jsx-attributes.d.ts.map +1 -0
- package/dist/mui/jsx-attributes.js +140 -0
- package/dist/mui/jsx-attributes.js.map +1 -0
- package/dist/mui/mark-manual-migration.d.ts +16 -0
- package/dist/mui/mark-manual-migration.d.ts.map +1 -0
- package/dist/mui/mark-manual-migration.js +73 -0
- package/dist/mui/mark-manual-migration.js.map +1 -0
- package/dist/mui/mark-palette-mode-usage.d.ts +12 -0
- package/dist/mui/mark-palette-mode-usage.d.ts.map +1 -0
- package/dist/mui/mark-palette-mode-usage.js +50 -0
- package/dist/mui/mark-palette-mode-usage.js.map +1 -0
- package/dist/mui/move-component-prop-to-slot.d.ts +22 -0
- package/dist/mui/move-component-prop-to-slot.d.ts.map +1 -0
- package/dist/mui/move-component-prop-to-slot.js +87 -0
- package/dist/mui/move-component-prop-to-slot.js.map +1 -0
- package/dist/mui/move-primary-text-to-children.d.ts +12 -0
- package/dist/mui/move-primary-text-to-children.d.ts.map +1 -0
- package/dist/mui/move-primary-text-to-children.js +52 -0
- package/dist/mui/move-primary-text-to-children.js.map +1 -0
- package/dist/mui/move-system-props-to-sx.d.ts +16 -0
- package/dist/mui/move-system-props-to-sx.d.ts.map +1 -0
- package/dist/mui/move-system-props-to-sx.js +122 -0
- package/dist/mui/move-system-props-to-sx.js.map +1 -0
- package/dist/mui/mui-components.d.ts +8 -0
- package/dist/mui/mui-components.d.ts.map +1 -0
- package/dist/mui/mui-components.js +41 -0
- package/dist/mui/mui-components.js.map +1 -0
- package/dist/mui/mui-tag-visitor.d.ts +5 -0
- package/dist/mui/mui-tag-visitor.d.ts.map +1 -0
- package/dist/mui/mui-tag-visitor.js +54 -0
- package/dist/mui/mui-tag-visitor.js.map +1 -0
- package/dist/mui/pre-v5-recipe.d.ts +14 -0
- package/dist/mui/pre-v5-recipe.d.ts.map +1 -0
- package/dist/mui/pre-v5-recipe.js +88 -0
- package/dist/mui/pre-v5-recipe.js.map +1 -0
- package/dist/mui/remove-component-prop.d.ts +18 -0
- package/dist/mui/remove-component-prop.d.ts.map +1 -0
- package/dist/mui/remove-component-prop.js +55 -0
- package/dist/mui/remove-component-prop.js.map +1 -0
- package/dist/mui/remove-root-ref.d.ts +8 -0
- package/dist/mui/remove-root-ref.d.ts.map +1 -0
- package/dist/mui/remove-root-ref.js +61 -0
- package/dist/mui/remove-root-ref.js.map +1 -0
- package/dist/mui/remove-spacing-px-suffix.d.ts +8 -0
- package/dist/mui/remove-spacing-px-suffix.d.ts.map +1 -0
- package/dist/mui/remove-spacing-px-suffix.js +62 -0
- package/dist/mui/remove-spacing-px-suffix.js.map +1 -0
- package/dist/mui/rename-component-prop.d.ts +20 -0
- package/dist/mui/rename-component-prop.d.ts.map +1 -0
- package/dist/mui/rename-component-prop.js +66 -0
- package/dist/mui/rename-component-prop.js.map +1 -0
- package/dist/mui/rename-joy-css-variables.d.ts +8 -0
- package/dist/mui/rename-joy-css-variables.d.ts.map +1 -0
- package/dist/mui/rename-joy-css-variables.js +51 -0
- package/dist/mui/rename-joy-css-variables.js.map +1 -0
- package/dist/mui/rename-theme-palette-type.d.ts +8 -0
- package/dist/mui/rename-theme-palette-type.d.ts.map +1 -0
- package/dist/mui/rename-theme-palette-type.js +61 -0
- package/dist/mui/rename-theme-palette-type.js.map +1 -0
- package/dist/mui/replace-box-border-radius.d.ts +10 -0
- package/dist/mui/replace-box-border-radius.d.ts.map +1 -0
- package/dist/mui/replace-box-border-radius.js +50 -0
- package/dist/mui/replace-box-border-radius.js.map +1 -0
- package/dist/mui/replace-breakpoints-width.d.ts +8 -0
- package/dist/mui/replace-breakpoints-width.d.ts.map +1 -0
- package/dist/mui/replace-breakpoints-width.js +46 -0
- package/dist/mui/replace-breakpoints-width.js.map +1 -0
- package/dist/mui/replace-component-class.d.ts +18 -0
- package/dist/mui/replace-component-class.d.ts.map +1 -0
- package/dist/mui/replace-component-class.js +126 -0
- package/dist/mui/replace-component-class.js.map +1 -0
- package/dist/mui/replace-components-with-slots.d.ts +14 -0
- package/dist/mui/replace-components-with-slots.d.ts.map +1 -0
- package/dist/mui/replace-components-with-slots.js +69 -0
- package/dist/mui/replace-components-with-slots.js.map +1 -0
- package/dist/mui/replace-import-paths.d.ts +14 -0
- package/dist/mui/replace-import-paths.d.ts.map +1 -0
- package/dist/mui/replace-import-paths.js +101 -0
- package/dist/mui/replace-import-paths.js.map +1 -0
- package/dist/mui/replace-in-string-literals.d.ts +15 -0
- package/dist/mui/replace-in-string-literals.d.ts.map +1 -0
- package/dist/mui/replace-in-string-literals.js +62 -0
- package/dist/mui/replace-in-string-literals.js.map +1 -0
- package/dist/mui/replace-list-item-button-prop.d.ts +12 -0
- package/dist/mui/replace-list-item-button-prop.d.ts.map +1 -0
- package/dist/mui/replace-list-item-button-prop.js +80 -0
- package/dist/mui/replace-list-item-button-prop.js.map +1 -0
- package/dist/mui/replace-tabs-scroll-buttons.d.ts +8 -0
- package/dist/mui/replace-tabs-scroll-buttons.d.ts.map +1 -0
- package/dist/mui/replace-tabs-scroll-buttons.js +41 -0
- package/dist/mui/replace-tabs-scroll-buttons.js.map +1 -0
- package/dist/mui/replace-theme-color-functions.d.ts +8 -0
- package/dist/mui/replace-theme-color-functions.d.ts.map +1 -0
- package/dist/mui/replace-theme-color-functions.js +72 -0
- package/dist/mui/replace-theme-color-functions.js.map +1 -0
- package/dist/mui/replace-theme-spacing-unit.d.ts +8 -0
- package/dist/mui/replace-theme-spacing-unit.d.ts.map +1 -0
- package/dist/mui/replace-theme-spacing-unit.js +77 -0
- package/dist/mui/replace-theme-spacing-unit.js.map +1 -0
- package/dist/mui/replace-typography-round.d.ts +8 -0
- package/dist/mui/replace-typography-round.d.ts.map +1 -0
- package/dist/mui/replace-typography-round.js +44 -0
- package/dist/mui/replace-typography-round.js.map +1 -0
- package/dist/mui/shift-hidden-down-props.d.ts +10 -0
- package/dist/mui/shift-hidden-down-props.d.ts.map +1 -0
- package/dist/mui/shift-hidden-down-props.js +49 -0
- package/dist/mui/shift-hidden-down-props.js.map +1 -0
- package/dist/mui/theme-access.d.ts +5 -0
- package/dist/mui/theme-access.d.ts.map +1 -0
- package/dist/mui/theme-access.js +21 -0
- package/dist/mui/theme-access.js.map +1 -0
- package/dist/mui/update-theme-breakpoints.d.ts +10 -0
- package/dist/mui/update-theme-breakpoints.d.ts.map +1 -0
- package/dist/mui/update-theme-breakpoints.js +58 -0
- package/dist/mui/update-theme-breakpoints.js.map +1 -0
- package/dist/mui/upgrade-grid-props.d.ts +16 -0
- package/dist/mui/upgrade-grid-props.d.ts.map +1 -0
- package/dist/mui/upgrade-grid-props.js +90 -0
- package/dist/mui/upgrade-grid-props.js.map +1 -0
- package/dist/react19/use-context-hook.d.ts.map +1 -1
- package/dist/react19/use-context-hook.js +2 -0
- package/dist/react19/use-context-hook.js.map +1 -1
- package/dist/search/find-enzyme-usage.d.ts +4 -0
- package/dist/search/find-enzyme-usage.d.ts.map +1 -1
- package/dist/search/find-enzyme-usage.js +91 -7
- package/dist/search/find-enzyme-usage.js.map +1 -1
- package/dist/testing/enzyme-host-components.d.ts +12 -0
- package/dist/testing/enzyme-host-components.d.ts.map +1 -1
- package/dist/testing/enzyme-host-components.js +100 -0
- package/dist/testing/enzyme-host-components.js.map +1 -1
- package/dist/testing/enzyme-render-blockers.d.ts +13 -4
- package/dist/testing/enzyme-render-blockers.d.ts.map +1 -1
- package/dist/testing/enzyme-render-blockers.js +162 -6
- package/dist/testing/enzyme-render-blockers.js.map +1 -1
- package/dist/testing/enzyme-to-react-testing-library.d.ts +9 -2
- package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
- package/dist/testing/enzyme-to-react-testing-library.js +163 -16
- package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
- package/dist/testing/enzyme-usage.d.ts +7 -0
- package/dist/testing/enzyme-usage.d.ts.map +1 -1
- package/dist/testing/enzyme-usage.js +8 -1
- package/dist/testing/enzyme-usage.js.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.d.ts +8 -5
- package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.js +16 -4
- package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
- package/dist/zustand/redux-stores.d.ts +2 -0
- package/dist/zustand/redux-stores.d.ts.map +1 -1
- package/dist/zustand/redux-stores.js +120 -6
- package/dist/zustand/redux-stores.js.map +1 -1
- package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
- package/dist/zustand/redux-to-zustand.js +10 -4
- package/dist/zustand/redux-to-zustand.js.map +1 -1
- package/dist/zustand/zustand-plan.d.ts +7 -0
- package/dist/zustand/zustand-plan.d.ts.map +1 -1
- package/dist/zustand/zustand-plan.js +141 -21
- package/dist/zustand/zustand-plan.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +10 -0
- package/src/migration/change-component-prop-value.ts +19 -8
- package/src/mui/adapt-v4-theme.ts +43 -0
- package/src/mui/add-component-prop.ts +43 -0
- package/src/mui/add-emotion-prepend.ts +48 -0
- package/src/mui/change-module-specifier.ts +71 -0
- package/src/mui/convert-mui-imports.ts +184 -0
- package/src/mui/convert-prop-to-sx.ts +89 -0
- package/src/mui/index.ts +31 -0
- package/src/mui/jsx-attributes.ts +133 -0
- package/src/mui/mark-manual-migration.ts +53 -0
- package/src/mui/mark-palette-mode-usage.ts +36 -0
- package/src/mui/move-component-prop-to-slot.ts +84 -0
- package/src/mui/move-primary-text-to-children.ts +41 -0
- package/src/mui/move-system-props-to-sx.ts +118 -0
- package/src/mui/mui-components.ts +40 -0
- package/src/mui/mui-tag-visitor.ts +36 -0
- package/src/mui/pre-v5-recipe.ts +82 -0
- package/src/mui/remove-component-prop.ts +43 -0
- package/src/mui/remove-root-ref.ts +41 -0
- package/src/mui/remove-spacing-px-suffix.ts +43 -0
- package/src/mui/rename-component-prop.ts +55 -0
- package/src/mui/rename-joy-css-variables.ts +41 -0
- package/src/mui/rename-theme-palette-type.ts +42 -0
- package/src/mui/replace-box-border-radius.ts +42 -0
- package/src/mui/replace-breakpoints-width.ts +28 -0
- package/src/mui/replace-component-class.ts +97 -0
- package/src/mui/replace-components-with-slots.ts +61 -0
- package/src/mui/replace-import-paths.ts +100 -0
- package/src/mui/replace-in-string-literals.ts +44 -0
- package/src/mui/replace-list-item-button-prop.ts +59 -0
- package/src/mui/replace-tabs-scroll-buttons.ts +31 -0
- package/src/mui/replace-theme-color-functions.ts +55 -0
- package/src/mui/replace-theme-spacing-unit.ts +59 -0
- package/src/mui/replace-typography-round.ts +29 -0
- package/src/mui/shift-hidden-down-props.ts +44 -0
- package/src/mui/theme-access.ts +18 -0
- package/src/mui/update-theme-breakpoints.ts +47 -0
- package/src/mui/upgrade-grid-props.ts +82 -0
- package/src/react19/use-context-hook.ts +2 -0
- package/src/search/find-enzyme-usage.ts +80 -7
- package/src/testing/enzyme-host-components.ts +110 -0
- package/src/testing/enzyme-render-blockers.ts +174 -9
- package/src/testing/enzyme-to-react-testing-library.ts +159 -25
- package/src/testing/enzyme-usage.ts +13 -0
- package/src/testing/enzyme-wrapper-scope.ts +27 -6
- package/src/zustand/redux-stores.ts +119 -5
- package/src/zustand/redux-to-zustand.ts +12 -5
- package/src/zustand/zustand-plan.ts +159 -18
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.hookName = exports.REDUCER_STORE_HOOK = exports.STORE_LISTENERS = exports.SELECTOR_HOOK = exports.STORE_MEMBERS = exports.REACT_REDUX = void 0;
|
|
13
|
+
exports.storeValueAction = storeValueAction;
|
|
13
14
|
exports.connectAction = connectAction;
|
|
14
15
|
exports.parentTree = parentTree;
|
|
15
16
|
exports.isStatement = isStatement;
|
|
@@ -40,6 +41,54 @@ const path_1 = require("path");
|
|
|
40
41
|
const module_imports_1 = require("../util/module-imports");
|
|
41
42
|
const redux_stores_1 = require("./redux-stores");
|
|
42
43
|
exports.REACT_REDUX = "react-redux";
|
|
44
|
+
function storeValueUse(identifier, cursor, persistStore) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const trees = ancestors(cursor);
|
|
47
|
+
if (trees.some(tree => tree.kind === javascript_1.JS.Kind.TypeQuery))
|
|
48
|
+
return { kind: "type" };
|
|
49
|
+
const parent = parentTree(cursor);
|
|
50
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation) {
|
|
51
|
+
const call = parent;
|
|
52
|
+
if (((_a = call.select) === null || _a === void 0 ? void 0 : _a.element) === identifier)
|
|
53
|
+
return { kind: "method", name: call.name.simpleName };
|
|
54
|
+
if (argumentsOf(call).includes(identifier)) {
|
|
55
|
+
if (!call.select && persistStore.has(call.name.simpleName))
|
|
56
|
+
return { kind: "persist" };
|
|
57
|
+
const select = call.select && (0, java_1.isIdentifier)(call.select.element) ? `${call.select.element.simpleName}.` : "";
|
|
58
|
+
return { kind: "passed", name: select + call.name.simpleName };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.FieldAccess && parent.target === identifier && exports.STORE_MEMBERS.has(parent.name.element.simpleName)) {
|
|
62
|
+
return { kind: "member", name: parent.name.element.simpleName };
|
|
63
|
+
}
|
|
64
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.kind) === javascript_1.JS.Kind.JsxEmbeddedExpression && ((_b = trees[2]) === null || _b === void 0 ? void 0 : _b.kind) === javascript_1.JS.Kind.JsxAttribute && (0, java_1.isIdentifier)(trees[2].key) &&
|
|
65
|
+
trees[2].key.simpleName === "store")
|
|
66
|
+
return { kind: "provider" };
|
|
67
|
+
return { kind: "other" };
|
|
68
|
+
}
|
|
69
|
+
const MEMBER_CALLS = { getState: "() => STORE.getState()", dispatch: "action => STORE.dispatch(action)", subscribe: "listener => STORE.subscribe(listener)" };
|
|
70
|
+
function storeValueAction(store, uses) {
|
|
71
|
+
if (uses.some(use => use.kind === "persist"))
|
|
72
|
+
return `\`${store}\` is passed to redux-persist's \`persistStore\`, and redux-persist persists a Redux store: convert the store by hand, with zustand's \`persist\` middleware in place of redux-persist.`;
|
|
73
|
+
const first = (kind) => uses.find(use => use.kind === kind);
|
|
74
|
+
const actions = [];
|
|
75
|
+
if (first("type"))
|
|
76
|
+
actions.push(`\`typeof ${store}\` types, such as \`ReturnType<typeof ${store}.getState>\`, go with the TypeScript sources, which aren't converted yet.`);
|
|
77
|
+
const passed = first("passed");
|
|
78
|
+
if (passed && /(^|\.)spyOn$/.test(passed.name))
|
|
79
|
+
actions.push(`\`${passed.name}(${store}, ...)\` spies on a member of the Redux store, which the conversion replaces: check what the test spies for another way, such as by the state after the dispatch, or convert the test by hand.`);
|
|
80
|
+
else if (passed)
|
|
81
|
+
actions.push(`\`${store}\` is passed to \`${passed.name}\`, which the recipe doesn't follow: pass the calls it makes instead, such as \`() => ${store}.getState()\` and \`action => ${store}.dispatch(action)\`, so that the recipe checks each call, or convert by hand.`);
|
|
82
|
+
const member = first("member");
|
|
83
|
+
if (member)
|
|
84
|
+
actions.push(`Call \`${store}.${member.name}\` rather than pass it, as \`${MEMBER_CALLS[member.name].replace("STORE", store)}\`, so that the recipe checks each call.`);
|
|
85
|
+
const method = first("method");
|
|
86
|
+
if (method)
|
|
87
|
+
actions.push(`The zustand store has no \`${method.name}\`: remove \`${store}.${method.name}(...)\`, or convert by hand.`);
|
|
88
|
+
if (first("provider"))
|
|
89
|
+
actions.push(`Render \`<Provider store={${store}}>\` in a module that imports the store, not in the store's own source.`);
|
|
90
|
+
return actions.length > 0 ? actions.join(" ") : undefined;
|
|
91
|
+
}
|
|
43
92
|
const REACT_REDUX_VALUE_ACTIONS = {
|
|
44
93
|
shallowEqual: "zustand's hooks take no equality function. Where `shallowEqual` is `useSelector`'s second argument, select one value in each `useSelector` and drop it, or write the selector with zustand's `useShallow` by hand.",
|
|
45
94
|
TypedUseSelectorHook: "A react-redux type goes with the TypeScript sources, which aren't converted yet.",
|
|
@@ -50,11 +99,50 @@ const REACT_REDUX_CALL_ACTIONS = {
|
|
|
50
99
|
batch: "zustand has no `batch`: on React 18, which batches updates itself, call the callback directly; before React 18, wrap it in `unstable_batchedUpdates` of react-dom.",
|
|
51
100
|
useStore: "Read the state with `useSelector` and dispatch with `useDispatch` instead of `useStore()`, or convert by hand."
|
|
52
101
|
};
|
|
102
|
+
function selectorAction(args, typed) {
|
|
103
|
+
if (typed)
|
|
104
|
+
return "A `useSelector` with type arguments goes with the TypeScript sources, which aren't converted yet.";
|
|
105
|
+
if (args !== 1)
|
|
106
|
+
return "Pass `useSelector` the selector alone: zustand's hooks take no equality function. Select one value in each `useSelector`, so that none needs one, or convert by hand.";
|
|
107
|
+
return "Read one slice's state in each selector, such as `state => state.counter.value`, or a top-level `const` selector that does, so that the slice's zustand hook can take it.";
|
|
108
|
+
}
|
|
109
|
+
const UNREAD_SLICES = "The store's slices aren't read while its own rows, such as MIDDLEWARE or ROOT_REDUCER, hold it back, so this use is recorded without being checked: remove what those rows name, and run the recipe again.";
|
|
110
|
+
function sliceDispatchAction(binding, fromSlice) {
|
|
111
|
+
return fromSlice ?
|
|
112
|
+
`\`${binding.name}\` of ${binding.module} is neither one of its slice's action creators nor a \`createAsyncThunk\` the recipe reads, such as a thunk written as \`() => async dispatch => ...\`: declare it with \`createAsyncThunk\` in that source, or export it from \`slice.actions\`, or convert by hand.` :
|
|
113
|
+
`\`${binding.name}\` comes from ${binding.module}, which declares none of the store's slices, such as a module of hand-written action creators or thunks: write it as a reducer of a \`createSlice\`, or as a \`createAsyncThunk\` in a slice's source, and import it from there, or convert by hand.`;
|
|
114
|
+
}
|
|
53
115
|
function connectAction(wholeStores) {
|
|
54
116
|
return wholeStores ?
|
|
55
117
|
"`connect` converts only where the store moves whole, which takes a `configureStore` of `reducer` alone, or a `createStore` of a reducer with at most a preloaded state, `applyMiddleware(thunk)` and Redux DevTools. Remove what the store's other rows name so it moves whole, or replace `connect` with `useSelector` and `useDispatch`." :
|
|
56
118
|
"`connect` converts only where the store moves whole, which `wholeStores` turns off: run with it on, or replace `connect` with `useSelector` and `useDispatch`.";
|
|
57
119
|
}
|
|
120
|
+
function storeExportAction(binding, source, store, storeModule, wholeStores) {
|
|
121
|
+
const name = binding.name === "default" ? binding.local : binding.name;
|
|
122
|
+
if (/^use[A-Z]/.test(name))
|
|
123
|
+
return `\`${name}\` comes from the store's source, which the conversion removes; most often it is a typed alias of a react-redux hook, such as \`useSelector.withTypes<RootState>()\`: call the hook itself where \`${name}\` is called and remove the alias, or convert by hand.`;
|
|
124
|
+
if (/^[A-Z]/.test(name) && source.typescript)
|
|
125
|
+
return `\`${name}\` comes from the store's source, which the conversion removes; most often it is a type of the store, such as \`ReturnType<typeof store.getState>\`, which goes with the TypeScript sources, which aren't converted yet.`;
|
|
126
|
+
if (/persist/i.test(name) && (storeModule === null || storeModule === void 0 ? void 0 : storeModule.bindings.some(b => b.module === "redux-persist")))
|
|
127
|
+
return `\`${name}\` comes from the store's source, and redux-persist persists a Redux store: convert the store by hand, with zustand's \`persist\` middleware in place of redux-persist.`;
|
|
128
|
+
if (!store.exportedAs && (name === store.store || /store/i.test(name)))
|
|
129
|
+
return `The store isn't created at its module's top level, so \`${name}\` is no store the recipe follows: create one store with \`export const store = configureStore(...)\`, and import that in place of \`${name}\`, or convert by hand.`;
|
|
130
|
+
return `\`${name}\` comes from the store's source, ${store.path}, which the conversion removes: move \`${name}\` to a module of its own and import it from there, or convert by hand.` +
|
|
131
|
+
(wholeStores && store.exportedAs ? ` Or remove what the store's other rows name, so that it moves whole and its source keeps \`${name}\`.` : "");
|
|
132
|
+
}
|
|
133
|
+
function multipleStoresAction(store, stores, facts) {
|
|
134
|
+
const app = stores.filter(s => { var _a; return !((_a = facts.get(s.path)) === null || _a === void 0 ? void 0 : _a.test); });
|
|
135
|
+
const why = "the recipe converts a package of one store, as react-redux's hooks don't say which store they read";
|
|
136
|
+
if (app.length === 0)
|
|
137
|
+
return `All ${stores.length} of the package's stores are created in test, mock or story sources: ${why}. Convert by hand.`;
|
|
138
|
+
if (app.length === 1) {
|
|
139
|
+
const one = app[0] === store ? "this store" : `its one other store, \`${app[0].store}\` of ${app[0].path}`;
|
|
140
|
+
return `${stores.length - 1} of the package's ${stores.length} stores ${stores.length === 2 ? "is" : "are"} created in test, mock or story sources, which hold back ${one}: ${why}. Convert by hand.`;
|
|
141
|
+
}
|
|
142
|
+
const paths = [...new Set(app.map(s => s.path))];
|
|
143
|
+
const named = paths.length > 3 ? `${paths.slice(0, 3).join(", ")} and ${paths.length - 3} more` : paths.join(", ");
|
|
144
|
+
return `The package creates ${app.length} stores outside tests, in ${named}: ${why}. Move each store, with the sources that use it, to a package of its own, or convert by hand.`;
|
|
145
|
+
}
|
|
58
146
|
function parentTree(cursor) {
|
|
59
147
|
for (let c = cursor.parent; c; c = c.parent) {
|
|
60
148
|
const value = c.value;
|
|
@@ -232,6 +320,7 @@ function sourceFacts(cu) {
|
|
|
232
320
|
};
|
|
233
321
|
const followed = new Map(bindings.filter(binding => binding.module === exports.REACT_REDUX || (0, module_imports_1.isRelativeSpecifier)(binding.module) || (0, module_imports_1.isAliasSpecifier)(binding.module))
|
|
234
322
|
.map(binding => [binding.local, binding]));
|
|
323
|
+
const persistStore = new Set(bindings.filter(b => b.module === "redux-persist" && b.name === "persistStore").map(b => b.local));
|
|
235
324
|
for (const { element } of cu.statements) {
|
|
236
325
|
if (element.kind === javascript_1.JS.Kind.Import) {
|
|
237
326
|
const imp = element;
|
|
@@ -273,7 +362,7 @@ function sourceFacts(cu) {
|
|
|
273
362
|
facts.uses.push(use);
|
|
274
363
|
}
|
|
275
364
|
if (binding) {
|
|
276
|
-
const use = classify(identifier, binding, this.cursor, followed, dispatchers, declared);
|
|
365
|
+
const use = classify(identifier, binding, this.cursor, followed, dispatchers, declared, persistStore);
|
|
277
366
|
if (use)
|
|
278
367
|
facts.uses.push(use);
|
|
279
368
|
}
|
|
@@ -311,7 +400,7 @@ function storeFacts(cu, modules, resolve) {
|
|
|
311
400
|
const name = storeNameAt(this.cursor);
|
|
312
401
|
const own = yield usesInSource(cu, name, call);
|
|
313
402
|
stores.push({ path: cu.sourcePath, api: store.api, store: name, findings: store.findings,
|
|
314
|
-
slices: store.slices, exportedAs: exportedStore(cu, this.cursor), reducerStore: store.reducerStore, usedInSource: own.other, calledInSource: own.called });
|
|
403
|
+
slices: store.slices, exportedAs: exportedStore(cu, this.cursor), reducerStore: store.reducerStore, usedInSource: own.other, usesInSource: own.uses, calledInSource: own.called });
|
|
315
404
|
}
|
|
316
405
|
return _super.visitMethodInvocation.call(this, call, ctx);
|
|
317
406
|
});
|
|
@@ -351,7 +440,7 @@ function dispatcherCount(cu, followed, name) {
|
|
|
351
440
|
});
|
|
352
441
|
return count;
|
|
353
442
|
}
|
|
354
|
-
function classify(identifier, binding, cursor, followed, dispatchers, declared) {
|
|
443
|
+
function classify(identifier, binding, cursor, followed, dispatchers, declared, persistStore) {
|
|
355
444
|
var _a, _b, _c, _d, _e;
|
|
356
445
|
const trees = ancestors(cursor);
|
|
357
446
|
if (trees.some(tree => tree.kind === javascript_1.JS.Kind.Import))
|
|
@@ -394,7 +483,7 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
|
|
|
394
483
|
if (read)
|
|
395
484
|
return { local, kind: "selector", key: read.key };
|
|
396
485
|
const selector = args.length === 1 && !call.typeParameters && (0, java_1.isIdentifier)(args[0]) ? args[0].simpleName : undefined;
|
|
397
|
-
return Object.assign(Object.assign({}, other("a selector that isn't a read of one slice's state")), { reason: "SELECTOR", selector, anySelector: args.length === 1 && !call.typeParameters });
|
|
486
|
+
return Object.assign(Object.assign({}, other("a selector that isn't a read of one slice's state", selectorAction(args.length, Boolean(call.typeParameters)))), { reason: "SELECTOR", selector, anySelector: args.length === 1 && !call.typeParameters });
|
|
398
487
|
}
|
|
399
488
|
if (binding.name === "useDispatch") {
|
|
400
489
|
const variable = parentTree(cursorOf(cursor, call));
|
|
@@ -427,7 +516,10 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
|
|
|
427
516
|
if (member === "dispatch" && dispatchedAction(call)) {
|
|
428
517
|
return isStatement(call, outer) ? { local, kind: "storeDispatch", member } : Object.assign(Object.assign({}, other("the dispatch's result is used")), { reason: "DISPATCH", member });
|
|
429
518
|
}
|
|
430
|
-
|
|
519
|
+
const action = member === "getState" ? `Read one slice's state in each call, such as \`${local}.getState().counter\`, rather than the whole state, or convert by hand.` :
|
|
520
|
+
member === "dispatch" ? unimportedDispatchAction(call, undefined, `${local}.dispatch`) :
|
|
521
|
+
member === "subscribe" ? `\`${local}.subscribe\` converts only where the store moves whole: remove what the store's other rows name, or convert by hand.` : undefined;
|
|
522
|
+
return Object.assign(Object.assign({}, other(`\`${local}.${member}\``, action)), { member });
|
|
431
523
|
}
|
|
432
524
|
if ((parent === null || parent === void 0 ? void 0 : parent.kind) === javascript_1.JS.Kind.JsxEmbeddedExpression) {
|
|
433
525
|
const attribute = trees[2];
|
|
@@ -440,7 +532,8 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
|
|
|
440
532
|
return { local, kind: "provider" };
|
|
441
533
|
}
|
|
442
534
|
}
|
|
443
|
-
|
|
535
|
+
const valueUse = storeValueUse(identifier, cursor, persistStore);
|
|
536
|
+
return Object.assign(Object.assign({}, other("referenced")), { valueUse: valueUse.kind === "provider" ? { kind: "other" } : valueUse });
|
|
444
537
|
}
|
|
445
538
|
function connectUse(call, other) {
|
|
446
539
|
const args = argumentsOf(call);
|
|
@@ -458,6 +551,20 @@ function connectUse(call, other) {
|
|
|
458
551
|
}
|
|
459
552
|
return undefined;
|
|
460
553
|
}
|
|
554
|
+
function unimportedDispatchAction(dispatch, action, name = dispatch.name.simpleName) {
|
|
555
|
+
const [arg] = argumentsOf(dispatch);
|
|
556
|
+
if (action) {
|
|
557
|
+
return `\`${action.name.simpleName}\` isn't imported: import the action creator from the slice's source that declares it, and dispatch \`${name}(${action.name.simpleName}(...))\`, or convert by hand.`;
|
|
558
|
+
}
|
|
559
|
+
if ((arg === null || arg === void 0 ? void 0 : arg.kind) === java_1.J.Kind.MethodInvocation && arg.select) {
|
|
560
|
+
const member = arg.name.simpleName;
|
|
561
|
+
return `Import \`${member}\` by name from the slice's source, as \`export const {${member}} = slice.actions\` exports it, and dispatch \`${name}(${member}(...))\` rather than a member call such as \`actions.${member}(...)\`, or convert by hand.`;
|
|
562
|
+
}
|
|
563
|
+
if ((0, redux_stores_1.objectProperties)(arg)) {
|
|
564
|
+
return `An action object such as \`${name}({type: ...})\` has no zustand equivalent: dispatch a call of a slice's action creator for the same type, \`${name}(x(...))\`, or convert by hand.`;
|
|
565
|
+
}
|
|
566
|
+
return `Dispatch a call of an imported action creator in place, \`${name}(x(...))\`, rather than an action held in a variable or chosen by a condition, or convert by hand.`;
|
|
567
|
+
}
|
|
461
568
|
function dispatcherUse(identifier, cursor, followed, bindings) {
|
|
462
569
|
const parent = parentTree(cursor);
|
|
463
570
|
const local = identifier.simpleName;
|
|
@@ -473,7 +580,7 @@ function dispatcherUse(identifier, cursor, followed, bindings) {
|
|
|
473
580
|
const binding = action && followed.get(action.name.simpleName);
|
|
474
581
|
if (binding && binding.module !== exports.REACT_REDUX)
|
|
475
582
|
return undefined;
|
|
476
|
-
return { local, kind: "other", detail: "dispatches what isn't an imported action creator", reason: "DISPATCH" };
|
|
583
|
+
return { local, kind: "other", detail: "dispatches what isn't an imported action creator", reason: "DISPATCH", action: unimportedDispatchAction(call, action) };
|
|
477
584
|
}
|
|
478
585
|
return { local, kind: "other", detail: "the dispatcher is used other than to dispatch", reason: "DISPATCH" };
|
|
479
586
|
}
|
|
@@ -521,7 +628,8 @@ function cursorOf(cursor, node) {
|
|
|
521
628
|
exports.STORE_MEMBERS = new Set(["getState", "dispatch", "subscribe"]);
|
|
522
629
|
function usesInSource(cu, name, call) {
|
|
523
630
|
return __awaiter(this, void 0, void 0, function* () {
|
|
524
|
-
const result = { other: false, called: new Set() };
|
|
631
|
+
const result = { other: false, uses: [], called: new Set() };
|
|
632
|
+
const persistStore = (0, redux_stores_1.importedAs)(cu, "redux-persist", "persistStore");
|
|
525
633
|
const statements = cu.statements.map(s => s.element).flatMap(statement => {
|
|
526
634
|
if (statement.kind === javascript_1.JS.Kind.Import)
|
|
527
635
|
return [];
|
|
@@ -560,6 +668,7 @@ function usesInSource(cu, name, call) {
|
|
|
560
668
|
parent.initializer)
|
|
561
669
|
return identifier;
|
|
562
670
|
result.other = true;
|
|
671
|
+
result.uses.push(storeValueUse(identifier, this.cursor, persistStore));
|
|
563
672
|
return identifier;
|
|
564
673
|
});
|
|
565
674
|
}
|
|
@@ -635,7 +744,7 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
|
|
|
635
744
|
return result;
|
|
636
745
|
if (stores.length > 1) {
|
|
637
746
|
for (const store of stores)
|
|
638
|
-
result.blocked.set(store, [...store.findings, { reason: "MULTIPLE_STORES", detail: `${stores.length} stores
|
|
747
|
+
result.blocked.set(store, [...store.findings, { reason: "MULTIPLE_STORES", detail: `${stores.length} stores`, action: multipleStoresAction(store, stores, facts) }]);
|
|
639
748
|
return result;
|
|
640
749
|
}
|
|
641
750
|
const store = stores[0];
|
|
@@ -643,6 +752,7 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
|
|
|
643
752
|
const block = (reason, detail, action) => findings.push(Object.assign({ reason, detail }, action ? { action } : {}));
|
|
644
753
|
const held = new Map();
|
|
645
754
|
const handled = new Map();
|
|
755
|
+
const slicesRead = findings.length === 0;
|
|
646
756
|
if (findings.length === 0) {
|
|
647
757
|
if (!store.exportedAs)
|
|
648
758
|
block("STORE_NOT_MODULE_LEVEL", store.store);
|
|
@@ -689,6 +799,7 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
|
|
|
689
799
|
}
|
|
690
800
|
}
|
|
691
801
|
const slicePaths = new Map([...result.slices.values()].map(slice => [slice.path, slice]));
|
|
802
|
+
const storeModule = facts.get(store.path);
|
|
692
803
|
const sources = new Set([store.path, ...slicePaths.keys()]);
|
|
693
804
|
for (const source of facts.values()) {
|
|
694
805
|
const resolve = (module) => resolveFrom(source.path, module);
|
|
@@ -738,15 +849,24 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
|
|
|
738
849
|
if (use.kind === "providerTag" && !provides(source, use, store, resolve))
|
|
739
850
|
block("REACT_REDUX_USE", `${where}: \`Provider\` of \`${use.via}\`, which isn't the store`, PROVIDER_OTHER_STORE);
|
|
740
851
|
if (use.kind === "other") {
|
|
741
|
-
|
|
852
|
+
const whole = !wholeStores ? "" : use.anySelector ? " Or remove what the store's other rows name, so that it moves whole and runs the selector as it is." :
|
|
853
|
+
use.reason === "DISPATCH" ? " Or remove what the store's other rows name, so that it moves whole and dispatches it as Redux does." : "";
|
|
854
|
+
const reason = (_a = use.reason) !== null && _a !== void 0 ? _a : (isStore ? "STORE_USE" : slice ? "SLICE_USE" : !binding ? "DISPATCH" : isReactRedux ? "REACT_REDUX_USE" : "STORE_USE");
|
|
855
|
+
const member = isStore && (use.member === "getState" || use.member === "dispatch") && wholeStores ?
|
|
856
|
+
` Or remove what the store's other rows name, so that it moves whole and calls \`${use.member}\` as Redux does.` : "";
|
|
857
|
+
const action = binding && path === store.path && !isStore && reason === "STORE_USE" ? storeExportAction(binding, source, store, storeModule, wholeStores) :
|
|
858
|
+
isStore && use.valueUse ? storeValueAction(use.local, [use.valueUse]) : use.action && use.action + whole + member;
|
|
859
|
+
block(reason, `${where}: ${use.detail}`, action);
|
|
742
860
|
}
|
|
743
861
|
else if (use.kind === "selector" || use.kind === "getState") {
|
|
744
|
-
if (!result.slices.has(use.key))
|
|
745
|
-
block("SELECTOR", `${where} reads \`${use.key}\`, which is no slice of the store
|
|
862
|
+
if (!result.slices.has(use.key)) {
|
|
863
|
+
block("SELECTOR", `${where} reads \`${use.key}\`, which is no slice of the store`, !slicesRead ? UNREAD_SLICES : `\`${use.key}\` isn't a key of the store's \`reducer\`, whose slices are ${[...result.slices.keys()].map(k => `\`${k}\``).join(", ") || "none that convert"}: read one of those, or, where \`${use.key}\` is a reducer of the store that isn't a slice, rewrite it with \`createSlice\`.`);
|
|
864
|
+
}
|
|
746
865
|
}
|
|
747
866
|
else if (use.kind === "dispatched") {
|
|
748
|
-
if (!slice || !binding || !slice.actions.has(binding.name) && !slice.unknown.has(binding.name) && !slice.thunkVariables.has(binding.name))
|
|
749
|
-
block("DISPATCH", `${where} dispatches what isn't an action creator of a slice
|
|
867
|
+
if (!slice || !binding || !slice.actions.has(binding.name) && !slice.unknown.has(binding.name) && !slice.thunkVariables.has(binding.name)) {
|
|
868
|
+
block("DISPATCH", `${where} dispatches what isn't an action creator of a slice`, slicesRead ? binding && sliceDispatchAction(binding, slice !== undefined) : UNREAD_SLICES);
|
|
869
|
+
}
|
|
750
870
|
const via = source.bindings.find(b => b.local === use.via);
|
|
751
871
|
if (via && !(resolve(via.module) === store.path && via.name === store.exportedAs))
|
|
752
872
|
block("DISPATCH", `${where} is dispatched through \`${use.via}\``);
|
|
@@ -760,14 +880,14 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
|
|
|
760
880
|
if (slice && use.kind !== "dispatched" && use.kind !== "other")
|
|
761
881
|
block("SLICE_USE", `${where}: ${use.kind}`);
|
|
762
882
|
if (path === store.path && !isStore && source.path !== store.path)
|
|
763
|
-
block("STORE_USE", `${where} imports more of the store's source
|
|
883
|
+
block("STORE_USE", `${where} imports more of the store's source`, binding && storeExportAction(binding, source, store, storeModule, wholeStores));
|
|
764
884
|
}
|
|
765
885
|
for (const binding of source.bindings) {
|
|
766
886
|
if (source.path === store.path || binding.module === exports.REACT_REDUX || resolve(binding.module) !== store.path)
|
|
767
887
|
continue;
|
|
768
888
|
changes = true;
|
|
769
889
|
if (binding.name !== store.exportedAs)
|
|
770
|
-
block("STORE_USE", `${binding.local} in ${source.path} imports more of the store's source
|
|
890
|
+
block("STORE_USE", `${binding.local} in ${source.path} imports more of the store's source`, storeExportAction(binding, source, store, storeModule, wholeStores));
|
|
771
891
|
}
|
|
772
892
|
if (changes && source.path !== store.path) {
|
|
773
893
|
if (source.typescript)
|
|
@@ -794,7 +914,7 @@ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores
|
|
|
794
914
|
return result;
|
|
795
915
|
}
|
|
796
916
|
function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer, selectsOnEachRead, resolveFrom) {
|
|
797
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
917
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
798
918
|
const findings = [];
|
|
799
919
|
const block = (reason, detail, action) => findings.push(Object.assign({ reason, detail }, action ? { action } : {}));
|
|
800
920
|
const hook = exports.REDUCER_STORE_HOOK;
|
|
@@ -804,7 +924,7 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
|
|
|
804
924
|
if (!store.exportedAs)
|
|
805
925
|
block("STORE_NOT_MODULE_LEVEL", store.store);
|
|
806
926
|
if (store.usedInSource)
|
|
807
|
-
block("STORE_USE", `\`${store.store}\` is used in its own source`);
|
|
927
|
+
block("STORE_USE", `\`${store.store}\` is used in its own source`, (_g = storeValueAction(store.store, (_f = store.usesInSource) !== null && _f !== void 0 ? _f : [])) !== null && _g !== void 0 ? _g : `Move what uses \`${store.store}\` in its own source, other than calls of its \`getState\`, \`dispatch\` and \`subscribe\`, to a module that imports the store, or convert by hand.`);
|
|
808
928
|
const dependency = dependencies(store.path, false);
|
|
809
929
|
if (dependency)
|
|
810
930
|
findings.push(dependency);
|
|
@@ -818,7 +938,7 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
|
|
|
818
938
|
const sources = new Set([store.path]);
|
|
819
939
|
let connects = false;
|
|
820
940
|
let selects = false;
|
|
821
|
-
let subscribes = (
|
|
941
|
+
let subscribes = (_j = (_h = store.calledInSource) === null || _h === void 0 ? void 0 : _h.has("subscribe")) !== null && _j !== void 0 ? _j : false;
|
|
822
942
|
for (const source of facts.values()) {
|
|
823
943
|
const resolve = (module) => resolveFrom(source.path, module);
|
|
824
944
|
if (!scope(source.path)) {
|
|
@@ -856,7 +976,7 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
|
|
|
856
976
|
continue;
|
|
857
977
|
}
|
|
858
978
|
if (use.kind === "other")
|
|
859
|
-
block((
|
|
979
|
+
block((_k = use.reason) !== null && _k !== void 0 ? _k : "REACT_REDUX_USE", `${where}: ${use.detail}`, use.action);
|
|
860
980
|
continue;
|
|
861
981
|
}
|
|
862
982
|
const path = resolve(binding.module);
|
|
@@ -867,7 +987,7 @@ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer,
|
|
|
867
987
|
else if (use.kind === "other" && use.member === "subscribe")
|
|
868
988
|
subscribes = true;
|
|
869
989
|
else if (use.kind === "other" && use.member !== "getState" && use.member !== "dispatch")
|
|
870
|
-
block(use.reason === "DISPATCH" ? "STORE_USE" : (
|
|
990
|
+
block(use.reason === "DISPATCH" ? "STORE_USE" : (_l = use.reason) !== null && _l !== void 0 ? _l : "STORE_USE", `${where}: ${use.detail}`, use.valueUse && storeValueAction(use.local, [use.valueUse]));
|
|
871
991
|
}
|
|
872
992
|
if (changes && source.path !== store.path) {
|
|
873
993
|
if (source.typescript)
|