@openrewrite/recipes-react 0.18.0 → 0.20.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 (48) hide show
  1. package/dist/react19/no-implicit-ref-callback-return.d.ts.map +1 -1
  2. package/dist/react19/no-implicit-ref-callback-return.js +25 -5
  3. package/dist/react19/no-implicit-ref-callback-return.js.map +1 -1
  4. package/dist/search/find-enzyme-usage.d.ts.map +1 -1
  5. package/dist/search/find-enzyme-usage.js +34 -1
  6. package/dist/search/find-enzyme-usage.js.map +1 -1
  7. package/dist/testing/enzyme-host-components.d.ts +2 -1
  8. package/dist/testing/enzyme-host-components.d.ts.map +1 -1
  9. package/dist/testing/enzyme-host-components.js +33 -2
  10. package/dist/testing/enzyme-host-components.js.map +1 -1
  11. package/dist/testing/enzyme-shared-wrapper.d.ts +26 -0
  12. package/dist/testing/enzyme-shared-wrapper.d.ts.map +1 -0
  13. package/dist/testing/enzyme-shared-wrapper.js +213 -0
  14. package/dist/testing/enzyme-shared-wrapper.js.map +1 -0
  15. package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
  16. package/dist/testing/enzyme-to-react-testing-library.js +280 -2
  17. package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
  18. package/dist/testing/enzyme-usage.d.ts +3 -1
  19. package/dist/testing/enzyme-usage.d.ts.map +1 -1
  20. package/dist/testing/enzyme-usage.js +19 -3
  21. package/dist/testing/enzyme-usage.js.map +1 -1
  22. package/dist/testing/enzyme-wrapper-scope.d.ts +3 -0
  23. package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
  24. package/dist/testing/enzyme-wrapper-scope.js +38 -6
  25. package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
  26. package/dist/zustand/redux-stores.d.ts +10 -0
  27. package/dist/zustand/redux-stores.d.ts.map +1 -1
  28. package/dist/zustand/redux-stores.js +187 -8
  29. package/dist/zustand/redux-stores.js.map +1 -1
  30. package/dist/zustand/redux-to-zustand.d.ts +20 -5
  31. package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
  32. package/dist/zustand/redux-to-zustand.js +520 -27
  33. package/dist/zustand/redux-to-zustand.js.map +1 -1
  34. package/dist/zustand/zustand-plan.d.ts +28 -4
  35. package/dist/zustand/zustand-plan.d.ts.map +1 -1
  36. package/dist/zustand/zustand-plan.js +265 -19
  37. package/dist/zustand/zustand-plan.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/react19/no-implicit-ref-callback-return.ts +34 -8
  40. package/src/search/find-enzyme-usage.ts +32 -3
  41. package/src/testing/enzyme-host-components.ts +38 -3
  42. package/src/testing/enzyme-shared-wrapper.ts +224 -0
  43. package/src/testing/enzyme-to-react-testing-library.ts +271 -6
  44. package/src/testing/enzyme-usage.ts +27 -3
  45. package/src/testing/enzyme-wrapper-scope.ts +35 -4
  46. package/src/zustand/redux-stores.ts +195 -8
  47. package/src/zustand/redux-to-zustand.ts +559 -35
  48. package/src/zustand/zustand-plan.ts +284 -18
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.hookName = exports.REACT_REDUX = void 0;
12
+ exports.hookName = exports.REDUCER_STORE_HOOK = exports.STORE_LISTENERS = exports.SELECTOR_HOOK = exports.STORE_MEMBERS = exports.REACT_REDUX = void 0;
13
13
  exports.parentTree = parentTree;
14
14
  exports.isStatement = isStatement;
15
15
  exports.isReactDependencies = isReactDependencies;
@@ -23,8 +23,10 @@ exports.walk = walk;
23
23
  exports.sourceFacts = sourceFacts;
24
24
  exports.storeFacts = storeFacts;
25
25
  exports.isDispatcherDeclaration = isDispatcherDeclaration;
26
+ exports.providerChildren = providerChildren;
26
27
  exports.providerChild = providerChild;
27
28
  exports.plan = plan;
29
+ exports.readSelector = readSelector;
28
30
  exports.planPackages = planPackages;
29
31
  exports.sliceSource = sliceSource;
30
32
  exports.actionsExport = actionsExport;
@@ -183,6 +185,26 @@ function walk(node, visit) {
183
185
  }
184
186
  }
185
187
  const SKIPPED = new Set(["markers", "prefix", "type", "methodType", "fieldType", "variableType", "constructorType", "javaType", "before", "after"]);
188
+ function readSelectors(cu, declared) {
189
+ var _a;
190
+ const local = new Set();
191
+ const exported = new Set();
192
+ for (const { element } of cu.statements) {
193
+ if (element.kind !== java_1.J.Kind.VariableDeclarations)
194
+ continue;
195
+ const declarations = element;
196
+ if (!declarations.modifiers.some(m => m.keyword === "const"))
197
+ continue;
198
+ for (const { element: variable } of declarations.variables) {
199
+ if (!(0, java_1.isIdentifier)(variable.name) || declared.get(variable.name.simpleName) !== 1 || !selectorRead((_a = variable.initializer) === null || _a === void 0 ? void 0 : _a.element))
200
+ continue;
201
+ local.add(variable.name.simpleName);
202
+ if (declarations.modifiers.some(m => m.keyword === "export"))
203
+ exported.add(variable.name.simpleName);
204
+ }
205
+ }
206
+ return { local, exported };
207
+ }
186
208
  function sourceFacts(cu) {
187
209
  return __awaiter(this, void 0, void 0, function* () {
188
210
  var _a, _b, _c, _d, _e;
@@ -190,7 +212,7 @@ function sourceFacts(cu) {
190
212
  const declared = declaredNames(cu);
191
213
  const facts = {
192
214
  path: cu.sourcePath, typescript: /\.(?:ts|tsx|mts|cts)$/.test(cu.sourcePath), test: redux_stores_1.TEST_SOURCE.test(cu.sourcePath),
193
- bindings, declared: new Set(declared.keys()), uses: [], unfollowed: [], stores: []
215
+ bindings, declared: new Set(declared.keys()), uses: [], unfollowed: [], stores: [], readSelectors: readSelectors(cu, declared)
194
216
  };
195
217
  const followed = new Map(bindings.filter(binding => binding.module === exports.REACT_REDUX || (0, module_imports_1.isRelativeSpecifier)(binding.module))
196
218
  .map(binding => [binding.local, binding]));
@@ -270,8 +292,10 @@ function storeFacts(cu, modules) {
270
292
  return __awaiter(this, void 0, void 0, function* () {
271
293
  const store = (0, redux_stores_1.storeFindings)(call, cu, modules, functions);
272
294
  if (store) {
273
- stores.push({ path: cu.sourcePath, api: store.api, store: storeNameAt(this.cursor), findings: store.findings,
274
- slices: store.slices, exportedAs: exportedStore(cu, this.cursor) });
295
+ const name = storeNameAt(this.cursor);
296
+ const own = yield usesInSource(cu, name, call);
297
+ stores.push({ path: cu.sourcePath, api: store.api, store: name, findings: store.findings,
298
+ slices: store.slices, exportedAs: exportedStore(cu, this.cursor), reducerStore: store.reducerStore, usedInSource: own.other, calledInSource: own.called });
275
299
  }
276
300
  return _super.visitMethodInvocation.call(this, call, ctx);
277
301
  });
@@ -312,7 +336,7 @@ function dispatcherCount(cu, followed, name) {
312
336
  return count;
313
337
  }
314
338
  function classify(identifier, binding, cursor, followed, dispatchers, declared) {
315
- var _a, _b;
339
+ var _a, _b, _c;
316
340
  const trees = ancestors(cursor);
317
341
  if (trees.some(tree => tree.kind === javascript_1.JS.Kind.Import))
318
342
  return undefined;
@@ -344,10 +368,15 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
344
368
  if ((parent === null || parent === void 0 ? void 0 : parent.kind) !== java_1.J.Kind.MethodInvocation || parent.name !== identifier)
345
369
  return other(`\`${binding.name}\` from react-redux`);
346
370
  const call = parent;
371
+ if (binding.name === "connect")
372
+ return (_b = connectUse(call, other)) !== null && _b !== void 0 ? _b : { local, kind: "connect" };
347
373
  if (binding.name === "useSelector") {
348
374
  const args = argumentsOf(call);
349
375
  const read = args.length === 1 && !call.typeParameters ? selectorRead(args[0]) : undefined;
350
- return read ? { local, kind: "selector", key: read.key } : Object.assign(Object.assign({}, other("a selector that isn't a read of one slice's state")), { reason: "SELECTOR" });
376
+ if (read)
377
+ return { local, kind: "selector", key: read.key };
378
+ const selector = args.length === 1 && !call.typeParameters && (0, java_1.isIdentifier)(args[0]) ? args[0].simpleName : undefined;
379
+ 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 });
351
380
  }
352
381
  if (binding.name === "useDispatch") {
353
382
  const variable = parentTree(cursorOf(cursor, call));
@@ -370,16 +399,17 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
370
399
  return Object.assign(Object.assign({}, other("the dispatch's result is used")), { reason: "DISPATCH" });
371
400
  return { local, kind: "dispatched", via };
372
401
  }
373
- if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation && ((_b = parent.select) === null || _b === void 0 ? void 0 : _b.element) === identifier) {
402
+ if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation && ((_c = parent.select) === null || _c === void 0 ? void 0 : _c.element) === identifier) {
374
403
  const call = parent;
375
404
  const outer = parentTree(cursorOf(cursor, call));
376
405
  const read = getStateRead(call, outer);
377
406
  if (read)
378
407
  return { local, kind: "getState", key: read.key };
379
- if (call.name.simpleName === "dispatch" && dispatchedAction(call)) {
380
- return isStatement(call, outer) ? { local, kind: "storeDispatch" } : Object.assign(Object.assign({}, other("the dispatch's result is used")), { reason: "DISPATCH" });
408
+ const member = call.name.simpleName;
409
+ if (member === "dispatch" && dispatchedAction(call)) {
410
+ return isStatement(call, outer) ? { local, kind: "storeDispatch", member } : Object.assign(Object.assign({}, other("the dispatch's result is used")), { reason: "DISPATCH", member });
381
411
  }
382
- return other(`\`${local}.${call.name.simpleName}\``);
412
+ return Object.assign(Object.assign({}, other(`\`${local}.${member}\``)), { member });
383
413
  }
384
414
  if ((parent === null || parent === void 0 ? void 0 : parent.kind) === javascript_1.JS.Kind.JsxEmbeddedExpression) {
385
415
  const attribute = trees[2];
@@ -394,6 +424,22 @@ function classify(identifier, binding, cursor, followed, dispatchers, declared)
394
424
  }
395
425
  return other("referenced");
396
426
  }
427
+ function connectUse(call, other) {
428
+ const args = argumentsOf(call);
429
+ const absent = (node) => !node ||
430
+ node.kind === java_1.J.Kind.Literal && node.valueSource === "null" ||
431
+ (0, java_1.isIdentifier)(node) && node.simpleName === "undefined";
432
+ if (args.length > 4 || !absent(args[2]))
433
+ return other("`connect` with `mergeProps`");
434
+ if (args.length === 4 && !absent(args[3])) {
435
+ const options = (0, redux_stores_1.objectProperties)(args[3]);
436
+ const forwardRef = options === null || options === void 0 ? void 0 : options.get("forwardRef");
437
+ if (!options || options.size !== 1 || (forwardRef === null || forwardRef === void 0 ? void 0 : forwardRef.kind) !== java_1.J.Kind.Literal || typeof forwardRef.value !== "boolean") {
438
+ return other("`connect` with options other than `forwardRef`");
439
+ }
440
+ }
441
+ return undefined;
442
+ }
397
443
  function dispatcherUse(identifier, cursor, followed, bindings) {
398
444
  const parent = parentTree(cursor);
399
445
  const local = identifier.simpleName;
@@ -423,10 +469,18 @@ function providerUse(tag, followed, local) {
423
469
  const expression = (value === null || value === void 0 ? void 0 : value.kind) === javascript_1.JS.Kind.JsxEmbeddedExpression ? value.expression.element : undefined;
424
470
  if (!(0, java_1.isIdentifier)(expression) || !followed.has(expression.simpleName))
425
471
  return other("`Provider` of a store that isn't imported");
426
- if (!providerChild(tag))
427
- return other("`Provider` without exactly one element child");
472
+ if (!providerChild(tag) && !providerChildren(tag))
473
+ return other("`Provider` without children");
428
474
  return { local, kind: "providerTag" };
429
475
  }
476
+ function providerChildren(tag) {
477
+ var _a;
478
+ return !tag.selfClosing && ((_a = tag.children) !== null && _a !== void 0 ? _a : []).some(child => {
479
+ var _a;
480
+ return !(child.kind === java_1.J.Kind.Literal && String((_a = child.value) !== null && _a !== void 0 ? _a : "").trim() === "") &&
481
+ child.kind !== java_1.J.Kind.Empty;
482
+ });
483
+ }
430
484
  function providerChild(tag) {
431
485
  var _a;
432
486
  const children = ((_a = tag.children) !== null && _a !== void 0 ? _a : []).filter(child => {
@@ -442,6 +496,54 @@ function cursorOf(cursor, node) {
442
496
  return c;
443
497
  return cursor;
444
498
  }
499
+ exports.STORE_MEMBERS = new Set(["getState", "dispatch", "subscribe"]);
500
+ function usesInSource(cu, name, call) {
501
+ return __awaiter(this, void 0, void 0, function* () {
502
+ const result = { other: false, called: new Set() };
503
+ const statements = cu.statements.map(s => s.element).flatMap(statement => {
504
+ if (statement.kind === javascript_1.JS.Kind.Import)
505
+ return [];
506
+ if (statement.kind === javascript_1.JS.Kind.ExportAssignment && (0, java_1.isIdentifier)(statement.expression.element) &&
507
+ statement.expression.element.simpleName === name)
508
+ return [];
509
+ if (statement.kind === java_1.J.Kind.VariableDeclarations && statement.variables.some(v => { var _a; return ((_a = v.element.initializer) === null || _a === void 0 ? void 0 : _a.element) === call; })) {
510
+ return [call];
511
+ }
512
+ return [statement];
513
+ });
514
+ for (const statement of statements) {
515
+ if (![...(0, javascript_1.namesReferencedWithin)(statement)].includes(name))
516
+ continue;
517
+ yield new class extends javascript_1.JavaScriptVisitor {
518
+ visitIdentifier(identifier, ctx) {
519
+ return __awaiter(this, void 0, void 0, function* () {
520
+ var _a;
521
+ if (identifier.simpleName !== name)
522
+ return identifier;
523
+ const parent = parentTree(this.cursor);
524
+ if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.FieldAccess && parent.name.element === identifier)
525
+ return identifier;
526
+ if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation && parent.name === identifier) {
527
+ if (parent.select)
528
+ return identifier;
529
+ }
530
+ else if ((parent === null || parent === void 0 ? void 0 : parent.kind) === java_1.J.Kind.MethodInvocation && ((_a = parent.select) === null || _a === void 0 ? void 0 : _a.element) === identifier &&
531
+ exports.STORE_MEMBERS.has(parent.name.simpleName)) {
532
+ result.called.add(parent.name.simpleName);
533
+ return identifier;
534
+ }
535
+ if ((parent === null || parent === void 0 ? void 0 : parent.kind) === javascript_1.JS.Kind.PropertyAssignment && parent.name.element === identifier &&
536
+ parent.initializer)
537
+ return identifier;
538
+ result.other = true;
539
+ return identifier;
540
+ });
541
+ }
542
+ }().visit(statement, new rewrite_1.ExecutionContext());
543
+ }
544
+ return result;
545
+ });
546
+ }
445
547
  function storeNameAt(cursor) {
446
548
  for (let c = cursor.parent; c; c = c.parent) {
447
549
  const node = c.value;
@@ -474,9 +576,12 @@ function exportedStore(cu, cursor) {
474
576
  (0, java_1.isIdentifier)(s.expression.element) && s.expression.element.simpleName === name);
475
577
  return exported ? "default" : undefined;
476
578
  }
579
+ exports.SELECTOR_HOOK = "useAppStoreSelector";
580
+ exports.STORE_LISTENERS = "storeListeners";
581
+ exports.REDUCER_STORE_HOOK = "useAppStore";
477
582
  const hookName = (key) => `use${key.charAt(0).toUpperCase()}${key.slice(1)}Store`;
478
583
  exports.hookName = hookName;
479
- function plan(facts, sliceSources, dependencies, scope = () => true) {
584
+ function plan(facts, sliceSources, dependencies, scope = () => true, wholeStores = true, renderer = () => "react-dom", selectsOnEachRead = () => false) {
480
585
  var _a;
481
586
  const stores = [...facts.values()].filter(source => scope(source.path)).flatMap(source => source.stores);
482
587
  const result = { slices: new Map(), sources: new Set(), blocked: new Map() };
@@ -491,6 +596,7 @@ function plan(facts, sliceSources, dependencies, scope = () => true) {
491
596
  const findings = [...store.findings];
492
597
  const block = (reason, detail) => findings.push({ reason, detail });
493
598
  const held = new Map();
599
+ const handled = new Map();
494
600
  if (findings.length === 0) {
495
601
  if (!store.exportedAs)
496
602
  block("STORE_NOT_MODULE_LEVEL", store.store);
@@ -527,6 +633,13 @@ function plan(facts, sliceSources, dependencies, scope = () => true) {
527
633
  if (!scope(slice.path))
528
634
  block("SLICE_SOURCE", `${key} is declared in another package, ${slice.path}`);
529
635
  result.slices.set(key, planned);
636
+ for (const type of reducers.types) {
637
+ const other = handled.get(type);
638
+ if (other)
639
+ block("SHARED_ACTION_TYPE", `\`${type}\` is handled by both \`${other}\` and \`${key}\``);
640
+ else
641
+ handled.set(type, key);
642
+ }
530
643
  }
531
644
  }
532
645
  const slicePaths = new Map([...result.slices.values()].map(slice => [slice.path, slice]));
@@ -590,6 +703,9 @@ function plan(facts, sliceSources, dependencies, scope = () => true) {
590
703
  if (via && !(resolve(via.module) === store.path && via.name === store.exportedAs))
591
704
  block("DISPATCH", `${where} is dispatched through \`${use.via}\``);
592
705
  }
706
+ else if (use.kind === "connect") {
707
+ block("REACT_REDUX_USE", `${where}: \`connect\` from react-redux`);
708
+ }
593
709
  else if ((use.kind === "provider" || use.kind === "storeDispatch") && !isStore) {
594
710
  block("STORE_USE", `${where} isn't the store`);
595
711
  }
@@ -618,6 +734,8 @@ function plan(facts, sliceSources, dependencies, scope = () => true) {
618
734
  }
619
735
  if ([store.path, ...slicePaths.keys()].some(path => /\.(?:ts|tsx|mts|cts)$/.test(path)))
620
736
  block("TYPESCRIPT", store.path);
737
+ if (findings.length > 0 && store.reducerStore && wholeStores)
738
+ return reducerPlan(facts, sliceSources, store, dependencies, scope, renderer, selectsOnEachRead);
621
739
  if (findings.length > 0) {
622
740
  result.blocked.set(store, dedupe(findings));
623
741
  result.slices.clear();
@@ -627,17 +745,142 @@ function plan(facts, sliceSources, dependencies, scope = () => true) {
627
745
  result.sources = sources;
628
746
  return result;
629
747
  }
630
- function planPackages(facts, sliceSources, packageOf, dependencies) {
748
+ function reducerPlan(facts, sliceSources, store, dependencies, scope, renderer, selectsOnEachRead) {
749
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
750
+ const findings = [];
751
+ const block = (reason, detail) => findings.push({ reason, detail });
752
+ const hook = exports.REDUCER_STORE_HOOK;
753
+ const source = facts.get(store.path);
754
+ const names = new Set([...(_b = (_a = sliceSources.get(store.path)) === null || _a === void 0 ? void 0 : _a.names) !== null && _b !== void 0 ? _b : [], ...(_c = source === null || source === void 0 ? void 0 : source.declared) !== null && _c !== void 0 ? _c : [], ...(_d = source === null || source === void 0 ? void 0 : source.bindings.map(b => b.local)) !== null && _d !== void 0 ? _d : []]);
755
+ const reducer = (_e = ["rootReducer", "appReducer", "storeReducer"].find(name => !names.has(name))) !== null && _e !== void 0 ? _e : "rootReducer";
756
+ if (!store.exportedAs)
757
+ block("STORE_NOT_MODULE_LEVEL", store.store);
758
+ if (store.usedInSource)
759
+ block("STORE_USE", `\`${store.store}\` is used in its own source`);
760
+ const dependency = dependencies(store.path, false);
761
+ if (dependency)
762
+ findings.push(dependency);
763
+ for (const name of [hook, reducer, "create"])
764
+ if (names.has(name))
765
+ block("NAME_TAKEN", `${name} in ${store.path}`);
766
+ const storeSource = facts.get(store.path);
767
+ const rtkCombine = storeSource === null || storeSource === void 0 ? void 0 : storeSource.bindings.some(b => b.local === "combineReducers" && b.module === redux_stores_1.RTK && b.name === "combineReducers");
768
+ if (store.reducerStore === "combined" && names.has("combineReducers") && !rtkCombine)
769
+ block("NAME_TAKEN", `combineReducers in ${store.path}`);
770
+ const sources = new Set([store.path]);
771
+ let connects = false;
772
+ let selects = false;
773
+ let subscribes = (_g = (_f = store.calledInSource) === null || _f === void 0 ? void 0 : _f.has("subscribe")) !== null && _g !== void 0 ? _g : false;
774
+ for (const source of facts.values()) {
775
+ const resolve = (module) => (0, module_imports_1.resolveRelative)(source.path, module, facts);
776
+ if (!scope(source.path)) {
777
+ for (const binding of source.bindings) {
778
+ if (binding.module !== exports.REACT_REDUX && resolve(binding.module) === store.path)
779
+ block("STORE_USE", `${binding.local} in ${source.path}, of another package`);
780
+ }
781
+ for (const { module, detail } of source.unfollowed) {
782
+ if (resolve(module) === store.path)
783
+ block("UNFOLLOWED_IMPORT", `${detail} of ${module} in ${source.path}, of another package`);
784
+ }
785
+ continue;
786
+ }
787
+ for (const { module, detail } of source.unfollowed) {
788
+ if (module === exports.REACT_REDUX || resolve(module) === store.path)
789
+ block("UNFOLLOWED_IMPORT", `${detail} of ${module} in ${source.path}`);
790
+ }
791
+ let changes = false;
792
+ for (const use of source.uses) {
793
+ const binding = source.bindings.find(b => b.local === use.local);
794
+ if (!binding)
795
+ continue;
796
+ const where = `${use.local} in ${source.path}`;
797
+ if (binding.module === exports.REACT_REDUX) {
798
+ changes = true;
799
+ if (use.kind === "connect")
800
+ connects = true;
801
+ if (use.kind === "other" && use.selector && readSelector(source, use.selector, facts))
802
+ continue;
803
+ if (use.kind === "other" && use.anySelector) {
804
+ if (selectsOnEachRead(store.path))
805
+ selects = true;
806
+ continue;
807
+ }
808
+ if (use.kind === "other")
809
+ block((_h = use.reason) !== null && _h !== void 0 ? _h : "REACT_REDUX_USE", `${where}: ${use.detail}`);
810
+ continue;
811
+ }
812
+ const path = resolve(binding.module);
813
+ if (path !== store.path || binding.name !== store.exportedAs)
814
+ continue;
815
+ if (use.kind === "provider")
816
+ changes = true;
817
+ else if (use.kind === "other" && use.member === "subscribe")
818
+ subscribes = true;
819
+ else if (use.kind === "other" && use.member !== "getState" && use.member !== "dispatch")
820
+ block(use.reason === "DISPATCH" ? "STORE_USE" : (_j = use.reason) !== null && _j !== void 0 ? _j : "STORE_USE", `${where}: ${use.detail}`);
821
+ }
822
+ if (changes && source.path !== store.path) {
823
+ if (source.typescript)
824
+ block("TYPESCRIPT", source.path);
825
+ if (source.bindings.some(b => b.local === hook) || source.declared.has(hook))
826
+ block("NAME_TAKEN", `${hook} in ${source.path}`);
827
+ sources.add(source.path);
828
+ }
829
+ }
830
+ if (/\.(?:ts|tsx|mts|cts)$/.test(store.path))
831
+ block("TYPESCRIPT", store.path);
832
+ const module = connects ? renderer(store.path) : undefined;
833
+ if (connects && !module)
834
+ block("REACT_REDUX_USE", `connect in a package that declares neither react-dom nor react-native`);
835
+ if (connects && storeSource) {
836
+ const helpers = [["connect", ""], ...["createElement", "forwardRef", "memo", "useRef"].map(name => [name, "react"]),
837
+ ["unstable_batchedUpdates", module !== null && module !== void 0 ? module : ""]];
838
+ for (const [name, from] of helpers) {
839
+ const bound = storeSource.bindings.find(b => b.local === name);
840
+ if (storeSource.declared.has(name) || bound && (bound.module !== from || bound.name !== name))
841
+ block("NAME_TAKEN", `${name} in ${store.path}`);
842
+ }
843
+ }
844
+ if (selects && storeSource) {
845
+ for (const name of [exports.SELECTOR_HOOK, "useRef", "useSyncExternalStore"]) {
846
+ const bound = storeSource.bindings.find(b => b.local === name);
847
+ if (storeSource.declared.has(name) || bound && (bound.module !== (name === exports.SELECTOR_HOOK ? "" : "react") || bound.name !== name))
848
+ block("NAME_TAKEN", `${name} in ${store.path}`);
849
+ }
850
+ for (const path of sources) {
851
+ const source = facts.get(path);
852
+ if (source && path !== store.path && (source.declared.has(exports.SELECTOR_HOOK) || source.bindings.some(b => b.local === exports.SELECTOR_HOOK)))
853
+ block("NAME_TAKEN", `${exports.SELECTOR_HOOK} in ${path}`);
854
+ }
855
+ }
856
+ if (subscribes && names.has(exports.STORE_LISTENERS))
857
+ block("NAME_TAKEN", `${exports.STORE_LISTENERS} in ${store.path}`);
858
+ const result = { slices: new Map(), sources: new Set(), blocked: new Map() };
859
+ if (findings.length > 0) {
860
+ result.blocked.set(store, dedupe(findings));
861
+ return result;
862
+ }
863
+ return Object.assign(Object.assign({}, result), { store, sources, reducerStore: Object.assign(Object.assign(Object.assign({ hook, reducer }, module ? { renderer: module } : {}), selects ? { selectorHook: exports.SELECTOR_HOOK } : {}), subscribes ? { listeners: exports.STORE_LISTENERS } : {}) });
864
+ }
865
+ function readSelector(source, name, facts) {
866
+ var _a, _b;
867
+ const binding = source.bindings.find(b => b.local === name);
868
+ if (!binding)
869
+ return source.readSelectors.local.has(name);
870
+ const path = (0, module_imports_1.resolveRelative)(source.path, binding.module, facts);
871
+ return path !== undefined && ((_b = (_a = facts.get(path)) === null || _a === void 0 ? void 0 : _a.readSelectors.exported.has(binding.name)) !== null && _b !== void 0 ? _b : false);
872
+ }
873
+ function planPackages(facts, sliceSources, packageOf, dependencies, wholeStores = true, renderer, selectsOnEachRead) {
631
874
  const root = (path) => { var _a; return (_a = packageOf(path)) !== null && _a !== void 0 ? _a : ""; };
632
875
  const roots = new Set([...facts.values()].filter(source => source.stores.length > 0).map(source => root(source.path)));
633
- return [...roots].map(packageRoot => plan(facts, sliceSources, dependencies, path => root(path) === packageRoot));
876
+ return [...roots].map(packageRoot => plan(facts, sliceSources, dependencies, path => root(path) === packageRoot, wholeStores, renderer, selectsOnEachRead));
634
877
  }
635
878
  function dedupe(findings) {
636
879
  const seen = new Set();
637
880
  return findings.filter(f => !seen.has(f.reason + "\0" + f.detail) && seen.add(f.reason + "\0" + f.detail));
638
881
  }
639
882
  function sliceSource(cu) {
640
- var _a;
883
+ var _a, _b;
641
884
  const createSlice = new Set((0, module_imports_1.importBindings)(cu).filter(b => b.module === redux_stores_1.RTK && b.name === "createSlice").map(b => b.local));
642
885
  const functions = (0, redux_stores_1.storeFunctions)(cu);
643
886
  if (createSlice.size === 0 && functions.configure.size === 0)
@@ -653,15 +896,17 @@ function sliceSource(cu) {
653
896
  functions.configure.has(v.element.initializer.element.name.simpleName);
654
897
  }));
655
898
  for (const [variable, facts] of local.localSlices) {
656
- const slice = { actions: new Set(), unknown: new Set(), thunks: new Set((_a = facts.thunks) === null || _a === void 0 ? void 0 : _a.keys()), blocker: facts.blocker };
899
+ const slice = { actions: new Set(), unknown: new Set(), thunks: new Set((_a = facts.thunks) === null || _a === void 0 ? void 0 : _a.keys()), types: new Set(), blocker: facts.blocker };
657
900
  result.slices.set(variable, slice);
658
901
  if (slice.blocker)
659
902
  continue;
660
- slice.blocker = sliceBlocker(cu, variable, slice.actions, slice.unknown, slice.thunks, local.localReducers);
903
+ slice.blocker = sliceBlocker(cu, variable, slice.actions, slice.unknown, slice.thunks, slice.types, local.localReducers);
904
+ for (const { thunk, stage } of (_b = facts.cases) !== null && _b !== void 0 ? _b : [])
905
+ slice.types.add(`${facts.thunks.get(thunk).typePrefix}/${stage}`);
661
906
  }
662
907
  return result;
663
908
  }
664
- function sliceBlocker(cu, variable, actions, unknown, thunks, reducerVariables) {
909
+ function sliceBlocker(cu, variable, actions, unknown, thunks, types, reducerVariables) {
665
910
  var _a, _b, _c, _d, _e, _f;
666
911
  const block = (reason, detail) => ({ reason, detail: `${variable}: ${detail}` });
667
912
  const statements = cu.statements.map(s => s.element);
@@ -702,6 +947,7 @@ function sliceBlocker(cu, variable, actions, unknown, thunks, reducerVariables)
702
947
  if (usesThis(value))
703
948
  return block("REDUCER", `\`${key}\` uses \`this\``);
704
949
  reducerNames.add(key);
950
+ types.add(`${name.value}/${key}`);
705
951
  }
706
952
  const rest = [];
707
953
  for (const statement of statements) {