@openrewrite/recipes-react 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +27 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/mui/adapt-v4-theme.d.ts +8 -0
  6. package/dist/mui/adapt-v4-theme.d.ts.map +1 -0
  7. package/dist/mui/adapt-v4-theme.js +65 -0
  8. package/dist/mui/adapt-v4-theme.js.map +1 -0
  9. package/dist/mui/add-component-prop.d.ts +18 -0
  10. package/dist/mui/add-component-prop.d.ts.map +1 -0
  11. package/dist/mui/add-component-prop.js +53 -0
  12. package/dist/mui/add-component-prop.js.map +1 -0
  13. package/dist/mui/add-emotion-prepend.d.ts +8 -0
  14. package/dist/mui/add-emotion-prepend.d.ts.map +1 -0
  15. package/dist/mui/add-emotion-prepend.js +71 -0
  16. package/dist/mui/add-emotion-prepend.js.map +1 -0
  17. package/dist/mui/change-module-specifier.d.ts +14 -0
  18. package/dist/mui/change-module-specifier.d.ts.map +1 -0
  19. package/dist/mui/change-module-specifier.js +95 -0
  20. package/dist/mui/change-module-specifier.js.map +1 -0
  21. package/dist/mui/convert-mui-imports.d.ts +14 -0
  22. package/dist/mui/convert-mui-imports.d.ts.map +1 -0
  23. package/dist/mui/convert-mui-imports.js +195 -0
  24. package/dist/mui/convert-mui-imports.js.map +1 -0
  25. package/dist/mui/convert-prop-to-sx.d.ts +22 -0
  26. package/dist/mui/convert-prop-to-sx.d.ts.map +1 -0
  27. package/dist/mui/convert-prop-to-sx.js +99 -0
  28. package/dist/mui/convert-prop-to-sx.js.map +1 -0
  29. package/dist/mui/index.d.ts +32 -0
  30. package/dist/mui/index.d.ts.map +1 -0
  31. package/dist/mui/index.js +67 -0
  32. package/dist/mui/index.js.map +1 -0
  33. package/dist/mui/jsx-attributes.d.ts +27 -0
  34. package/dist/mui/jsx-attributes.d.ts.map +1 -0
  35. package/dist/mui/jsx-attributes.js +140 -0
  36. package/dist/mui/jsx-attributes.js.map +1 -0
  37. package/dist/mui/mark-manual-migration.d.ts +16 -0
  38. package/dist/mui/mark-manual-migration.d.ts.map +1 -0
  39. package/dist/mui/mark-manual-migration.js +73 -0
  40. package/dist/mui/mark-manual-migration.js.map +1 -0
  41. package/dist/mui/mark-palette-mode-usage.d.ts +12 -0
  42. package/dist/mui/mark-palette-mode-usage.d.ts.map +1 -0
  43. package/dist/mui/mark-palette-mode-usage.js +50 -0
  44. package/dist/mui/mark-palette-mode-usage.js.map +1 -0
  45. package/dist/mui/move-component-prop-to-slot.d.ts +22 -0
  46. package/dist/mui/move-component-prop-to-slot.d.ts.map +1 -0
  47. package/dist/mui/move-component-prop-to-slot.js +87 -0
  48. package/dist/mui/move-component-prop-to-slot.js.map +1 -0
  49. package/dist/mui/move-primary-text-to-children.d.ts +12 -0
  50. package/dist/mui/move-primary-text-to-children.d.ts.map +1 -0
  51. package/dist/mui/move-primary-text-to-children.js +52 -0
  52. package/dist/mui/move-primary-text-to-children.js.map +1 -0
  53. package/dist/mui/move-system-props-to-sx.d.ts +16 -0
  54. package/dist/mui/move-system-props-to-sx.d.ts.map +1 -0
  55. package/dist/mui/move-system-props-to-sx.js +122 -0
  56. package/dist/mui/move-system-props-to-sx.js.map +1 -0
  57. package/dist/mui/mui-components.d.ts +8 -0
  58. package/dist/mui/mui-components.d.ts.map +1 -0
  59. package/dist/mui/mui-components.js +41 -0
  60. package/dist/mui/mui-components.js.map +1 -0
  61. package/dist/mui/mui-tag-visitor.d.ts +5 -0
  62. package/dist/mui/mui-tag-visitor.d.ts.map +1 -0
  63. package/dist/mui/mui-tag-visitor.js +54 -0
  64. package/dist/mui/mui-tag-visitor.js.map +1 -0
  65. package/dist/mui/pre-v5-recipe.d.ts +14 -0
  66. package/dist/mui/pre-v5-recipe.d.ts.map +1 -0
  67. package/dist/mui/pre-v5-recipe.js +88 -0
  68. package/dist/mui/pre-v5-recipe.js.map +1 -0
  69. package/dist/mui/remove-component-prop.d.ts +18 -0
  70. package/dist/mui/remove-component-prop.d.ts.map +1 -0
  71. package/dist/mui/remove-component-prop.js +55 -0
  72. package/dist/mui/remove-component-prop.js.map +1 -0
  73. package/dist/mui/remove-root-ref.d.ts +8 -0
  74. package/dist/mui/remove-root-ref.d.ts.map +1 -0
  75. package/dist/mui/remove-root-ref.js +61 -0
  76. package/dist/mui/remove-root-ref.js.map +1 -0
  77. package/dist/mui/remove-spacing-px-suffix.d.ts +8 -0
  78. package/dist/mui/remove-spacing-px-suffix.d.ts.map +1 -0
  79. package/dist/mui/remove-spacing-px-suffix.js +62 -0
  80. package/dist/mui/remove-spacing-px-suffix.js.map +1 -0
  81. package/dist/mui/rename-component-prop.d.ts +20 -0
  82. package/dist/mui/rename-component-prop.d.ts.map +1 -0
  83. package/dist/mui/rename-component-prop.js +66 -0
  84. package/dist/mui/rename-component-prop.js.map +1 -0
  85. package/dist/mui/rename-joy-css-variables.d.ts +8 -0
  86. package/dist/mui/rename-joy-css-variables.d.ts.map +1 -0
  87. package/dist/mui/rename-joy-css-variables.js +51 -0
  88. package/dist/mui/rename-joy-css-variables.js.map +1 -0
  89. package/dist/mui/rename-theme-palette-type.d.ts +8 -0
  90. package/dist/mui/rename-theme-palette-type.d.ts.map +1 -0
  91. package/dist/mui/rename-theme-palette-type.js +61 -0
  92. package/dist/mui/rename-theme-palette-type.js.map +1 -0
  93. package/dist/mui/replace-box-border-radius.d.ts +10 -0
  94. package/dist/mui/replace-box-border-radius.d.ts.map +1 -0
  95. package/dist/mui/replace-box-border-radius.js +50 -0
  96. package/dist/mui/replace-box-border-radius.js.map +1 -0
  97. package/dist/mui/replace-breakpoints-width.d.ts +8 -0
  98. package/dist/mui/replace-breakpoints-width.d.ts.map +1 -0
  99. package/dist/mui/replace-breakpoints-width.js +46 -0
  100. package/dist/mui/replace-breakpoints-width.js.map +1 -0
  101. package/dist/mui/replace-component-class.d.ts +18 -0
  102. package/dist/mui/replace-component-class.d.ts.map +1 -0
  103. package/dist/mui/replace-component-class.js +126 -0
  104. package/dist/mui/replace-component-class.js.map +1 -0
  105. package/dist/mui/replace-components-with-slots.d.ts +14 -0
  106. package/dist/mui/replace-components-with-slots.d.ts.map +1 -0
  107. package/dist/mui/replace-components-with-slots.js +69 -0
  108. package/dist/mui/replace-components-with-slots.js.map +1 -0
  109. package/dist/mui/replace-import-paths.d.ts +14 -0
  110. package/dist/mui/replace-import-paths.d.ts.map +1 -0
  111. package/dist/mui/replace-import-paths.js +101 -0
  112. package/dist/mui/replace-import-paths.js.map +1 -0
  113. package/dist/mui/replace-in-string-literals.d.ts +15 -0
  114. package/dist/mui/replace-in-string-literals.d.ts.map +1 -0
  115. package/dist/mui/replace-in-string-literals.js +62 -0
  116. package/dist/mui/replace-in-string-literals.js.map +1 -0
  117. package/dist/mui/replace-list-item-button-prop.d.ts +12 -0
  118. package/dist/mui/replace-list-item-button-prop.d.ts.map +1 -0
  119. package/dist/mui/replace-list-item-button-prop.js +80 -0
  120. package/dist/mui/replace-list-item-button-prop.js.map +1 -0
  121. package/dist/mui/replace-tabs-scroll-buttons.d.ts +8 -0
  122. package/dist/mui/replace-tabs-scroll-buttons.d.ts.map +1 -0
  123. package/dist/mui/replace-tabs-scroll-buttons.js +41 -0
  124. package/dist/mui/replace-tabs-scroll-buttons.js.map +1 -0
  125. package/dist/mui/replace-theme-color-functions.d.ts +8 -0
  126. package/dist/mui/replace-theme-color-functions.d.ts.map +1 -0
  127. package/dist/mui/replace-theme-color-functions.js +72 -0
  128. package/dist/mui/replace-theme-color-functions.js.map +1 -0
  129. package/dist/mui/replace-theme-spacing-unit.d.ts +8 -0
  130. package/dist/mui/replace-theme-spacing-unit.d.ts.map +1 -0
  131. package/dist/mui/replace-theme-spacing-unit.js +77 -0
  132. package/dist/mui/replace-theme-spacing-unit.js.map +1 -0
  133. package/dist/mui/replace-typography-round.d.ts +8 -0
  134. package/dist/mui/replace-typography-round.d.ts.map +1 -0
  135. package/dist/mui/replace-typography-round.js +44 -0
  136. package/dist/mui/replace-typography-round.js.map +1 -0
  137. package/dist/mui/shift-hidden-down-props.d.ts +10 -0
  138. package/dist/mui/shift-hidden-down-props.d.ts.map +1 -0
  139. package/dist/mui/shift-hidden-down-props.js +49 -0
  140. package/dist/mui/shift-hidden-down-props.js.map +1 -0
  141. package/dist/mui/theme-access.d.ts +5 -0
  142. package/dist/mui/theme-access.d.ts.map +1 -0
  143. package/dist/mui/theme-access.js +21 -0
  144. package/dist/mui/theme-access.js.map +1 -0
  145. package/dist/mui/update-theme-breakpoints.d.ts +10 -0
  146. package/dist/mui/update-theme-breakpoints.d.ts.map +1 -0
  147. package/dist/mui/update-theme-breakpoints.js +58 -0
  148. package/dist/mui/update-theme-breakpoints.js.map +1 -0
  149. package/dist/mui/upgrade-grid-props.d.ts +16 -0
  150. package/dist/mui/upgrade-grid-props.d.ts.map +1 -0
  151. package/dist/mui/upgrade-grid-props.js +90 -0
  152. package/dist/mui/upgrade-grid-props.js.map +1 -0
  153. package/dist/search/find-enzyme-usage.d.ts +4 -0
  154. package/dist/search/find-enzyme-usage.d.ts.map +1 -1
  155. package/dist/search/find-enzyme-usage.js +91 -7
  156. package/dist/search/find-enzyme-usage.js.map +1 -1
  157. package/dist/testing/enzyme-host-components.d.ts +12 -0
  158. package/dist/testing/enzyme-host-components.d.ts.map +1 -1
  159. package/dist/testing/enzyme-host-components.js +100 -0
  160. package/dist/testing/enzyme-host-components.js.map +1 -1
  161. package/dist/testing/enzyme-render-blockers.d.ts +13 -4
  162. package/dist/testing/enzyme-render-blockers.d.ts.map +1 -1
  163. package/dist/testing/enzyme-render-blockers.js +162 -6
  164. package/dist/testing/enzyme-render-blockers.js.map +1 -1
  165. package/dist/testing/enzyme-to-react-testing-library.d.ts +9 -2
  166. package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
  167. package/dist/testing/enzyme-to-react-testing-library.js +163 -16
  168. package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
  169. package/dist/testing/enzyme-usage.d.ts +7 -0
  170. package/dist/testing/enzyme-usage.d.ts.map +1 -1
  171. package/dist/testing/enzyme-usage.js +8 -1
  172. package/dist/testing/enzyme-usage.js.map +1 -1
  173. package/dist/testing/enzyme-wrapper-scope.d.ts +8 -5
  174. package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
  175. package/dist/testing/enzyme-wrapper-scope.js +16 -4
  176. package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
  177. package/dist/zustand/redux-stores.d.ts +2 -0
  178. package/dist/zustand/redux-stores.d.ts.map +1 -1
  179. package/dist/zustand/redux-stores.js +120 -6
  180. package/dist/zustand/redux-stores.js.map +1 -1
  181. package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
  182. package/dist/zustand/redux-to-zustand.js +10 -4
  183. package/dist/zustand/redux-to-zustand.js.map +1 -1
  184. package/dist/zustand/zustand-plan.d.ts +7 -0
  185. package/dist/zustand/zustand-plan.d.ts.map +1 -1
  186. package/dist/zustand/zustand-plan.js +141 -21
  187. package/dist/zustand/zustand-plan.js.map +1 -1
  188. package/package.json +1 -1
  189. package/src/index.ts +10 -0
  190. package/src/mui/adapt-v4-theme.ts +43 -0
  191. package/src/mui/add-component-prop.ts +43 -0
  192. package/src/mui/add-emotion-prepend.ts +48 -0
  193. package/src/mui/change-module-specifier.ts +71 -0
  194. package/src/mui/convert-mui-imports.ts +184 -0
  195. package/src/mui/convert-prop-to-sx.ts +89 -0
  196. package/src/mui/index.ts +31 -0
  197. package/src/mui/jsx-attributes.ts +133 -0
  198. package/src/mui/mark-manual-migration.ts +53 -0
  199. package/src/mui/mark-palette-mode-usage.ts +36 -0
  200. package/src/mui/move-component-prop-to-slot.ts +84 -0
  201. package/src/mui/move-primary-text-to-children.ts +41 -0
  202. package/src/mui/move-system-props-to-sx.ts +118 -0
  203. package/src/mui/mui-components.ts +40 -0
  204. package/src/mui/mui-tag-visitor.ts +36 -0
  205. package/src/mui/pre-v5-recipe.ts +82 -0
  206. package/src/mui/remove-component-prop.ts +43 -0
  207. package/src/mui/remove-root-ref.ts +41 -0
  208. package/src/mui/remove-spacing-px-suffix.ts +43 -0
  209. package/src/mui/rename-component-prop.ts +55 -0
  210. package/src/mui/rename-joy-css-variables.ts +41 -0
  211. package/src/mui/rename-theme-palette-type.ts +42 -0
  212. package/src/mui/replace-box-border-radius.ts +42 -0
  213. package/src/mui/replace-breakpoints-width.ts +28 -0
  214. package/src/mui/replace-component-class.ts +97 -0
  215. package/src/mui/replace-components-with-slots.ts +61 -0
  216. package/src/mui/replace-import-paths.ts +100 -0
  217. package/src/mui/replace-in-string-literals.ts +44 -0
  218. package/src/mui/replace-list-item-button-prop.ts +59 -0
  219. package/src/mui/replace-tabs-scroll-buttons.ts +31 -0
  220. package/src/mui/replace-theme-color-functions.ts +55 -0
  221. package/src/mui/replace-theme-spacing-unit.ts +59 -0
  222. package/src/mui/replace-typography-round.ts +29 -0
  223. package/src/mui/shift-hidden-down-props.ts +44 -0
  224. package/src/mui/theme-access.ts +18 -0
  225. package/src/mui/update-theme-breakpoints.ts +47 -0
  226. package/src/mui/upgrade-grid-props.ts +82 -0
  227. package/src/search/find-enzyme-usage.ts +80 -7
  228. package/src/testing/enzyme-host-components.ts +110 -0
  229. package/src/testing/enzyme-render-blockers.ts +174 -9
  230. package/src/testing/enzyme-to-react-testing-library.ts +159 -25
  231. package/src/testing/enzyme-usage.ts +13 -0
  232. package/src/testing/enzyme-wrapper-scope.ts +27 -6
  233. package/src/zustand/redux-stores.ts +119 -5
  234. package/src/zustand/redux-to-zustand.ts +12 -5
  235. package/src/zustand/zustand-plan.ts +159 -18
@@ -1,6 +1,6 @@
1
1
  import {Cursor, DataTable, emptyMarkers, ExecutionContext, Markup, MarkersKind, Option, or, randomId, ScanningRecipe, SourceFile, Tree, TreePrinters, TreeVisitor} from "@openrewrite/rewrite";
2
2
  import {
3
- AddDependencyOptions, autoFormat, ChangeImport, findNodeResolutionResult, isVendoredOrBundled, JavaScriptVisitor, JS, JSX, maybeAddImport, maybeRemoveImport, raw, template
3
+ AddDependencyOptions, autoFormat, ChangeImport, findNodeResolutionResult, isVendoredOrBundled, JavaScriptVisitor, JS, JSX, maybeAddImport, maybeRemoveImport, namesReferencedWithin, raw, template
4
4
  } from "@openrewrite/rewrite/javascript";
5
5
  import {emptySpace, isIdentifier, J, Statement} from "@openrewrite/rewrite/java";
6
6
  import {Json, JsonVisitor} from "@openrewrite/rewrite/json";
@@ -11,7 +11,7 @@ import {JavaDependencyRecipe, treesOfType} from "../util/java-recipe-proxy";
11
11
  import {addPathsConfig, importBindings, isAliasSpecifier, PathsConfigs, Resolve, resolveModule} from "../util/module-imports";
12
12
  import {rewriteVersion, supportsResolvingGate} from "../testing/enzyme-to-react-testing-library";
13
13
  import {ENTRY_STORE_MODULE, EntrySplit, splitEntryStore} from "./entry-store";
14
- import {caseReducers, Finding, importedAs, legacyEnhancer, localSlices, objectProperties, preloadedValue, REDUX_STORES_TABLE, ReduxStoreRow, REDUX, RTK, SliceModule, storeFunctions, SUGGESTED_ACTIONS, TEST_SOURCE} from "./redux-stores";
14
+ import {caseReducers, Finding, importedAs, legacyEnhancer, localSlices, objectProperties, preloadedValue, withoutEffects, REDUX_STORES_TABLE, ReduxStoreRow, REDUX, RTK, SliceModule, storeFunctions, SUGGESTED_ACTIONS, TEST_SOURCE} from "./redux-stores";
15
15
  import {
16
16
  actionsExport, argumentsOf, dispatchedAction, getStateRead, isDispatcherDeclaration, isReactDependencies, isReducerExport, parentTree, Plan, planPackages, PlannedSlice, providerChild, providerChildren,
17
17
  REACT_REDUX, readSelector, relativeSpecifier, selectorRead, sliceSource, SliceSource, SourceFacts, sourceFacts, StoreFacts, storeFacts
@@ -480,7 +480,8 @@ export class ReduxToZustand extends ScanningRecipe<Scanned> {
480
480
  if (react === undefined || react < 16 || react === 16 && (minVersion(facts.react!)?.minor ?? 0) < 8) return {reason: "REACT_VERSION", detail: facts.react ?? "react not declared"};
481
481
  // A package the steps weren't asked to change keeps its store for another reason, recorded already
482
482
  const refusal = !forecast ? this.forecast.refused?.get(root) : undefined;
483
- if (refusal) return {reason: "DEPENDENCY", detail: `zustand isn't added: ${refusal.message}`};
483
+ if (refusal) return {reason: "DEPENDENCY", detail: `zustand isn't added: ${refusal.message}`,
484
+ action: `The recipe adds \`zustand\` and \`immer\` only where it can write the lockfile the package manager would, which the detail says it can't here: add \`zustand\` ${(react >= 18 ? ZUSTAND_5 : ZUSTAND_4).version} and \`immer\` ${IMMER_10.version} to the package yourself, with its own package manager, and run the recipe again.`};
484
485
  const landed = (step: ZustandDependency | undefined) => forecast || !this.asked?.has(root) && this.asked !== undefined ? !!this.steps : !!step?.landed.has(root);
485
486
  const zustand = facts.zustand !== undefined ? (major(facts.zustand) ?? 0) >= (react >= 18 ? 4 : 4) && (react >= 18 || major(facts.zustand) === 4)
486
487
  : landed(react >= 18 ? this.steps?.zustand : this.steps?.zustand4);
@@ -919,8 +920,14 @@ function storeStatement(cu: JS.CompilationUnit, store: StoreFacts): {index: numb
919
920
  // NOTE: the arguments are moved into new calls, so they drop the line breaks they had in the store's call
920
921
  return {index, call, reducer: {...args[0], prefix: emptySpace}, preloaded: preloaded && {...preloaded, prefix: emptySpace}, consts: enhancer && !("unsupported" in enhancer) ? enhancer.consts : new Set()};
921
922
  }
922
- const reducer = objectProperties(argumentsOf(call)[0])?.get("reducer");
923
- return reducer ? {index, call, reducer} : undefined;
923
+ const options = objectProperties(argumentsOf(call)[0]);
924
+ const reducer = options?.get("reducer");
925
+ // The development-only options go with the call, and so may the `const`s only they read, unless making one has effects
926
+ const effectful = new Set(cu.statements.map(padded => padded.element).filter(s => s.kind === J.Kind.VariableDeclarations)
927
+ .flatMap(s => (s as J.VariableDeclarations).variables.map(v => v.element))
928
+ .filter(v => isIdentifier(v.name) && v.initializer && !withoutEffects(v.initializer.element)).map(v => (v.name as J.Identifier).simpleName));
929
+ const consts = new Set([...options ?? []].filter(([key]) => key !== "reducer").flatMap(([, value]) => [...namesReferencedWithin(value)]).filter(name => !effectful.has(name)));
930
+ return reducer ? {index, call, reducer, consts} : undefined;
924
931
  }
925
932
  return undefined;
926
933
  }
@@ -3,7 +3,7 @@ import {JavaScriptVisitor, JS, JSX, namesReferencedWithin} from "@openrewrite/re
3
3
  import {isIdentifier, J} from "@openrewrite/rewrite/java";
4
4
  import {posix} from "path";
5
5
  import {ImportBinding, importBindings, isAliasSpecifier, isRelativeSpecifier, Resolve, resolveRelative} from "../util/module-imports";
6
- import {Finding, localSlices, ReducerStoreKind, objectProperties, RTK, SliceFacts, SliceModule, storeFindings, storeFunctions, TEST_SOURCE} from "./redux-stores";
6
+ import {Finding, importedAs, localSlices, ReducerStoreKind, objectProperties, RTK, SliceFacts, SliceModule, storeFindings, storeFunctions, TEST_SOURCE} from "./redux-stores";
7
7
 
8
8
  export const REACT_REDUX = "react-redux";
9
9
 
@@ -47,6 +47,58 @@ export interface Use {
47
47
  anySelector?: boolean;
48
48
  /** What to do about an `other` use, for the review row, where it says more than its reason's action. */
49
49
  action?: string;
50
+ /** For an `other` use of an import as a value, how it is used, which says what to do where the import is the store. */
51
+ valueUse?: StoreValueUse;
52
+ }
53
+
54
+ /** How a source uses the store's variable as a value, other than to call `getState`, `dispatch` or `subscribe`. */
55
+ export interface StoreValueUse {
56
+ kind: "type" | "persist" | "passed" | "provider" | "method" | "member" | "other";
57
+ /** The function the store is passed to, or the member called or used. */
58
+ name?: string;
59
+ }
60
+
61
+ /** How the identifier at `cursor`, the store's variable, is used, where it is used other than to call a member of `STORE_MEMBERS`. */
62
+ function storeValueUse(identifier: J.Identifier, cursor: Cursor, persistStore: ReadonlySet<string>): StoreValueUse {
63
+ const trees = ancestors(cursor);
64
+ if (trees.some(tree => tree.kind === JS.Kind.TypeQuery)) return {kind: "type"};
65
+ const parent = parentTree(cursor);
66
+ if (parent?.kind === J.Kind.MethodInvocation) {
67
+ const call = parent as J.MethodInvocation;
68
+ if (call.select?.element === identifier) return {kind: "method", name: call.name.simpleName};
69
+ if (argumentsOf(call).includes(identifier)) {
70
+ if (!call.select && persistStore.has(call.name.simpleName)) return {kind: "persist"};
71
+ const select = call.select && isIdentifier(call.select.element) ? `${call.select.element.simpleName}.` : "";
72
+ return {kind: "passed", name: select + call.name.simpleName};
73
+ }
74
+ }
75
+ if (parent?.kind === J.Kind.FieldAccess && (parent as J.FieldAccess).target === identifier && STORE_MEMBERS.has((parent as J.FieldAccess).name.element.simpleName)) {
76
+ return {kind: "member", name: (parent as J.FieldAccess).name.element.simpleName};
77
+ }
78
+ if (parent?.kind === JS.Kind.JsxEmbeddedExpression && trees[2]?.kind === JS.Kind.JsxAttribute && isIdentifier((trees[2] as JSX.Attribute).key) &&
79
+ ((trees[2] as JSX.Attribute).key as J.Identifier).simpleName === "store") return {kind: "provider"};
80
+ return {kind: "other"};
81
+ }
82
+
83
+ /** The calls of a member of the store that stand in for passing the member, by name. */
84
+ const MEMBER_CALLS: Readonly<Record<string, string>> = {getState: "() => STORE.getState()", dispatch: "action => STORE.dispatch(action)", subscribe: "listener => STORE.subscribe(listener)"};
85
+
86
+ /** What to do about the uses of the store `store` as a value, or undefined where none says more than the reason's action does. */
87
+ export function storeValueAction(store: string, uses: readonly StoreValueUse[]): string | undefined {
88
+ if (uses.some(use => use.kind === "persist")) 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.`;
89
+ const first = (kind: StoreValueUse["kind"]) => uses.find(use => use.kind === kind);
90
+ const actions: string[] = [];
91
+ if (first("type")) actions.push(`\`typeof ${store}\` types, such as \`ReturnType<typeof ${store}.getState>\`, go with the TypeScript sources, which aren't converted yet.`);
92
+ const passed = first("passed");
93
+ // A test's spy on a member of the Redux store watches a store the conversion replaces
94
+ if (passed && /(^|\.)spyOn$/.test(passed.name!)) 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.`);
95
+ else if (passed) 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.`);
96
+ const member = first("member");
97
+ if (member) 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.`);
98
+ const method = first("method");
99
+ if (method) actions.push(`The zustand store has no \`${method.name}\`: remove \`${store}.${method.name}(...)\`, or convert by hand.`);
100
+ if (first("provider")) actions.push(`Render \`<Provider store={${store}}>\` in a module that imports the store, not in the store's own source.`);
101
+ return actions.length > 0 ? actions.join(" ") : undefined;
50
102
  }
51
103
 
52
104
  /** What to do with an import of react-redux used other than called, by its name. */
@@ -63,6 +115,23 @@ const REACT_REDUX_CALL_ACTIONS: Readonly<Record<string, string>> = {
63
115
  useStore: "Read the state with `useSelector` and dispatch with `useDispatch` instead of `useStore()`, or convert by hand."
64
116
  };
65
117
 
118
+ /** What to do with a `useSelector` whose selector doesn't read one slice's state, by its arguments. */
119
+ function selectorAction(args: number, typed: boolean): string {
120
+ if (typed) return "A `useSelector` with type arguments goes with the TypeScript sources, which aren't converted yet.";
121
+ if (args !== 1) 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.";
122
+ 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.";
123
+ }
124
+
125
+ /** What to do with a use checked against the store's slices, which aren't read while the store has findings of its own. */
126
+ 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.";
127
+
128
+ /** What to do with a dispatch of an import that isn't an action creator or thunk of the store's slices, by whether its source declares a slice. */
129
+ function sliceDispatchAction(binding: ImportBinding, fromSlice: boolean): string {
130
+ return fromSlice ?
131
+ `\`${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.` :
132
+ `\`${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.`;
133
+ }
134
+
66
135
  /** What to do with a `connect` of a store that can't move whole, which only a store moving whole declares. */
67
136
  export function connectAction(wholeStores: boolean): string {
68
137
  return wholeStores ?
@@ -70,6 +139,33 @@ export function connectAction(wholeStores: boolean): string {
70
139
  "`connect` converts only where the store moves whole, which `wholeStores` turns off: run with it on, or replace `connect` with `useSelector` and `useDispatch`.";
71
140
  }
72
141
 
142
+ /** What to do with an import of the store's source other than the store, which the slice plan removes with the source. */
143
+ function storeExportAction(binding: ImportBinding, source: SourceFacts, store: StoreFacts, storeModule: SourceFacts | undefined, wholeStores: boolean): string {
144
+ // A default import is named by its local name, as the source writes it
145
+ const name = binding.name === "default" ? binding.local : binding.name;
146
+ if (/^use[A-Z]/.test(name)) 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.`;
147
+ if (/^[A-Z]/.test(name) && source.typescript) 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.`;
148
+ if (/persist/i.test(name) && storeModule?.bindings.some(b => b.module === "redux-persist")) 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.`;
149
+ // A store made by a function, such as `initStore`, is no store until it's called
150
+ if (!store.exportedAs && (name === store.store || /store/i.test(name))) 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.`;
151
+ 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.` +
152
+ (wholeStores && store.exportedAs ? ` Or remove what the store's other rows name, so that it moves whole and its source keeps \`${name}\`.` : "");
153
+ }
154
+
155
+ /** What to do with a store of a package that creates more than one, by how many of them are created outside tests. */
156
+ function multipleStoresAction(store: StoreFacts, stores: readonly StoreFacts[], facts: ReadonlyMap<string, SourceFacts>): string {
157
+ const app = stores.filter(s => !facts.get(s.path)?.test);
158
+ const why = "the recipe converts a package of one store, as react-redux's hooks don't say which store they read";
159
+ if (app.length === 0) return `All ${stores.length} of the package's stores are created in test, mock or story sources: ${why}. Convert by hand.`;
160
+ if (app.length === 1) {
161
+ const one = app[0] === store ? "this store" : `its one other store, \`${app[0].store}\` of ${app[0].path}`;
162
+ 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.`;
163
+ }
164
+ const paths = [...new Set(app.map(s => s.path))];
165
+ const named = paths.length > 3 ? `${paths.slice(0, 3).join(", ")} and ${paths.length - 3} more` : paths.join(", ");
166
+ 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.`;
167
+ }
168
+
73
169
  /** What one source tells the plan. */
74
170
  export interface SourceFacts {
75
171
  path: string;
@@ -105,6 +201,8 @@ export interface StoreFacts {
105
201
  reducerStore?: ReducerStoreKind;
106
202
  /** Whether the store's own source uses the store other than to declare and export it, or to call its `getState`, `dispatch` or `subscribe`. */
107
203
  usedInSource?: boolean;
204
+ /** How the store's own source uses it, where `usedInSource`. */
205
+ usesInSource?: readonly StoreValueUse[];
108
206
  /** The members of the store its own source calls, such as `subscribe`. */
109
207
  calledInSource?: ReadonlySet<string>;
110
208
  }
@@ -285,6 +383,7 @@ export async function sourceFacts(cu: JS.CompilationUnit): Promise<SourceFacts>
285
383
  // A specifier no package can have, such as `@/store`, may name a source through an alias, which the plan resolves
286
384
  const followed = new Map(bindings.filter(binding => binding.module === REACT_REDUX || isRelativeSpecifier(binding.module) || isAliasSpecifier(binding.module))
287
385
  .map(binding => [binding.local, binding]));
386
+ const persistStore = new Set(bindings.filter(b => b.module === "redux-persist" && b.name === "persistStore").map(b => b.local));
288
387
  for (const {element} of cu.statements) {
289
388
  if (element.kind === JS.Kind.Import) {
290
389
  const imp = element as JS.Import;
@@ -319,7 +418,7 @@ export async function sourceFacts(cu: JS.CompilationUnit): Promise<SourceFacts>
319
418
  if (use) facts.uses.push(use);
320
419
  }
321
420
  if (binding) {
322
- const use = classify(identifier, binding, this.cursor, followed, dispatchers, declared);
421
+ const use = classify(identifier, binding, this.cursor, followed, dispatchers, declared, persistStore);
323
422
  if (use) facts.uses.push(use);
324
423
  }
325
424
  return identifier;
@@ -349,7 +448,7 @@ export async function storeFacts(cu: JS.CompilationUnit, modules: ReadonlyMap<st
349
448
  const name = storeNameAt(this.cursor);
350
449
  const own = await usesInSource(cu, name, call);
351
450
  stores.push({path: cu.sourcePath, api: store.api, store: name, findings: store.findings,
352
- slices: store.slices, exportedAs: exportedStore(cu, this.cursor), reducerStore: store.reducerStore, usedInSource: own.other, calledInSource: own.called});
451
+ slices: store.slices, exportedAs: exportedStore(cu, this.cursor), reducerStore: store.reducerStore, usedInSource: own.other, usesInSource: own.uses, calledInSource: own.called});
353
452
  }
354
453
  return super.visitMethodInvocation(call, ctx);
355
454
  }
@@ -390,7 +489,7 @@ function dispatcherCount(cu: JS.CompilationUnit, followed: ReadonlyMap<string, I
390
489
 
391
490
  /** How the identifier at `cursor`, which names the import `binding`, is used; undefined where it is no use, such as a property name. */
392
491
  function classify(identifier: J.Identifier, binding: ImportBinding, cursor: Cursor, followed: ReadonlyMap<string, ImportBinding>,
393
- dispatchers: ReadonlySet<string>, declared: ReadonlyMap<string, number>): Use | undefined {
492
+ dispatchers: ReadonlySet<string>, declared: ReadonlyMap<string, number>, persistStore: ReadonlySet<string>): Use | undefined {
394
493
  const trees = ancestors(cursor);
395
494
  if (trees.some(tree => tree.kind === JS.Kind.Import)) return undefined;
396
495
  const parent = parentTree(cursor);
@@ -422,7 +521,7 @@ function classify(identifier: J.Identifier, binding: ImportBinding, cursor: Curs
422
521
  if (read) return {local, kind: "selector", key: read.key};
423
522
  // A selector passed by name moves only with its whole store, which calls it as it is
424
523
  const selector = args.length === 1 && !call.typeParameters && isIdentifier(args[0]) ? args[0].simpleName : undefined;
425
- return {...other("a selector that isn't a read of one slice's state"), reason: "SELECTOR", selector, anySelector: args.length === 1 && !call.typeParameters};
524
+ return {...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};
426
525
  }
427
526
  if (binding.name === "useDispatch") {
428
527
  const variable = parentTree(cursorOf(cursor, call));
@@ -454,7 +553,10 @@ function classify(identifier: J.Identifier, binding: ImportBinding, cursor: Curs
454
553
  if (member === "dispatch" && dispatchedAction(call)) {
455
554
  return isStatement(call, outer) ? {local, kind: "storeDispatch", member} : {...other("the dispatch's result is used"), reason: "DISPATCH", member};
456
555
  }
457
- return {...other(`\`${local}.${member}\``), member};
556
+ 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.` :
557
+ member === "dispatch" ? unimportedDispatchAction(call, undefined, `${local}.dispatch`) :
558
+ member === "subscribe" ? `\`${local}.subscribe\` converts only where the store moves whole: remove what the store's other rows name, or convert by hand.` : undefined;
559
+ return {...other(`\`${local}.${member}\``, action), member};
458
560
  }
459
561
  if (parent?.kind === JS.Kind.JsxEmbeddedExpression) {
460
562
  const attribute = trees[2];
@@ -466,7 +568,9 @@ function classify(identifier: J.Identifier, binding: ImportBinding, cursor: Curs
466
568
  if (provider?.module === REACT_REDUX && provider.name === "Provider") return {local, kind: "provider"};
467
569
  }
468
570
  }
469
- return other("referenced");
571
+ // NOTE: a `store` attribute of a tag other than react-redux's `Provider` says nothing of where to render it
572
+ const valueUse = storeValueUse(identifier, cursor, persistStore);
573
+ return {...other("referenced"), valueUse: valueUse.kind === "provider" ? {kind: "other"} : valueUse};
470
574
  }
471
575
 
472
576
  /** Why a call of `connect` can't move to the zustand store's own `connect`, if it can't. */
@@ -488,6 +592,22 @@ function connectUse(call: J.MethodInvocation, other: (detail: string, action?: s
488
592
  return undefined;
489
593
  }
490
594
 
595
+ /** What to do with `dispatch(x)` whose `x` isn't a call of an imported action creator, by what `x` is. */
596
+ function unimportedDispatchAction(dispatch: J.MethodInvocation, action: J.MethodInvocation | undefined, name = dispatch.name.simpleName): string {
597
+ const [arg] = argumentsOf(dispatch);
598
+ if (action) {
599
+ 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.`;
600
+ }
601
+ if (arg?.kind === J.Kind.MethodInvocation && (arg as J.MethodInvocation).select) {
602
+ const member = (arg as J.MethodInvocation).name.simpleName;
603
+ 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.`;
604
+ }
605
+ if (objectProperties(arg)) {
606
+ 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.`;
607
+ }
608
+ 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.`;
609
+ }
610
+
491
611
  /** A use of a dispatcher from `useDispatch`: only `dispatch(x(...))` of an imported `x`, whose result is unused, converts. */
492
612
  function dispatcherUse(identifier: J.Identifier, cursor: Cursor, followed: ReadonlyMap<string, ImportBinding>,
493
613
  bindings: readonly ImportBinding[]): Use | undefined {
@@ -502,7 +622,7 @@ function dispatcherUse(identifier: J.Identifier, cursor: Cursor, followed: Reado
502
622
  const action = dispatchedAction(call);
503
623
  const binding = action && followed.get(action.name.simpleName);
504
624
  if (binding && binding.module !== REACT_REDUX) return undefined;
505
- return {local, kind: "other", detail: "dispatches what isn't an imported action creator", reason: "DISPATCH"};
625
+ return {local, kind: "other", detail: "dispatches what isn't an imported action creator", reason: "DISPATCH", action: unimportedDispatchAction(call, action)};
506
626
  }
507
627
  return {local, kind: "other", detail: "the dispatcher is used other than to dispatch", reason: "DISPATCH"};
508
628
  }
@@ -552,8 +672,9 @@ export const STORE_MEMBERS: ReadonlySet<string> = new Set(["getState", "dispatch
552
672
  * How the statements of `cu` other than the store's declaration, `call`, and `export default name` refer to the store's
553
673
  * variable: the members of `STORE_MEMBERS` they call on it, and whether they refer to it any other way.
554
674
  */
555
- async function usesInSource(cu: JS.CompilationUnit, name: string, call: J.MethodInvocation): Promise<{other: boolean, called: Set<string>}> {
556
- const result = {other: false, called: new Set<string>()};
675
+ async function usesInSource(cu: JS.CompilationUnit, name: string, call: J.MethodInvocation): Promise<{other: boolean, uses: StoreValueUse[], called: Set<string>}> {
676
+ const result = {other: false, uses: [] as StoreValueUse[], called: new Set<string>()};
677
+ const persistStore = importedAs(cu, "redux-persist", "persistStore");
557
678
  const statements = cu.statements.map(s => s.element).flatMap(statement => {
558
679
  if (statement.kind === JS.Kind.Import) return [];
559
680
  // Exporting the store by name, which `exportedStore` reads, is no use of it
@@ -583,6 +704,7 @@ async function usesInSource(cu: JS.CompilationUnit, name: string, call: J.Method
583
704
  if (parent?.kind === JS.Kind.PropertyAssignment && (parent as JS.PropertyAssignment).name.element === identifier &&
584
705
  (parent as JS.PropertyAssignment).initializer) return identifier;
585
706
  result.other = true;
707
+ result.uses.push(storeValueUse(identifier, this.cursor, persistStore));
586
708
  return identifier;
587
709
  }
588
710
  }().visit(statement, new ExecutionContext());
@@ -701,7 +823,7 @@ export function plan(facts: ReadonlyMap<string, SourceFacts>, sliceSources: Read
701
823
  const result: Plan = {slices: new Map(), sources: new Set(), blocked: new Map()};
702
824
  if (stores.length === 0) return result;
703
825
  if (stores.length > 1) {
704
- for (const store of stores) result.blocked.set(store, [...store.findings, {reason: "MULTIPLE_STORES", detail: `${stores.length} stores`}]);
826
+ for (const store of stores) result.blocked.set(store, [...store.findings, {reason: "MULTIPLE_STORES", detail: `${stores.length} stores`, action: multipleStoresAction(store, stores, facts)}]);
705
827
  return result;
706
828
  }
707
829
  const store = stores[0];
@@ -710,6 +832,8 @@ export function plan(facts: ReadonlyMap<string, SourceFacts>, sliceSources: Read
710
832
  // Slices that stay in Redux for a reason of their own, already recorded: their uses add nothing to it
711
833
  const held = new Map<string, string>();
712
834
  const handled = new Map<string, string>();
835
+ // The slices are read only for a store with no findings of its own, so a use checked against them is unchecked otherwise
836
+ const slicesRead = findings.length === 0;
713
837
  if (findings.length === 0) {
714
838
  if (!store.exportedAs) block("STORE_NOT_MODULE_LEVEL", store.store);
715
839
  const storeSource = sliceSources.get(store.path);
@@ -753,6 +877,7 @@ export function plan(facts: ReadonlyMap<string, SourceFacts>, sliceSources: Read
753
877
  }
754
878
  }
755
879
  const slicePaths = new Map([...result.slices.values()].map(slice => [slice.path, slice]));
880
+ const storeModule = facts.get(store.path);
756
881
  const sources = new Set<string>([store.path, ...slicePaths.keys()]);
757
882
  for (const source of facts.values()) {
758
883
  const resolve = (module: string) => resolveFrom(source.path, module);
@@ -797,12 +922,26 @@ export function plan(facts: ReadonlyMap<string, SourceFacts>, sliceSources: Read
797
922
  const where = `${use.local} in ${source.path}`;
798
923
  if (use.kind === "providerTag" && !provides(source, use, store, resolve)) block("REACT_REDUX_USE", `${where}: \`Provider\` of \`${use.via}\`, which isn't the store`, PROVIDER_OTHER_STORE);
799
924
  if (use.kind === "other") {
800
- block(use.reason ?? (isStore ? "STORE_USE" : slice ? "SLICE_USE" : !binding ? "DISPATCH" : isReactRedux ? "REACT_REDUX_USE" : "STORE_USE"), `${where}: ${use.detail}`, use.action);
925
+ // A store that moves whole runs any selector of one argument as it is, and dispatches any action as Redux does
926
+ 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." :
927
+ use.reason === "DISPATCH" ? " Or remove what the store's other rows name, so that it moves whole and dispatches it as Redux does." : "";
928
+ const reason = use.reason ?? (isStore ? "STORE_USE" : slice ? "SLICE_USE" : !binding ? "DISPATCH" : isReactRedux ? "REACT_REDUX_USE" : "STORE_USE");
929
+ // A store that moves whole calls its own `getState` and `dispatch` as they are
930
+ const member = isStore && (use.member === "getState" || use.member === "dispatch") && wholeStores ?
931
+ ` Or remove what the store's other rows name, so that it moves whole and calls \`${use.member}\` as Redux does.` : "";
932
+ const action = binding && path === store.path && !isStore && reason === "STORE_USE" ? storeExportAction(binding, source, store, storeModule, wholeStores) :
933
+ isStore && use.valueUse ? storeValueAction(use.local, [use.valueUse]) : use.action && use.action + whole + member;
934
+ block(reason, `${where}: ${use.detail}`, action);
801
935
  } else if (use.kind === "selector" || use.kind === "getState") {
802
- if (!result.slices.has(use.key!)) block("SELECTOR", `${where} reads \`${use.key}\`, which is no slice of the store`);
936
+ if (!result.slices.has(use.key!)) {
937
+ block("SELECTOR", `${where} reads \`${use.key}\`, which is no slice of the store`,
938
+ !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\`.`);
939
+ }
803
940
  } else if (use.kind === "dispatched") {
804
941
  // An import without a reducer is recorded once, as UNKNOWN_ACTION
805
- if (!slice || !binding || !slice.actions.has(binding.name) && !slice.unknown.has(binding.name) && !slice.thunkVariables.has(binding.name)) block("DISPATCH", `${where} dispatches what isn't an action creator of a slice`);
942
+ if (!slice || !binding || !slice.actions.has(binding.name) && !slice.unknown.has(binding.name) && !slice.thunkVariables.has(binding.name)) {
943
+ block("DISPATCH", `${where} dispatches what isn't an action creator of a slice`, slicesRead ? binding && sliceDispatchAction(binding, slice !== undefined) : UNREAD_SLICES);
944
+ }
806
945
  const via = source.bindings.find(b => b.local === use.via);
807
946
  if (via && !(resolve(via.module) === store.path && via.name === store.exportedAs)) block("DISPATCH", `${where} is dispatched through \`${use.via}\``);
808
947
  } else if (use.kind === "connect") {
@@ -812,13 +951,13 @@ export function plan(facts: ReadonlyMap<string, SourceFacts>, sliceSources: Read
812
951
  }
813
952
  // An `other` use is recorded above with what it was
814
953
  if (slice && use.kind !== "dispatched" && use.kind !== "other") block("SLICE_USE", `${where}: ${use.kind}`);
815
- if (path === store.path && !isStore && source.path !== store.path) block("STORE_USE", `${where} imports more of the store's source`);
954
+ if (path === store.path && !isStore && source.path !== store.path) block("STORE_USE", `${where} imports more of the store's source`, binding && storeExportAction(binding, source, store, storeModule, wholeStores));
816
955
  }
817
956
  // The store's source is removed, so each import of it goes too, even one nothing uses
818
957
  for (const binding of source.bindings) {
819
958
  if (source.path === store.path || binding.module === REACT_REDUX || resolve(binding.module) !== store.path) continue;
820
959
  changes = true;
821
- if (binding.name !== store.exportedAs) block("STORE_USE", `${binding.local} in ${source.path} imports more of the store's source`);
960
+ if (binding.name !== store.exportedAs) block("STORE_USE", `${binding.local} in ${source.path} imports more of the store's source`, storeExportAction(binding, source, store, storeModule, wholeStores));
822
961
  }
823
962
  if (changes && source.path !== store.path) {
824
963
  if (source.typescript) block("TYPESCRIPT", source.path);
@@ -859,7 +998,8 @@ function reducerPlan(facts: ReadonlyMap<string, SourceFacts>, sliceSources: Read
859
998
  const names = new Set<string>([...sliceSources.get(store.path)?.names ?? [], ...source?.declared ?? [], ...source?.bindings.map(b => b.local) ?? []]);
860
999
  const reducer = ["rootReducer", "appReducer", "storeReducer"].find(name => !names.has(name)) ?? "rootReducer";
861
1000
  if (!store.exportedAs) block("STORE_NOT_MODULE_LEVEL", store.store);
862
- if (store.usedInSource) block("STORE_USE", `\`${store.store}\` is used in its own source`);
1001
+ if (store.usedInSource) block("STORE_USE", `\`${store.store}\` is used in its own source`, storeValueAction(store.store, store.usesInSource ?? []) ??
1002
+ `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.`);
863
1003
  const dependency = dependencies(store.path, false);
864
1004
  if (dependency) findings.push(dependency);
865
1005
  for (const name of [hook, reducer, "create"]) if (names.has(name)) block("NAME_TAKEN", `${name} in ${store.path}`);
@@ -910,7 +1050,8 @@ function reducerPlan(facts: ReadonlyMap<string, SourceFacts>, sliceSources: Read
910
1050
  if (path !== store.path || binding.name !== store.exportedAs) continue;
911
1051
  if (use.kind === "provider") changes = true;
912
1052
  else if (use.kind === "other" && use.member === "subscribe") subscribes = true;
913
- else if (use.kind === "other" && use.member !== "getState" && use.member !== "dispatch") block(use.reason === "DISPATCH" ? "STORE_USE" : use.reason ?? "STORE_USE", `${where}: ${use.detail}`);
1053
+ else if (use.kind === "other" && use.member !== "getState" && use.member !== "dispatch") block(use.reason === "DISPATCH" ? "STORE_USE" : use.reason ?? "STORE_USE", `${where}: ${use.detail}`,
1054
+ use.valueUse && storeValueAction(use.local, [use.valueUse]));
914
1055
  }
915
1056
  if (changes && source.path !== store.path) {
916
1057
  if (source.typescript) block("TYPESCRIPT", source.path);