oxlint-plugin-react-doctor 0.9.1-dev.54ba416 → 0.9.1-dev.5d2f66d

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 (3) hide show
  1. package/dist/index.d.ts +337 -1
  2. package/dist/index.js +1774 -80
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -14551,16 +14551,136 @@ const dangerousHtmlSink = defineRule({
14551
14551
  }
14552
14552
  });
14553
14553
  //#endregion
14554
+ //#region src/plugin/utils/get-static-logical-expression-result-branches.ts
14555
+ const deduplicateResultBranches = (branches) => {
14556
+ const resultBranches = [];
14557
+ const seenStatesByExpression = /* @__PURE__ */ new Map();
14558
+ for (const branch of branches) {
14559
+ const branchState = `${branch.truthiness}:${branch.nullishness}`;
14560
+ const seenStates = seenStatesByExpression.get(branch.expression);
14561
+ if (seenStates?.has(branchState)) continue;
14562
+ if (seenStates) seenStates.add(branchState);
14563
+ else seenStatesByExpression.set(branch.expression, new Set([branchState]));
14564
+ resultBranches.push(branch);
14565
+ }
14566
+ return resultBranches;
14567
+ };
14568
+ const getAtomicExpressionResultBranch = (expression) => {
14569
+ if (isNodeOfType(expression, "JSXElement") || isNodeOfType(expression, "JSXFragment") || isNodeOfType(expression, "ArrayExpression") || isNodeOfType(expression, "ObjectExpression") || isNodeOfType(expression, "ArrowFunctionExpression") || isNodeOfType(expression, "FunctionExpression") || isNodeOfType(expression, "ClassExpression") || isNodeOfType(expression, "NewExpression")) return {
14570
+ expression,
14571
+ truthiness: "truthy",
14572
+ nullishness: "non-nullish"
14573
+ };
14574
+ if (isNodeOfType(expression, "Literal")) {
14575
+ if (expression.value === null) return {
14576
+ expression,
14577
+ truthiness: "falsy",
14578
+ nullishness: "nullish"
14579
+ };
14580
+ return {
14581
+ expression,
14582
+ truthiness: expression.value ? "truthy" : "falsy",
14583
+ nullishness: "non-nullish"
14584
+ };
14585
+ }
14586
+ if (isNodeOfType(expression, "UnaryExpression") && expression.operator === "void") return {
14587
+ expression,
14588
+ truthiness: "falsy",
14589
+ nullishness: "nullish"
14590
+ };
14591
+ return {
14592
+ expression,
14593
+ truthiness: "unknown",
14594
+ nullishness: "unknown"
14595
+ };
14596
+ };
14597
+ const getStaticExpressionResultBranches = (expression) => {
14598
+ const finalExpression = getFinalSequenceExpressionValue(expression);
14599
+ if (isNodeOfType(finalExpression, "ConditionalExpression")) return deduplicateResultBranches([...getStaticExpressionResultBranches(finalExpression.consequent), ...getStaticExpressionResultBranches(finalExpression.alternate)]);
14600
+ if (!isNodeOfType(finalExpression, "LogicalExpression")) return [getAtomicExpressionResultBranch(finalExpression)];
14601
+ const leftBranches = getStaticExpressionResultBranches(finalExpression.left);
14602
+ const rightBranches = getStaticExpressionResultBranches(finalExpression.right);
14603
+ const resultBranches = [];
14604
+ for (const leftBranch of leftBranches) {
14605
+ if (finalExpression.operator === "&&") {
14606
+ if (leftBranch.truthiness !== "truthy") resultBranches.push(leftBranch.truthiness === "falsy" ? leftBranch : {
14607
+ ...leftBranch,
14608
+ truthiness: "falsy"
14609
+ });
14610
+ if (leftBranch.truthiness !== "falsy") resultBranches.push(...rightBranches);
14611
+ continue;
14612
+ }
14613
+ if (finalExpression.operator === "||") {
14614
+ if (leftBranch.truthiness !== "falsy") resultBranches.push(leftBranch.truthiness === "truthy" ? leftBranch : {
14615
+ ...leftBranch,
14616
+ truthiness: "truthy",
14617
+ nullishness: "non-nullish"
14618
+ });
14619
+ if (leftBranch.truthiness !== "truthy") resultBranches.push(...rightBranches);
14620
+ continue;
14621
+ }
14622
+ if (leftBranch.nullishness !== "nullish") resultBranches.push(leftBranch.nullishness === "non-nullish" ? leftBranch : {
14623
+ ...leftBranch,
14624
+ nullishness: "non-nullish"
14625
+ });
14626
+ if (leftBranch.nullishness !== "non-nullish") resultBranches.push(...rightBranches);
14627
+ }
14628
+ return deduplicateResultBranches(resultBranches);
14629
+ };
14630
+ const getStaticLogicalExpressionResultBranches = (expression) => {
14631
+ const resultExpressions = [];
14632
+ const seenExpressions = /* @__PURE__ */ new Set();
14633
+ for (const resultBranch of getStaticExpressionResultBranches(expression)) {
14634
+ if (seenExpressions.has(resultBranch.expression)) continue;
14635
+ seenExpressions.add(resultBranch.expression);
14636
+ resultExpressions.push(resultBranch.expression);
14637
+ }
14638
+ return resultExpressions;
14639
+ };
14640
+ //#endregion
14554
14641
  //#region src/plugin/utils/get-static-jsx-descendant-opening-elements.ts
14555
- const appendDescendants = (children, descendants) => {
14556
- for (const child of children) if (isNodeOfType(child, "JSXElement")) {
14557
- descendants.push(child.openingElement);
14558
- appendDescendants(child.children, descendants);
14559
- } else if (isNodeOfType(child, "JSXFragment")) appendDescendants(child.children, descendants);
14642
+ const appendDescendant = (node, descendants, includeStaticExpressionBranches) => {
14643
+ const expression = stripParenExpression(node);
14644
+ if (isNodeOfType(expression, "JSXElement")) {
14645
+ descendants.push(expression.openingElement);
14646
+ for (const child of expression.children) appendDescendant(child, descendants, includeStaticExpressionBranches);
14647
+ return;
14648
+ }
14649
+ if (isNodeOfType(expression, "JSXFragment")) {
14650
+ for (const child of expression.children) appendDescendant(child, descendants, includeStaticExpressionBranches);
14651
+ return;
14652
+ }
14653
+ if (!includeStaticExpressionBranches) return;
14654
+ if (isNodeOfType(expression, "JSXExpressionContainer")) {
14655
+ appendDescendant(expression.expression, descendants, true);
14656
+ return;
14657
+ }
14658
+ if (isNodeOfType(expression, "ConditionalExpression")) {
14659
+ const staticTestValue = readStaticBoolean(getFinalSequenceExpressionValue(expression.test));
14660
+ if (staticTestValue !== null) {
14661
+ appendDescendant(staticTestValue ? expression.consequent : expression.alternate, descendants, true);
14662
+ return;
14663
+ }
14664
+ appendDescendant(expression.consequent, descendants, true);
14665
+ appendDescendant(expression.alternate, descendants, true);
14666
+ return;
14667
+ }
14668
+ if (isNodeOfType(expression, "LogicalExpression")) {
14669
+ for (const resultBranch of getStaticLogicalExpressionResultBranches(expression)) appendDescendant(resultBranch, descendants, true);
14670
+ return;
14671
+ }
14672
+ if (isNodeOfType(expression, "ArrayExpression")) {
14673
+ for (const element of expression.elements) if (element && !isNodeOfType(element, "SpreadElement")) appendDescendant(element, descendants, true);
14674
+ return;
14675
+ }
14676
+ if (isNodeOfType(expression, "SequenceExpression")) {
14677
+ if (expression.expressions.length === 0) return;
14678
+ appendDescendant(getFinalSequenceExpressionValue(expression), descendants, true);
14679
+ }
14560
14680
  };
14561
- const getStaticJsxDescendantOpeningElements = (element) => {
14681
+ const getStaticJsxDescendantOpeningElements = (element, options = {}) => {
14562
14682
  const descendants = [];
14563
- appendDescendants(element.children, descendants);
14683
+ for (const child of element.children) appendDescendant(child, descendants, options.includeStaticExpressionBranches === true);
14564
14684
  return descendants;
14565
14685
  };
14566
14686
  //#endregion
@@ -25376,6 +25496,27 @@ const flattenLogicalAndChain = (node) => {
25376
25496
  return [node];
25377
25497
  };
25378
25498
  //#endregion
25499
+ //#region src/plugin/utils/resolve-imported-jsx-component-name.ts
25500
+ const resolveImportedJsxComponentName = (openingElement, moduleSource, scopes) => {
25501
+ const elementName = openingElement.name;
25502
+ if (isNodeOfType(elementName, "JSXIdentifier")) {
25503
+ const symbol = scopes.symbolFor(elementName);
25504
+ if (!symbol || symbol.kind !== "import") return null;
25505
+ const importDeclaration = getImportDeclarationForSymbol(symbol);
25506
+ if (!importDeclaration || importDeclaration.source.value !== moduleSource || isTypeOnlyImport(importDeclaration)) return null;
25507
+ if (isNodeOfType(symbol.declarationNode, "ImportDefaultSpecifier")) return "default";
25508
+ if (!isNodeOfType(symbol.declarationNode, "ImportSpecifier")) return null;
25509
+ if (symbol.declarationNode.importKind === "type") return null;
25510
+ return getImportedName(symbol.declarationNode) ?? null;
25511
+ }
25512
+ if (!isNodeOfType(elementName, "JSXMemberExpression") || !isNodeOfType(elementName.object, "JSXIdentifier") || !isNodeOfType(elementName.property, "JSXIdentifier")) return null;
25513
+ const namespaceSymbol = scopes.symbolFor(elementName.object);
25514
+ if (!namespaceSymbol || namespaceSymbol.kind !== "import" || !isNodeOfType(namespaceSymbol.declarationNode, "ImportNamespaceSpecifier")) return null;
25515
+ const importDeclaration = getImportDeclarationForSymbol(namespaceSymbol);
25516
+ if (!importDeclaration || importDeclaration.source.value !== moduleSource || isTypeOnlyImport(importDeclaration)) return null;
25517
+ return elementName.property.name;
25518
+ };
25519
+ //#endregion
25379
25520
  //#region src/plugin/utils/resolve-ink-api-name.ts
25380
25521
  const resolveInkApiName = (node, scopes) => {
25381
25522
  if (isNodeOfType(node, "Identifier")) {
@@ -25385,15 +25526,7 @@ const resolveInkApiName = (node, scopes) => {
25385
25526
  if (isNodeOfType(node, "MemberExpression") && isNodeOfType(node.object, "Identifier") && scopes.symbolFor(node.object)?.kind === "import" && isNamespaceImportFromModule$1(node, node.object.name, "ink")) return getStaticPropertyName(node);
25386
25527
  return null;
25387
25528
  };
25388
- const resolveInkJsxElementName = (openingElement, scopes) => {
25389
- const elementName = openingElement.name;
25390
- if (isNodeOfType(elementName, "JSXIdentifier")) {
25391
- if (scopes.symbolFor(elementName)?.kind !== "import") return null;
25392
- return getImportedNameFromModule(openingElement, elementName.name, "ink");
25393
- }
25394
- if (isNodeOfType(elementName, "JSXMemberExpression") && isNodeOfType(elementName.object, "JSXIdentifier") && scopes.symbolFor(elementName.object)?.kind === "import" && isNamespaceImportFromModule$1(openingElement, elementName.object.name, "ink")) return elementName.property.name;
25395
- return null;
25396
- };
25529
+ const resolveInkJsxElementName = (openingElement, scopes) => resolveImportedJsxComponentName(openingElement, "ink", scopes);
25397
25530
  //#endregion
25398
25531
  //#region src/plugin/utils/resolve-ink-render-calls.ts
25399
25532
  const getRenderedComponentName = (renderCall) => {
@@ -35937,6 +36070,7 @@ const MOBX_RULE_GATES = {
35937
36070
  const resolveImportSymbol = (symbol) => {
35938
36071
  const importDeclaration = getImportDeclarationForSymbol(symbol);
35939
36072
  if (!importDeclaration || typeof importDeclaration.source.value !== "string") return null;
36073
+ if (importDeclaration.importKind === "type" || isNodeOfType(symbol.declarationNode, "ImportSpecifier") && symbol.declarationNode.importKind === "type") return null;
35940
36074
  if (isNodeOfType(symbol.declarationNode, "ImportNamespaceSpecifier")) return {
35941
36075
  source: importDeclaration.source.value,
35942
36076
  importedName: null,
@@ -51167,6 +51301,23 @@ const isProvenReactClassComponent = (classNode, scopes, visitedClassNodes = /* @
51167
51301
  return isReactComponentClassValue(classNode.superClass, scopes, visitedClassNodes, visitedSymbolIds);
51168
51302
  };
51169
51303
  //#endregion
51304
+ //#region src/plugin/utils/unwrap-proven-react-hoc-function.ts
51305
+ const unwrapProvenReactHocFunction = (node, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
51306
+ if (!node) return null;
51307
+ const expression = stripParenExpression(node);
51308
+ if (isFunctionLike$1(expression)) return expression;
51309
+ if (isNodeOfType(expression, "Identifier")) {
51310
+ const symbol = scopes.symbolFor(expression);
51311
+ if (!symbol || visitedSymbolIds.has(symbol.id) || !symbol.initializer || hasSymbolWriteBefore(symbol, expression, scopes)) return null;
51312
+ visitedSymbolIds.add(symbol.id);
51313
+ return unwrapProvenReactHocFunction(symbol.initializer, scopes, visitedSymbolIds);
51314
+ }
51315
+ if (!isNodeOfType(expression, "CallExpression") || !isReactApiCall(expression, "memo", scopes, { resolveNamedAliases: true }) && !isReactApiCall(expression, "forwardRef", scopes, { resolveNamedAliases: true })) return null;
51316
+ const componentArgument = expression.arguments[0];
51317
+ if (!componentArgument || isNodeOfType(componentArgument, "SpreadElement")) return null;
51318
+ return unwrapProvenReactHocFunction(componentArgument, scopes, visitedSymbolIds);
51319
+ };
51320
+ //#endregion
51170
51321
  //#region src/plugin/utils/is-inline-intrinsic-ref-callback.ts
51171
51322
  const isInlineIntrinsicRefCallback = (functionNode, scopes) => {
51172
51323
  const functionExpression = findTransparentExpressionRoot(functionNode);
@@ -51279,22 +51430,6 @@ const getEnvironment = (program, filename, state) => {
51279
51430
  state.environmentsByProgram.set(program, environment);
51280
51431
  return environment;
51281
51432
  };
51282
- const unwrapProvenReactHocFunction = (node, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
51283
- if (!node) return null;
51284
- const current = findTransparentExpressionRoot(node);
51285
- if (isFunctionLike$1(current)) return current;
51286
- if (isNodeOfType(current, "Identifier")) {
51287
- const symbol = scopes.symbolFor(current);
51288
- if (!symbol || visitedSymbolIds.has(symbol.id) || !symbol.initializer || hasSymbolWriteBefore(symbol, current, scopes)) return null;
51289
- visitedSymbolIds.add(symbol.id);
51290
- return unwrapProvenReactHocFunction(symbol.initializer, scopes, visitedSymbolIds);
51291
- }
51292
- if (!isNodeOfType(current, "CallExpression")) return null;
51293
- if (!isProvenReactCall(current, "memo", scopes) && !isProvenReactCall(current, "forwardRef", scopes)) return null;
51294
- const firstArgument = current.arguments[0];
51295
- if (!firstArgument || isNodeOfType(firstArgument, "SpreadElement")) return null;
51296
- return unwrapProvenReactHocFunction(firstArgument, scopes, visitedSymbolIds);
51297
- };
51298
51433
  const isForwardRefValue = (node, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
51299
51434
  const current = findTransparentExpressionRoot(node);
51300
51435
  if (isNodeOfType(current, "Identifier")) {
@@ -99790,9 +99925,9 @@ const rawSqlInjectionRisk = defineRule({
99790
99925
  //#endregion
99791
99926
  //#region src/plugin/rules/architecture/react-compiler-no-manual-memoization.ts
99792
99927
  const REMOVAL_MESSAGE_BY_REACT_API_NAME = new Map([
99793
- ["useMemo", "This `useMemo` is dead weight, since React Compiler already caches every value here. Delete it."],
99794
- ["useCallback", "This `useCallback` is dead weight, since React Compiler already caches every function here. Delete it."],
99795
- ["memo", "This `memo()` is dead weight, since React Compiler already caches the component's output. Delete it."]
99928
+ ["useMemo", "React Compiler can cache this value automatically. Verify that removing `useMemo` preserves behavior before simplifying it."],
99929
+ ["useCallback", "React Compiler can cache this function automatically. Verify that removing `useCallback` preserves behavior before simplifying it."],
99930
+ ["memo", "React Compiler can cache this component output automatically. Verify that removing `memo()` preserves behavior before simplifying it."]
99796
99931
  ]);
99797
99932
  const resolveReactApiNameForIdentifier = (callee, context) => {
99798
99933
  if (!isNodeOfType(callee, "Identifier")) return null;
@@ -99838,10 +99973,10 @@ const isCompilerInferableFunction = (functionNode) => {
99838
99973
  };
99839
99974
  const reactCompilerNoManualMemoization = defineRule({
99840
99975
  id: "react-compiler-no-manual-memoization",
99841
- title: "Redundant manual memoization",
99976
+ title: "Manual memoization in compiler-managed code",
99842
99977
  severity: "warn",
99843
99978
  requires: ["react-compiler"],
99844
- recommendation: "Delete the `useMemo` / `useCallback` / `memo` call and use the plain value or component. React Compiler caches it for you.",
99979
+ recommendation: "Profile compiler-managed code and remove `useMemo`, `useCallback`, or `memo` only when the manual cache no longer carries behavioral or performance intent.",
99845
99980
  create: (context) => ({ CallExpression(node) {
99846
99981
  const apiName = resolveReactApiNameForCallee(node.callee, context);
99847
99982
  if (!apiName) return;
@@ -106449,7 +106584,7 @@ const rnAnimateLayoutProperty = defineRetiredRule({
106449
106584
  });
106450
106585
  //#endregion
106451
106586
  //#region src/plugin/rules/react-native/rn-animation-reaction-as-derived.ts
106452
- const REANIMATED_MODULE_SOURCE = "react-native-reanimated";
106587
+ const REANIMATED_MODULE_SOURCE$1 = "react-native-reanimated";
106453
106588
  const rnAnimationReactionAsDerived = defineRule({
106454
106589
  id: "rn-animation-reaction-as-derived",
106455
106590
  title: "useAnimatedReaction just copies a value",
@@ -106459,7 +106594,7 @@ const rnAnimationReactionAsDerived = defineRule({
106459
106594
  recommendation: "This useAnimatedReaction just copies one value to another. Replace it with `useDerivedValue(() => ..., [deps])`, which is shorter and tracks changes for you.",
106460
106595
  create: (context) => ({ CallExpression(node) {
106461
106596
  if (!isNodeOfType(node.callee, "Identifier") || node.callee.name !== "useAnimatedReaction") return;
106462
- if (getImportSourceForName(node, node.callee.name) !== REANIMATED_MODULE_SOURCE) return;
106597
+ if (getImportSourceForName(node, node.callee.name) !== REANIMATED_MODULE_SOURCE$1) return;
106463
106598
  const reactionFn = node.arguments?.[1];
106464
106599
  if (!reactionFn) return;
106465
106600
  if (!isNodeOfType(reactionFn, "ArrowFunctionExpression") && !isNodeOfType(reactionFn, "FunctionExpression")) return;
@@ -106483,6 +106618,69 @@ const rnAnimationReactionAsDerived = defineRule({
106483
106618
  } })
106484
106619
  });
106485
106620
  //#endregion
106621
+ //#region src/plugin/rules/react-native/rn-bottom-sheet-no-ignored-scroll-prop.ts
106622
+ const GORHOM_BOTTOM_SHEET_MODULE$2 = "@gorhom/bottom-sheet";
106623
+ const IGNORED_SCROLL_PROPERTY_NAMES = new Set([
106624
+ "decelerationRate",
106625
+ "onScrollBeginDrag",
106626
+ "scrollEventThrottle"
106627
+ ]);
106628
+ const rnBottomSheetNoIgnoredScrollProp = defineRule({
106629
+ id: "rn-bottom-sheet-no-ignored-scroll-prop",
106630
+ title: "Ignored BottomSheetScrollView prop",
106631
+ requires: ["react-native"],
106632
+ severity: "warn",
106633
+ recommendation: "Remove scrollEventThrottle, decelerationRate, and onScrollBeginDrag from BottomSheetScrollView because the component ignores them.",
106634
+ create: (context) => ({ JSXOpeningElement(node) {
106635
+ if (resolveImportedJsxComponentName(node, GORHOM_BOTTOM_SHEET_MODULE$2, context.scopes) !== "BottomSheetScrollView") return;
106636
+ for (const attribute of node.attributes) {
106637
+ if (!isNodeOfType(attribute, "JSXAttribute")) continue;
106638
+ const propertyName = getJsxAttributeName(attribute.name);
106639
+ if (!propertyName || !IGNORED_SCROLL_PROPERTY_NAMES.has(propertyName)) continue;
106640
+ context.report({
106641
+ node: attribute,
106642
+ message: `BottomSheetScrollView ignores \`${propertyName}\`, so this prop cannot affect scrolling. Remove it or handle the behavior outside the scrollable.`
106643
+ });
106644
+ }
106645
+ } })
106646
+ });
106647
+ //#endregion
106648
+ //#region src/plugin/rules/react-native/rn-bottom-sheet-no-state-in-on-animate.ts
106649
+ const GORHOM_BOTTOM_SHEET_MODULE$1 = "@gorhom/bottom-sheet";
106650
+ const BOTTOM_SHEET_CONTAINER_NAMES$1 = new Set([
106651
+ "BottomSheet",
106652
+ "BottomSheetModal",
106653
+ "default"
106654
+ ]);
106655
+ const rnBottomSheetNoStateInOnAnimate = defineRule({
106656
+ id: "rn-bottom-sheet-no-state-in-on-animate",
106657
+ title: "React state update in Bottom Sheet onAnimate",
106658
+ requires: ["react-native"],
106659
+ severity: "warn",
106660
+ recommendation: "Avoid starting React renders from onAnimate. Use animatedIndex or animatedPosition for animation-coupled UI, or onChange for committed index state.",
106661
+ create: (context) => ({ JSXOpeningElement(node) {
106662
+ const componentName = resolveImportedJsxComponentName(node, GORHOM_BOTTOM_SHEET_MODULE$1, context.scopes);
106663
+ if (!componentName || !BOTTOM_SHEET_CONTAINER_NAMES$1.has(componentName)) return;
106664
+ const onAnimateAttribute = findJsxAttribute(node.attributes, "onAnimate");
106665
+ if (!onAnimateAttribute?.value || !isNodeOfType(onAnimateAttribute.value, "JSXExpressionContainer")) return;
106666
+ const handler = resolveExactLocalFunction(onAnimateAttribute.value.expression, context.scopes);
106667
+ if (!handler) return;
106668
+ let stateSetterCall = null;
106669
+ walkOwnFunctionScope(handler, (child) => {
106670
+ if (stateSetterCall) return false;
106671
+ if (!isNodeOfType(child, "CallExpression") || !isNodeOfType(child.callee, "Identifier")) return;
106672
+ if (!resolveReactUseStatePair(child.callee, context.scopes)) return;
106673
+ stateSetterCall = child;
106674
+ return false;
106675
+ });
106676
+ if (!stateSetterCall) return;
106677
+ context.report({
106678
+ node: stateSetterCall,
106679
+ message: "This onAnimate handler starts a React state update as the Bottom Sheet begins moving, adding render work to the transition. Use animatedIndex or animatedPosition for animation-coupled UI."
106680
+ });
106681
+ } })
106682
+ });
106683
+ //#endregion
106486
106684
  //#region src/plugin/rules/react-native/rn-bottom-sheet-prefer-native.ts
106487
106685
  const JS_BOTTOM_SHEET_PACKAGES = new Set([
106488
106686
  "react-native-bottom-sheet",
@@ -106499,7 +106697,7 @@ const rnBottomSheetPreferNative = defineRule({
106499
106697
  tags: ["test-noise"],
106500
106698
  requires: ["react-native"],
106501
106699
  severity: "warn",
106502
- recommendation: "On RN v7+, use `<Modal presentationStyle=\"formSheet\">` so the sheet uses platform-native gestures, detents, accessibility, and presentation behavior.",
106700
+ recommendation: "When native presentation fits the design, use `<Modal presentationStyle=\"formSheet\">` for platform-native gestures, accessibility, and presentation behavior.",
106503
106701
  create: (context) => ({ ImportDeclaration(node) {
106504
106702
  const source = node.source?.value;
106505
106703
  if (typeof source !== "string" || !JS_BOTTOM_SHEET_PACKAGES.has(source)) return;
@@ -106511,6 +106709,45 @@ const rnBottomSheetPreferNative = defineRule({
106511
106709
  } })
106512
106710
  });
106513
106711
  //#endregion
106712
+ //#region src/plugin/rules/react-native/rn-bottom-sheet-use-integrated-scrollable.ts
106713
+ const GORHOM_BOTTOM_SHEET_MODULE = "@gorhom/bottom-sheet";
106714
+ const REACT_NATIVE_MODULE$1 = "react-native";
106715
+ const BOTTOM_SHEET_CONTAINER_NAMES = new Set([
106716
+ "BottomSheet",
106717
+ "BottomSheetModal",
106718
+ "default"
106719
+ ]);
106720
+ const REACT_NATIVE_SCROLLABLE_NAMES = new Set([
106721
+ "FlatList",
106722
+ "ScrollView",
106723
+ "SectionList",
106724
+ "VirtualizedList"
106725
+ ]);
106726
+ const rnBottomSheetUseIntegratedScrollable = defineRule({
106727
+ id: "rn-bottom-sheet-use-integrated-scrollable",
106728
+ title: "React Native scrollable inside a Bottom Sheet",
106729
+ requires: ["react-native"],
106730
+ severity: "warn",
106731
+ recommendation: "Use @gorhom/bottom-sheet's integrated BottomSheetScrollView, BottomSheetFlatList, BottomSheetSectionList, or BottomSheetVirtualizedList so gestures coordinate with the sheet.",
106732
+ create: (context) => {
106733
+ const reportedScrollables = /* @__PURE__ */ new WeakSet();
106734
+ return { JSXElement(node) {
106735
+ const containerName = resolveImportedJsxComponentName(node.openingElement, GORHOM_BOTTOM_SHEET_MODULE, context.scopes);
106736
+ if (!containerName || !BOTTOM_SHEET_CONTAINER_NAMES.has(containerName)) return;
106737
+ for (const descendant of getStaticJsxDescendantOpeningElements(node, { includeStaticExpressionBranches: true })) {
106738
+ if (reportedScrollables.has(descendant)) continue;
106739
+ const scrollableName = resolveImportedJsxComponentName(descendant, REACT_NATIVE_MODULE$1, context.scopes);
106740
+ if (!scrollableName || !REACT_NATIVE_SCROLLABLE_NAMES.has(scrollableName)) continue;
106741
+ reportedScrollables.add(descendant);
106742
+ context.report({
106743
+ node: descendant,
106744
+ message: `React Native's \`${scrollableName}\` does not coordinate gestures with this Bottom Sheet. Use \`BottomSheet${scrollableName}\` from @gorhom/bottom-sheet.`
106745
+ });
106746
+ }
106747
+ } };
106748
+ }
106749
+ });
106750
+ //#endregion
106514
106751
  //#region src/plugin/rules/react-native/rn-detox-missing-await.ts
106515
106752
  const EMPTY_VISITORS$6 = {};
106516
106753
  const DETOX_TEST_FILE = /(\.e2e\.[cm]?[jt]sx?$)|((^|\/)e2e\/)/;
@@ -106800,8 +107037,20 @@ const REACT_NATIVE_BUILTIN_LIST_COMPONENTS = new Set([
106800
107037
  ]);
106801
107038
  const RECYCLABLE_LIST_PACKAGES = {
106802
107039
  FlashList: ["@shopify/flash-list"],
106803
- LegendList: ["@legendapp/list"]
106804
- };
107040
+ AnimatedFlashList: ["@shopify/flash-list"],
107041
+ LegendList: ["@legendapp/list", "@legendapp/list/react-native"],
107042
+ AnimatedLegendList: ["@legendapp/list/animated", "@legendapp/list/reanimated"],
107043
+ KeyboardAwareLegendList: ["@legendapp/list/keyboard"],
107044
+ KeyboardAvoidingLegendList: ["@legendapp/list/keyboard-legacy"]
107045
+ };
107046
+ const SHOPIFY_FLASH_LIST_COMPONENTS = new Set(["FlashList", "AnimatedFlashList"]);
107047
+ const LEGEND_LIST_V3_PACKAGE_SOURCES = new Set([
107048
+ "@legendapp/list/react-native",
107049
+ "@legendapp/list/animated",
107050
+ "@legendapp/list/reanimated",
107051
+ "@legendapp/list/keyboard",
107052
+ "@legendapp/list/keyboard-legacy"
107053
+ ]);
106805
107054
  const RECYCLABLE_LIST_PACKAGE_SOURCES = Object.values(RECYCLABLE_LIST_PACKAGES).flat();
106806
107055
  const REACT_NATIVE_LIST_COMPONENTS = new Set([...REACT_NATIVE_BUILTIN_LIST_COMPONENTS, ...Object.keys(RECYCLABLE_LIST_PACKAGES)]);
106807
107056
  const RENDER_ITEM_PROP_NAMES = new Set([
@@ -106889,21 +107138,9 @@ const getInitializerModuleSource = (contextNode, initializer) => {
106889
107138
  };
106890
107139
  //#endregion
106891
107140
  //#region src/plugin/rules/react-native/utils/resolve-imported-recycler-name.ts
106892
- const getJsxMemberObjectName = (node) => {
106893
- if (!isNodeOfType(node, "JSXOpeningElement")) return null;
106894
- const elementName = node.name;
106895
- if (!elementName || !isNodeOfType(elementName, "JSXMemberExpression")) return null;
106896
- return isNodeOfType(elementName.object, "JSXIdentifier") ? elementName.object.name : null;
106897
- };
106898
- const resolveImportedRecyclerName = (node, localName, options) => {
106899
- const jsxMemberObjectName = options?.allowNamespaceMemberAccess ? getJsxMemberObjectName(node) : null;
106900
- for (const [canonicalName, packageSources] of Object.entries(RECYCLABLE_LIST_PACKAGES)) {
106901
- if (jsxMemberObjectName !== null) {
106902
- if (localName === canonicalName && packageSources.some((packageSource) => isNamespaceImportFromModule$1(node, jsxMemberObjectName, packageSource))) return canonicalName;
106903
- continue;
106904
- }
106905
- if (packageSources.some((packageSource) => getImportedNameFromModule(node, localName, packageSource) === canonicalName)) return canonicalName;
106906
- }
107141
+ const resolveImportedRecyclerName = (node, scopes, options) => {
107142
+ if (isNodeOfType(node.name, "JSXMemberExpression") && !options?.allowNamespaceMemberAccess) return null;
107143
+ for (const [canonicalName, packageSources] of Object.entries(RECYCLABLE_LIST_PACKAGES)) for (const packageSource of packageSources) if (resolveImportedJsxComponentName(node, packageSource, scopes) === canonicalName) return canonicalName;
106907
107144
  return null;
106908
107145
  };
106909
107146
  //#endregion
@@ -106923,8 +107160,8 @@ const isLocalBindingReactNativeList = (node, elementName) => {
106923
107160
  const initializerModuleSource = getInitializerModuleSource(node, declaratorInitializer);
106924
107161
  return initializerModuleSource !== null && REACT_NATIVE_LIST_MODULE_SOURCES.has(initializerModuleSource);
106925
107162
  };
106926
- const isVirtualizedList = (node, elementName) => {
106927
- if (resolveImportedRecyclerName(node, elementName, { allowNamespaceMemberAccess: true }) !== null) return true;
107163
+ const isVirtualizedList = (node, elementName, scopes) => {
107164
+ if (resolveImportedRecyclerName(node, scopes, { allowNamespaceMemberAccess: true }) !== null) return true;
106928
107165
  if (isNodeOfType(node.name, "JSXMemberExpression")) {
106929
107166
  if (!REACT_NATIVE_BUILTIN_LIST_COMPONENTS.has(elementName)) return false;
106930
107167
  const memberObjectName = getJsxMemberRootObjectName(node.name);
@@ -106981,7 +107218,7 @@ const rnListDataMapped = defineRule({
106981
107218
  recommendation: "This builds a new array each time the parent redraws, so every row redraws too. Wrap it in `useMemo(() => items.map(...), [items])` to keep the same array.",
106982
107219
  create: (context) => ({ JSXOpeningElement(node) {
106983
107220
  const elementName = resolveJsxElementName(node);
106984
- if (!elementName || !isVirtualizedList(node, elementName)) return;
107221
+ if (!elementName || !isVirtualizedList(node, elementName, context.scopes)) return;
106985
107222
  for (const attr of node.attributes ?? []) {
106986
107223
  if (!isNodeOfType(attr, "JSXAttribute")) continue;
106987
107224
  if (!isNodeOfType(attr.name, "JSXIdentifier") || attr.name.name !== "data") continue;
@@ -106997,12 +107234,14 @@ const rnListDataMapped = defineRule({
106997
107234
  } })
106998
107235
  });
106999
107236
  //#endregion
107000
- //#region src/plugin/rules/react-native/rn-list-missing-estimated-item-size.ts
107001
- const SIZING_HINT_ATTRIBUTE_NAMES = new Set(["estimatedItemSize", "estimatedListSize"]);
107237
+ //#region src/plugin/rules/react-native/utils/is-flash-list-v2-or-newer.ts
107002
107238
  const isFlashListV2OrNewer = (context) => {
107003
107239
  const flashListMajorVersion = getReactDoctorNumberSetting(context.settings, "shopifyFlashListMajorVersion");
107004
107240
  return flashListMajorVersion !== void 0 && flashListMajorVersion >= 2;
107005
107241
  };
107242
+ //#endregion
107243
+ //#region src/plugin/rules/react-native/rn-list-missing-estimated-item-size.ts
107244
+ const SIZING_HINT_ATTRIBUTE_NAMES = new Set(["estimatedItemSize", "estimatedListSize"]);
107006
107245
  const isEmptyArrayLiteral = (node) => {
107007
107246
  if (!isNodeOfType(node.value, "JSXExpressionContainer")) return false;
107008
107247
  const expression = node.value.expression;
@@ -107025,9 +107264,10 @@ const rnListMissingEstimatedItemSize = defineRule({
107025
107264
  if (!fileImportsRecycler) return;
107026
107265
  const localElementName = resolveJsxElementName(node);
107027
107266
  if (!localElementName) return;
107028
- const canonicalRecyclerName = resolveImportedRecyclerName(node, localElementName);
107267
+ const canonicalRecyclerName = resolveImportedRecyclerName(node, context.scopes);
107029
107268
  if (canonicalRecyclerName === null) return;
107030
- if (canonicalRecyclerName === "FlashList" && isFlashListV2OrNewer(context)) return;
107269
+ if ([...LEGEND_LIST_V3_PACKAGE_SOURCES].some((packageSource) => resolveImportedJsxComponentName(node, packageSource, context.scopes) !== null)) return;
107270
+ if (SHOPIFY_FLASH_LIST_COMPONENTS.has(canonicalRecyclerName) && isFlashListV2OrNewer(context)) return;
107031
107271
  let hasSizingHint = false;
107032
107272
  let dataIsEmptyLiteral = false;
107033
107273
  let hasDataProp = false;
@@ -107054,15 +107294,1272 @@ const rnListMissingEstimatedItemSize = defineRule({
107054
107294
  });
107055
107295
  //#endregion
107056
107296
  //#region src/plugin/rules/react-native/rn-list-recyclable-without-types.ts
107297
+ const RENDER_ITEM_INPUT_NAMES = new Set(["item", "index"]);
107298
+ const EMPTY_RENDERED_ROOT_NAME = "empty";
107299
+ const isSymbolStable = (symbol) => symbol.references.every((reference) => reference.flag === "read");
107300
+ const getSymbolVariableDeclarator = (symbol) => {
107301
+ let declaration = symbol.declarationNode;
107302
+ while (declaration && !isNodeOfType(declaration, "VariableDeclarator")) declaration = declaration.parent;
107303
+ return declaration && isNodeOfType(declaration, "VariableDeclarator") ? declaration : null;
107304
+ };
107305
+ const getConstInitializerExpressions = (symbol) => {
107306
+ if (symbol.kind !== "const" || !symbol.initializer) return [];
107307
+ const declarationInitializer = getSymbolVariableDeclarator(symbol)?.init;
107308
+ return declarationInitializer && declarationInitializer !== symbol.initializer ? [declarationInitializer, symbol.initializer] : [symbol.initializer];
107309
+ };
107310
+ const getSymbolIdentity = (symbol) => {
107311
+ if (symbol.kind !== "import") return `symbol:${symbol.id}`;
107312
+ const source = getImportDeclarationForSymbol(symbol)?.source.value;
107313
+ if (typeof source !== "string") return `symbol:${symbol.id}`;
107314
+ if (isNodeOfType(symbol.declarationNode, "ImportDefaultSpecifier")) return `import:${source}:default`;
107315
+ if (isNodeOfType(symbol.declarationNode, "ImportNamespaceSpecifier")) return `import:${source}:*`;
107316
+ return `import:${source}:${getImportedName(symbol.declarationNode) ?? symbol.name}`;
107317
+ };
107318
+ const appendComponentMemberIdentity = (receiverIdentity, propertyName) => {
107319
+ if (!receiverIdentity || !receiverIdentity.startsWith("import:") && !receiverIdentity.startsWith("global:")) return null;
107320
+ if (receiverIdentity.endsWith(":*")) return `${receiverIdentity.slice(0, -1)}${propertyName}`;
107321
+ return `${receiverIdentity}.${propertyName}`;
107322
+ };
107323
+ const getComponentReferenceIdentity = (expression, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
107324
+ const componentReference = stripParenExpression(expression);
107325
+ if (isNodeOfType(componentReference, "Identifier") || isNodeOfType(componentReference, "JSXIdentifier")) {
107326
+ const symbol = scopes.symbolFor(componentReference);
107327
+ if (!symbol) return `global:${componentReference.name}`;
107328
+ if (visitedSymbolIds.has(symbol.id) || !isSymbolStable(symbol)) return null;
107329
+ visitedSymbolIds.add(symbol.id);
107330
+ if (symbol.kind === "import" || symbol.kind === "function" || symbol.kind === "class") return getSymbolIdentity(symbol);
107331
+ if (symbol.kind !== "const" || !symbol.initializer) return null;
107332
+ const initializer = stripParenExpression(symbol.initializer);
107333
+ const destructuredPropertyName = getDestructuredBindingPropertyName(symbol.bindingIdentifier);
107334
+ if (destructuredPropertyName) return appendComponentMemberIdentity(getComponentReferenceIdentity(initializer, scopes, visitedSymbolIds), destructuredPropertyName);
107335
+ const isProvenReactHocCall = isNodeOfType(initializer, "CallExpression") && (isReactApiCall(initializer, "memo", scopes, { resolveNamedAliases: true }) || isReactApiCall(initializer, "forwardRef", scopes, { resolveNamedAliases: true })) && initializer.arguments[0] !== void 0 && !isNodeOfType(initializer.arguments[0], "SpreadElement");
107336
+ if (isFunctionLike$1(initializer) || isNodeOfType(initializer, "ClassExpression") || isProvenReactHocCall) return getSymbolIdentity(symbol);
107337
+ if (!isNodeOfType(initializer, "Identifier") && !isNodeOfType(initializer, "MemberExpression")) return null;
107338
+ return getComponentReferenceIdentity(initializer, scopes, visitedSymbolIds);
107339
+ }
107340
+ if (!isNodeOfType(componentReference, "MemberExpression")) return null;
107341
+ const propertyName = getStaticPropertyName(componentReference);
107342
+ if (propertyName === null) return null;
107343
+ return appendComponentMemberIdentity(getComponentReferenceIdentity(componentReference.object, scopes, visitedSymbolIds), propertyName);
107344
+ };
107345
+ const getJsxElementIdentity = (node, scopes) => {
107346
+ if (isNodeOfType(node, "JSXIdentifier")) {
107347
+ const identity = getComponentReferenceIdentity(node, scopes);
107348
+ if (identity !== `global:${node.name}`) return identity;
107349
+ return /^[a-z]/u.test(node.name) ? `intrinsic:${node.name}` : identity;
107350
+ }
107351
+ if (!isNodeOfType(node, "JSXMemberExpression")) return null;
107352
+ const objectIdentity = getJsxElementIdentity(node.object, scopes);
107353
+ if (!isNodeOfType(node.property, "JSXIdentifier")) return null;
107354
+ return appendComponentMemberIdentity(objectIdentity, node.property.name);
107355
+ };
107356
+ const isStaticallyEmptyJsxChild = (node) => {
107357
+ const expression = getFinalSequenceExpressionValue(node);
107358
+ if (isNodeOfType(expression, "JSXEmptyExpression")) return true;
107359
+ if (isNodeOfType(expression, "Literal") && (expression.value === null || typeof expression.value === "boolean")) return true;
107360
+ if (isNodeOfType(expression, "UnaryExpression")) return expression.operator === "!" || expression.operator === "void";
107361
+ if (!isNodeOfType(expression, "BinaryExpression")) return false;
107362
+ switch (expression.operator) {
107363
+ case "==":
107364
+ case "!=":
107365
+ case "===":
107366
+ case "!==":
107367
+ case "<":
107368
+ case "<=":
107369
+ case ">":
107370
+ case ">=":
107371
+ case "in":
107372
+ case "instanceof": return true;
107373
+ default: return false;
107374
+ }
107375
+ };
107376
+ const getStaticSelectorBindingPath = (pattern, bindingIdentifier, scopes) => {
107377
+ if (pattern === bindingIdentifier) return [];
107378
+ if (isNodeOfType(pattern, "AssignmentPattern")) return readStaticSelectorTruthiness(pattern.right, scopes) === false ? getStaticSelectorBindingPath(pattern.left, bindingIdentifier, scopes) : null;
107379
+ if (isNodeOfType(pattern, "RestElement")) return null;
107380
+ if (isNodeOfType(pattern, "ArrayPattern")) {
107381
+ for (const [elementIndex, element] of pattern.elements.entries()) {
107382
+ if (!element) continue;
107383
+ const nestedPath = getStaticSelectorBindingPath(element, bindingIdentifier, scopes);
107384
+ if (nestedPath !== null) return [String(elementIndex), ...nestedPath];
107385
+ }
107386
+ return null;
107387
+ }
107388
+ if (!isNodeOfType(pattern, "ObjectPattern")) return null;
107389
+ for (const property of pattern.properties) {
107390
+ if (!isNodeOfType(property, "Property")) continue;
107391
+ const nestedPath = getStaticSelectorBindingPath(property.value, bindingIdentifier, scopes);
107392
+ if (nestedPath === null) continue;
107393
+ const propertyName = getStaticPropertyKeyName(property, { allowComputedString: true });
107394
+ return propertyName === null ? null : [propertyName, ...nestedPath];
107395
+ }
107396
+ return null;
107397
+ };
107398
+ const getStaticSelectorPropertyName = (memberExpression) => getStaticPropertyName(memberExpression) ?? getStaticPropertyKeyName(memberExpression, {
107399
+ allowComputedString: true,
107400
+ stringifyNonStringLiterals: true
107401
+ });
107402
+ const getSelectorReferenceKey = (expression, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
107403
+ const selector = stripParenExpression(expression);
107404
+ if (isNodeOfType(selector, "Identifier")) {
107405
+ const symbol = scopes.referenceFor(selector)?.resolvedSymbol;
107406
+ if (!symbol || !isSymbolStable(symbol) || visitedSymbolIds.has(symbol.id)) return null;
107407
+ if (symbol.kind === "const" && symbol.initializer) {
107408
+ visitedSymbolIds.add(symbol.id);
107409
+ const declaration = getSymbolVariableDeclarator(symbol);
107410
+ if (declaration?.id === symbol.bindingIdentifier) return getSelectorReferenceKey(symbol.initializer, scopes, visitedSymbolIds) ?? JSON.stringify(["symbol", symbol.id]);
107411
+ if (declaration?.init) {
107412
+ const bindingPath = getStaticSelectorBindingPath(declaration.id, symbol.bindingIdentifier, scopes);
107413
+ let receiverKey = getSelectorReferenceKey(declaration.init, scopes, visitedSymbolIds);
107414
+ if (bindingPath !== null && receiverKey !== null) {
107415
+ for (const propertyName of bindingPath) receiverKey = JSON.stringify([
107416
+ "member",
107417
+ receiverKey,
107418
+ propertyName
107419
+ ]);
107420
+ return receiverKey;
107421
+ }
107422
+ }
107423
+ return JSON.stringify(["symbol", symbol.id]);
107424
+ }
107425
+ return JSON.stringify(["symbol", symbol.id]);
107426
+ }
107427
+ if (!isNodeOfType(selector, "MemberExpression")) return null;
107428
+ const propertyName = getStaticSelectorPropertyName(selector);
107429
+ if (propertyName === null) return null;
107430
+ const receiverKey = getSelectorReferenceKey(selector.object, scopes, visitedSymbolIds);
107431
+ return receiverKey === null ? null : JSON.stringify([
107432
+ "member",
107433
+ receiverKey,
107434
+ propertyName
107435
+ ]);
107436
+ };
107437
+ const getStaticComparisonOperandKey = (expression, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
107438
+ const operand = stripParenExpression(expression);
107439
+ if (isNodeOfType(operand, "Identifier")) {
107440
+ const symbol = scopes.referenceFor(operand)?.resolvedSymbol;
107441
+ if (symbol?.kind === "const" && symbol.initializer && isSymbolStable(symbol) && getSymbolVariableDeclarator(symbol)?.id === symbol.bindingIdentifier && !visitedSymbolIds.has(symbol.id)) {
107442
+ visitedSymbolIds.add(symbol.id);
107443
+ return getStaticComparisonOperandKey(symbol.initializer, scopes, visitedSymbolIds) ?? JSON.stringify(["symbol", symbol.id]);
107444
+ }
107445
+ }
107446
+ if (isNodeOfType(operand, "UnaryExpression") && operand.operator === "typeof") {
107447
+ const argumentKey = getSelectorReferenceKey(operand.argument, scopes, visitedSymbolIds);
107448
+ return argumentKey === null ? null : JSON.stringify(["typeof", argumentKey]);
107449
+ }
107450
+ return getSelectorReferenceKey(operand, scopes, visitedSymbolIds);
107451
+ };
107452
+ const getStaticPrimitiveLiteralKey = (expression) => {
107453
+ const literal = stripParenExpression(expression);
107454
+ if (isNodeOfType(literal, "UnaryExpression") && (literal.operator === "-" || literal.operator === "+")) {
107455
+ const argument = stripParenExpression(literal.argument);
107456
+ if (isNodeOfType(argument, "Literal") && typeof argument.value === "number") {
107457
+ const numericValue = literal.operator === "-" ? -argument.value : argument.value;
107458
+ return `number:${String(numericValue)}`;
107459
+ }
107460
+ }
107461
+ if (!isNodeOfType(literal, "Literal")) return null;
107462
+ if (literal.value === null) return "null";
107463
+ if (typeof literal.value === "string") return `string:${JSON.stringify(literal.value)}`;
107464
+ if (typeof literal.value === "number") return `number:${String(literal.value)}`;
107465
+ if (typeof literal.value === "boolean") return `boolean:${String(literal.value)}`;
107466
+ if (typeof literal.value === "bigint") return `bigint:${String(literal.value)}`;
107467
+ return null;
107468
+ };
107469
+ const getImportedStaticReferenceKey = (expression, scopes) => {
107470
+ const reference = stripParenExpression(expression);
107471
+ if (isNodeOfType(reference, "Identifier")) {
107472
+ const symbol = scopes.referenceFor(reference)?.resolvedSymbol;
107473
+ return symbol?.kind === "import" ? getSymbolIdentity(symbol) : null;
107474
+ }
107475
+ if (!isNodeOfType(reference, "MemberExpression")) return null;
107476
+ const propertyName = getStaticPropertyName(reference);
107477
+ if (propertyName === null) return null;
107478
+ const receiverKey = getImportedStaticReferenceKey(reference.object, scopes);
107479
+ return receiverKey === null ? null : JSON.stringify([
107480
+ "member",
107481
+ receiverKey,
107482
+ propertyName
107483
+ ]);
107484
+ };
107485
+ const getStaticComparisonConstantKey = (expression, scopes) => getStaticPrimitiveLiteralKey(expression) ?? getImportedStaticReferenceKey(expression, scopes);
107486
+ const getStaticSelectorIdentity = (expression, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
107487
+ const selector = getFinalSequenceExpressionValue(expression);
107488
+ if (isNodeOfType(selector, "Identifier")) {
107489
+ const symbol = scopes.referenceFor(selector)?.resolvedSymbol;
107490
+ if (symbol?.kind === "const" && symbol.initializer && isSymbolStable(symbol) && getSymbolVariableDeclarator(symbol)?.id === symbol.bindingIdentifier && !visitedSymbolIds.has(symbol.id)) {
107491
+ visitedSymbolIds.add(symbol.id);
107492
+ const initializerIdentity = getStaticSelectorIdentity(symbol.initializer, scopes, visitedSymbolIds);
107493
+ if (initializerIdentity) return initializerIdentity;
107494
+ }
107495
+ }
107496
+ if (isNodeOfType(selector, "UnaryExpression") && selector.operator === "!") {
107497
+ const argumentIdentity = getStaticSelectorIdentity(selector.argument, scopes, visitedSymbolIds);
107498
+ return argumentIdentity ? {
107499
+ isInverted: !argumentIdentity.isInverted,
107500
+ key: argumentIdentity.key
107501
+ } : null;
107502
+ }
107503
+ if (isNodeOfType(selector, "BinaryExpression") && [
107504
+ "==",
107505
+ "!=",
107506
+ "===",
107507
+ "!=="
107508
+ ].includes(selector.operator)) {
107509
+ const operandPairs = [{
107510
+ literal: selector.right,
107511
+ selectorOperand: selector.left
107512
+ }, {
107513
+ literal: selector.left,
107514
+ selectorOperand: selector.right
107515
+ }];
107516
+ for (const operandPair of operandPairs) {
107517
+ const constantKey = getStaticComparisonConstantKey(operandPair.literal, scopes);
107518
+ if (constantKey === null) continue;
107519
+ const operandKey = getStaticComparisonOperandKey(operandPair.selectorOperand, scopes);
107520
+ if (operandKey === null) continue;
107521
+ return {
107522
+ isInverted: selector.operator === "!=" || selector.operator === "!==",
107523
+ key: JSON.stringify([
107524
+ "comparison",
107525
+ selector.operator.length === 3 ? "strict" : "loose",
107526
+ operandKey,
107527
+ constantKey
107528
+ ])
107529
+ };
107530
+ }
107531
+ return null;
107532
+ }
107533
+ if (isNodeOfType(selector, "BinaryExpression") && [
107534
+ "<",
107535
+ "<=",
107536
+ ">",
107537
+ ">=",
107538
+ "in",
107539
+ "instanceof"
107540
+ ].includes(selector.operator)) {
107541
+ const leftKey = getStaticPrimitiveLiteralKey(selector.left) ?? getStaticComparisonOperandKey(selector.left, scopes);
107542
+ const rightKey = getStaticPrimitiveLiteralKey(selector.right) ?? getStaticComparisonOperandKey(selector.right, scopes);
107543
+ if (leftKey !== null && rightKey !== null) return {
107544
+ isInverted: false,
107545
+ key: JSON.stringify([
107546
+ "binary-comparison",
107547
+ selector.operator,
107548
+ leftKey,
107549
+ rightKey
107550
+ ])
107551
+ };
107552
+ }
107553
+ const key = getSelectorReferenceKey(selector, scopes);
107554
+ return key === null ? null : {
107555
+ isInverted: false,
107556
+ key
107557
+ };
107558
+ };
107559
+ const getRenderedRootShapeAlternativeKey = (alternative) => JSON.stringify({
107560
+ facts: [...alternative.facts].map(([key, fact]) => ({
107561
+ key,
107562
+ outcome: fact.outcome
107563
+ })).sort((firstFact, secondFact) => firstFact.key.localeCompare(secondFact.key)),
107564
+ roots: alternative.roots
107565
+ });
107566
+ const getRenderedRootFactStateKey = (alternative) => JSON.stringify([...alternative.facts].map(([key, fact]) => ({
107567
+ key,
107568
+ outcome: fact.outcome
107569
+ })).sort((firstFact, secondFact) => firstFact.key.localeCompare(secondFact.key)));
107570
+ const deduplicateRenderedRootShapeAlternatives = (alternatives) => {
107571
+ const deduplicatedAlternatives = [];
107572
+ const alternativeKeys = /* @__PURE__ */ new Set();
107573
+ const alternativeCountsByFactState = /* @__PURE__ */ new Map();
107574
+ for (const alternative of alternatives) {
107575
+ const alternativeKey = getRenderedRootShapeAlternativeKey(alternative);
107576
+ if (alternativeKeys.has(alternativeKey)) continue;
107577
+ const factStateKey = getRenderedRootFactStateKey(alternative);
107578
+ const factStateAlternativeCount = alternativeCountsByFactState.get(factStateKey) ?? 0;
107579
+ if (factStateAlternativeCount > 1) continue;
107580
+ alternativeKeys.add(alternativeKey);
107581
+ alternativeCountsByFactState.set(factStateKey, factStateAlternativeCount + 1);
107582
+ deduplicatedAlternatives.push(alternative);
107583
+ if (deduplicatedAlternatives.length > 64) return null;
107584
+ }
107585
+ return deduplicatedAlternatives;
107586
+ };
107587
+ const addRenderedRootSelectorFact = (alternatives, identity, expressionOutcome, selector) => {
107588
+ const outcome = identity.isInverted ? !expressionOutcome : expressionOutcome;
107589
+ const constrainedAlternatives = [];
107590
+ for (const alternative of alternatives) {
107591
+ const existingFact = alternative.facts.get(identity.key);
107592
+ if (existingFact && existingFact.outcome !== outcome) continue;
107593
+ constrainedAlternatives.push({
107594
+ facts: new Map(alternative.facts).set(identity.key, {
107595
+ outcome,
107596
+ selector
107597
+ }),
107598
+ roots: alternative.roots
107599
+ });
107600
+ }
107601
+ return constrainedAlternatives;
107602
+ };
107603
+ const mergeRenderedRootShapeAlternatives = (existingAlternatives, appendedAlternatives) => {
107604
+ const mergedAlternatives = [];
107605
+ for (const existingAlternative of existingAlternatives) for (const appendedAlternative of appendedAlternatives) {
107606
+ const mergedFacts = new Map(existingAlternative.facts);
107607
+ let hasContradictoryFact = false;
107608
+ for (const [key, appendedFact] of appendedAlternative.facts) {
107609
+ const existingFact = mergedFacts.get(key);
107610
+ if (existingFact && existingFact.outcome !== appendedFact.outcome) {
107611
+ hasContradictoryFact = true;
107612
+ break;
107613
+ }
107614
+ mergedFacts.set(key, appendedFact);
107615
+ }
107616
+ if (hasContradictoryFact) continue;
107617
+ mergedAlternatives.push({
107618
+ facts: mergedFacts,
107619
+ roots: [...existingAlternative.roots, ...appendedAlternative.roots]
107620
+ });
107621
+ }
107622
+ return deduplicateRenderedRootShapeAlternatives(mergedAlternatives);
107623
+ };
107624
+ const combineRenderedRootShapeAlternativeBranches = (branches) => deduplicateRenderedRootShapeAlternatives(branches.flat());
107625
+ const getStaticRenderedRootAlternatives = (node, scopes) => {
107626
+ const renderedNode = getFinalSequenceExpressionValue(node);
107627
+ if (isNodeOfType(renderedNode, "JSXElement") && !isJsxFragmentElement(renderedNode.openingElement, scopes)) {
107628
+ const elementIdentity = getJsxElementIdentity(renderedNode.openingElement.name, scopes);
107629
+ return elementIdentity === null ? null : [{
107630
+ facts: /* @__PURE__ */ new Map(),
107631
+ roots: [elementIdentity]
107632
+ }];
107633
+ }
107634
+ if (isNodeOfType(renderedNode, "JSXElement") || isNodeOfType(renderedNode, "JSXFragment")) {
107635
+ let alternatives = [{
107636
+ facts: /* @__PURE__ */ new Map(),
107637
+ roots: []
107638
+ }];
107639
+ for (const child of renderedNode.children) {
107640
+ const childAlternatives = getStaticRenderedRootAlternatives(child, scopes);
107641
+ if (childAlternatives === null) return null;
107642
+ const mergedAlternatives = mergeRenderedRootShapeAlternatives(alternatives, childAlternatives);
107643
+ if (mergedAlternatives === null) return null;
107644
+ alternatives = mergedAlternatives;
107645
+ }
107646
+ return alternatives;
107647
+ }
107648
+ if (isNodeOfType(renderedNode, "JSXText")) return renderedNode.value?.trim() ? null : [{
107649
+ facts: /* @__PURE__ */ new Map(),
107650
+ roots: []
107651
+ }];
107652
+ if (isNodeOfType(renderedNode, "JSXExpressionContainer")) return getStaticRenderedRootAlternatives(renderedNode.expression, scopes);
107653
+ if (isStaticallyEmptyJsxChild(renderedNode)) return [{
107654
+ facts: /* @__PURE__ */ new Map(),
107655
+ roots: []
107656
+ }];
107657
+ if (isNodeOfType(renderedNode, "ConditionalExpression")) {
107658
+ const staticTestValue = readStaticSelectorTruthiness(renderedNode.test, scopes);
107659
+ if (staticTestValue !== null) return getStaticRenderedRootAlternatives(staticTestValue ? renderedNode.consequent : renderedNode.alternate, scopes);
107660
+ const consequentAlternatives = getStaticRenderedRootAlternatives(renderedNode.consequent, scopes);
107661
+ const alternateAlternatives = getStaticRenderedRootAlternatives(renderedNode.alternate, scopes);
107662
+ if (consequentAlternatives === null || alternateAlternatives === null) return null;
107663
+ const selectorIdentity = getStaticSelectorIdentity(renderedNode.test, scopes);
107664
+ return combineRenderedRootShapeAlternativeBranches([selectorIdentity ? addRenderedRootSelectorFact(consequentAlternatives, selectorIdentity, true, renderedNode.test) : consequentAlternatives, selectorIdentity ? addRenderedRootSelectorFact(alternateAlternatives, selectorIdentity, false, renderedNode.test) : alternateAlternatives]);
107665
+ }
107666
+ if (isNodeOfType(renderedNode, "LogicalExpression")) {
107667
+ const selectorIdentity = (renderedNode.operator === "&&" || renderedNode.operator === "||") && isStaticallyEmptyJsxChild(renderedNode.left) ? getStaticSelectorIdentity(renderedNode.left, scopes) : null;
107668
+ if (selectorIdentity) {
107669
+ const rightAlternatives = getStaticRenderedRootAlternatives(renderedNode.right, scopes);
107670
+ if (rightAlternatives === null) return null;
107671
+ const emptyAlternatives = [{
107672
+ facts: /* @__PURE__ */ new Map(),
107673
+ roots: []
107674
+ }];
107675
+ return combineRenderedRootShapeAlternativeBranches([addRenderedRootSelectorFact(renderedNode.operator === "&&" ? rightAlternatives : emptyAlternatives, selectorIdentity, true, renderedNode.left), addRenderedRootSelectorFact(renderedNode.operator === "&&" ? emptyAlternatives : rightAlternatives, selectorIdentity, false, renderedNode.left)]);
107676
+ }
107677
+ const resultAlternatives = [];
107678
+ for (const resultBranch of getStaticLogicalExpressionResultBranches(renderedNode)) {
107679
+ const branchAlternatives = getStaticRenderedRootAlternatives(resultBranch, scopes);
107680
+ if (branchAlternatives === null) return null;
107681
+ resultAlternatives.push(branchAlternatives);
107682
+ }
107683
+ return combineRenderedRootShapeAlternativeBranches(resultAlternatives);
107684
+ }
107685
+ return null;
107686
+ };
107687
+ const getFlattenedFragmentChildren = (node, scopes) => {
107688
+ const flattenChild = (child) => {
107689
+ const renderedChild = getFinalSequenceExpressionValue(child);
107690
+ if (isNodeOfType(renderedChild, "JSXExpressionContainer")) return flattenChild(renderedChild.expression);
107691
+ if (!isNodeOfType(renderedChild, "JSXFragment") && (!isNodeOfType(renderedChild, "JSXElement") || !isJsxFragmentElement(renderedChild.openingElement, scopes))) return [child];
107692
+ return renderedChild.children.flatMap(flattenChild);
107693
+ };
107694
+ const renderedNode = getFinalSequenceExpressionValue(node);
107695
+ if (!isNodeOfType(renderedNode, "JSXFragment") && (!isNodeOfType(renderedNode, "JSXElement") || !isJsxFragmentElement(renderedNode.openingElement, scopes))) return null;
107696
+ return renderedNode.children.flatMap(flattenChild);
107697
+ };
107698
+ const forgetFinalizedRenderedRootFacts = (alternatives, futureFactKeyCounts) => deduplicateRenderedRootShapeAlternatives(alternatives.map((alternative) => ({
107699
+ facts: new Map([...alternative.facts].filter(([key]) => (futureFactKeyCounts.get(key) ?? 0) > 0)),
107700
+ roots: alternative.roots
107701
+ })));
107702
+ const getStaticRenderedRootShapes = (node, scopes) => {
107703
+ let alternatives = getStaticRenderedRootAlternatives(node, scopes);
107704
+ if (alternatives === null) {
107705
+ const fragmentChildren = getFlattenedFragmentChildren(node, scopes);
107706
+ if (fragmentChildren === null) return null;
107707
+ const childAlternatives = [];
107708
+ for (const child of fragmentChildren) {
107709
+ const staticChildAlternatives = getStaticRenderedRootAlternatives(child, scopes);
107710
+ if (staticChildAlternatives === null) return null;
107711
+ childAlternatives.push(staticChildAlternatives);
107712
+ }
107713
+ const futureFactKeyCounts = /* @__PURE__ */ new Map();
107714
+ for (const staticChildAlternatives of childAlternatives) {
107715
+ const childFactKeys = /* @__PURE__ */ new Set();
107716
+ for (const alternative of staticChildAlternatives) for (const key of alternative.facts.keys()) childFactKeys.add(key);
107717
+ for (const key of childFactKeys) futureFactKeyCounts.set(key, (futureFactKeyCounts.get(key) ?? 0) + 1);
107718
+ }
107719
+ let prefixAlternatives = [{
107720
+ facts: /* @__PURE__ */ new Map(),
107721
+ roots: []
107722
+ }];
107723
+ let witnessAlternatives = null;
107724
+ for (const staticChildAlternatives of childAlternatives) {
107725
+ const currentFactKeys = /* @__PURE__ */ new Set();
107726
+ for (const alternative of staticChildAlternatives) for (const key of alternative.facts.keys()) currentFactKeys.add(key);
107727
+ for (const key of currentFactKeys) futureFactKeyCounts.set(key, (futureFactKeyCounts.get(key) ?? 1) - 1);
107728
+ const mergedAlternatives = mergeRenderedRootShapeAlternatives(prefixAlternatives, staticChildAlternatives);
107729
+ if (mergedAlternatives === null) break;
107730
+ prefixAlternatives = mergedAlternatives;
107731
+ for (let firstAlternativeIndex = 0; firstAlternativeIndex < prefixAlternatives.length; firstAlternativeIndex += 1) {
107732
+ const firstAlternative = prefixAlternatives[firstAlternativeIndex];
107733
+ for (let secondAlternativeIndex = firstAlternativeIndex + 1; secondAlternativeIndex < prefixAlternatives.length; secondAlternativeIndex += 1) {
107734
+ const secondAlternative = prefixAlternatives[secondAlternativeIndex];
107735
+ if (JSON.stringify(firstAlternative.roots) === JSON.stringify(secondAlternative.roots)) continue;
107736
+ if ([...firstAlternative.facts].some(([key, firstFact]) => {
107737
+ const secondFact = secondAlternative.facts.get(key);
107738
+ return futureFactKeyCounts.get(key) === 0 && secondFact !== void 0 && secondFact.outcome !== firstFact.outcome;
107739
+ })) {
107740
+ witnessAlternatives = [firstAlternative, secondAlternative];
107741
+ break;
107742
+ }
107743
+ }
107744
+ if (witnessAlternatives) break;
107745
+ }
107746
+ if (witnessAlternatives) break;
107747
+ const remainingAlternatives = forgetFinalizedRenderedRootFacts(prefixAlternatives, futureFactKeyCounts);
107748
+ if (remainingAlternatives === null) break;
107749
+ prefixAlternatives = remainingAlternatives;
107750
+ }
107751
+ if (witnessAlternatives === null) return null;
107752
+ alternatives = witnessAlternatives;
107753
+ }
107754
+ const rootShapes = [];
107755
+ const rootShapeKeys = /* @__PURE__ */ new Set();
107756
+ for (const alternative of alternatives) {
107757
+ const rootShapeKey = JSON.stringify(alternative.roots);
107758
+ if (rootShapeKeys.has(rootShapeKey)) continue;
107759
+ rootShapeKeys.add(rootShapeKey);
107760
+ rootShapes.push([...alternative.roots]);
107761
+ }
107762
+ return rootShapes;
107763
+ };
107764
+ const getRenderedRootNames = (root, scopes) => {
107765
+ const renderedRootShapes = getStaticRenderedRootShapes(root, scopes);
107766
+ if (renderedRootShapes === null) return null;
107767
+ return renderedRootShapes.map((rootShape) => {
107768
+ const onlyRootName = rootShape[0];
107769
+ return rootShape.length === 1 && onlyRootName ? onlyRootName : `fragment:${JSON.stringify(rootShape)}`;
107770
+ });
107771
+ };
107772
+ const getPatternBindingIdentifier = (pattern) => {
107773
+ const unwrappedPattern = stripParenExpression(pattern);
107774
+ if (isNodeOfType(unwrappedPattern, "Identifier")) return unwrappedPattern;
107775
+ if (isNodeOfType(unwrappedPattern, "AssignmentPattern")) return getPatternBindingIdentifier(unwrappedPattern.left);
107776
+ return null;
107777
+ };
107778
+ const getObjectPatternPropertyBinding = (pattern, propertyName) => {
107779
+ const unwrappedPattern = stripParenExpression(pattern);
107780
+ if (!isNodeOfType(unwrappedPattern, "ObjectPattern")) return null;
107781
+ for (const property of unwrappedPattern.properties) {
107782
+ if (!isNodeOfType(property, "Property") || getStaticPropertyKeyName(property, { allowComputedString: true }) !== propertyName) continue;
107783
+ return getPatternBindingIdentifier(property.value);
107784
+ }
107785
+ return null;
107786
+ };
107787
+ const isUnconditionallyTerminalStatement = (statement) => {
107788
+ if (isNodeOfType(statement, "ReturnStatement") || isNodeOfType(statement, "ThrowStatement")) return true;
107789
+ if (isNodeOfType(statement, "BlockStatement")) return statement.body.some(isUnconditionallyTerminalStatement);
107790
+ if (isNodeOfType(statement, "IfStatement")) return Boolean(statement.alternate && isUnconditionallyTerminalStatement(statement.consequent) && isUnconditionallyTerminalStatement(statement.alternate));
107791
+ if (isNodeOfType(statement, "SwitchStatement")) return statement.cases.some((switchCase) => switchCase.test === null) && statement.cases.every((switchCase) => switchCase.consequent.some(isUnconditionallyTerminalStatement));
107792
+ return false;
107793
+ };
107794
+ const getReachableFunctionReturnStatements = (functionNode, scopes) => collectFunctionReturnStatements(functionNode).filter((returnStatement) => {
107795
+ let descendant = returnStatement;
107796
+ let ancestor = returnStatement.parent;
107797
+ while (ancestor && ancestor !== functionNode) {
107798
+ if (isNodeOfType(ancestor, "IfStatement")) {
107799
+ const staticTestValue = readStaticSelectorTruthiness(ancestor.test, scopes);
107800
+ if (staticTestValue !== null && (staticTestValue && ancestor.alternate === descendant || !staticTestValue && ancestor.consequent === descendant)) return false;
107801
+ }
107802
+ if (isNodeOfType(ancestor, "BlockStatement")) {
107803
+ const descendantIndex = ancestor.body.findIndex((statement) => statement === descendant);
107804
+ if (descendantIndex > 0 && ancestor.body.slice(0, descendantIndex).some((statement) => {
107805
+ if (isNodeOfType(statement, "IfStatement")) {
107806
+ const staticTestValue = readStaticSelectorTruthiness(statement.test, scopes);
107807
+ if (staticTestValue === true) return isUnconditionallyTerminalStatement(statement.consequent);
107808
+ if (staticTestValue === false) return Boolean(statement.alternate && isUnconditionallyTerminalStatement(statement.alternate));
107809
+ }
107810
+ return isUnconditionallyTerminalStatement(statement);
107811
+ })) return false;
107812
+ }
107813
+ descendant = ancestor;
107814
+ ancestor = ancestor.parent;
107815
+ }
107816
+ return true;
107817
+ });
107818
+ const getRenderItemInputReferences = (functionNode, scopes) => {
107819
+ if (!isFunctionLike$1(functionNode)) return [];
107820
+ const parameter = functionNode.params[0];
107821
+ if (!parameter) return [];
107822
+ const unwrappedParameter = stripParenExpression(parameter);
107823
+ if (isNodeOfType(unwrappedParameter, "Identifier")) {
107824
+ const symbol = scopes.symbolFor(unwrappedParameter);
107825
+ if (!symbol) return [];
107826
+ return [...RENDER_ITEM_INPUT_NAMES].map((inputName) => ({
107827
+ inputName,
107828
+ isStable: isSymbolStable(symbol),
107829
+ propertyName: inputName,
107830
+ symbolId: symbol.id
107831
+ }));
107832
+ }
107833
+ if (!isNodeOfType(unwrappedParameter, "ObjectPattern")) return [];
107834
+ const references = [];
107835
+ for (const inputName of RENDER_ITEM_INPUT_NAMES) {
107836
+ const bindingIdentifier = getObjectPatternPropertyBinding(unwrappedParameter, inputName);
107837
+ const symbol = bindingIdentifier ? scopes.symbolFor(bindingIdentifier) : null;
107838
+ if (symbol) references.push({
107839
+ inputName,
107840
+ isStable: isSymbolStable(symbol),
107841
+ propertyName: null,
107842
+ symbolId: symbol.id
107843
+ });
107844
+ }
107845
+ return references;
107846
+ };
107847
+ const isStaticallyTruthyContainer = (node) => isNodeOfType(node, "ArrayExpression") || isNodeOfType(node, "ObjectExpression") || isNodeOfType(node, "ArrowFunctionExpression") || isNodeOfType(node, "FunctionExpression") || isNodeOfType(node, "ClassExpression") || isNodeOfType(node, "NewExpression") || isNodeOfType(node, "JSXElement") || isNodeOfType(node, "JSXFragment");
107848
+ const expressionReadsInput = (expression, inputReferences, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
107849
+ const inputExpression = getFinalSequenceExpressionValue(expression);
107850
+ if (isStaticallyTruthyContainer(inputExpression)) return false;
107851
+ let didReadInput = false;
107852
+ walkAst(inputExpression, (node) => {
107853
+ if (didReadInput) return false;
107854
+ if (node !== inputExpression && (isFunctionLike$1(node) || isNodeOfType(node, "ClassDeclaration") || isNodeOfType(node, "ClassExpression"))) return false;
107855
+ if (isNodeOfType(node, "Identifier")) {
107856
+ const reference = scopes.referenceFor(node);
107857
+ if (reference && reference.flag !== "write" && inputReferences.some((inputReference) => inputReference.isStable && inputReference.propertyName === null && inputReference.symbolId === reference.resolvedSymbol?.id)) {
107858
+ didReadInput = true;
107859
+ return false;
107860
+ }
107861
+ const symbol = reference?.resolvedSymbol;
107862
+ if (symbol?.kind === "const" && symbol.initializer && isSymbolStable(symbol) && !visitedSymbolIds.has(symbol.id)) {
107863
+ visitedSymbolIds.add(symbol.id);
107864
+ for (const initializer of getConstInitializerExpressions(symbol)) if (expressionReadsInput(initializer, inputReferences, scopes, visitedSymbolIds)) {
107865
+ didReadInput = true;
107866
+ return false;
107867
+ }
107868
+ }
107869
+ }
107870
+ if (!isNodeOfType(node, "MemberExpression")) return;
107871
+ const propertyName = getStaticPropertyName(node);
107872
+ const receiver = stripParenExpression(node.object);
107873
+ if (propertyName === null || !isNodeOfType(receiver, "Identifier")) return;
107874
+ const receiverReference = scopes.referenceFor(receiver);
107875
+ if (receiverReference && receiverReference.flag !== "write" && inputReferences.some((inputReference) => inputReference.isStable && inputReference.propertyName === propertyName && inputReference.symbolId === receiverReference.resolvedSymbol?.id)) {
107876
+ didReadInput = true;
107877
+ return false;
107878
+ }
107879
+ });
107880
+ return didReadInput;
107881
+ };
107882
+ const climbTransparentExpressionWrappers = (node) => {
107883
+ let expression = node;
107884
+ while (expression.parent && TRANSPARENT_EXPRESSION_WRAPPER_TYPES.has(expression.parent.type) && "expression" in expression.parent && expression.parent.expression === expression) expression = expression.parent;
107885
+ return expression;
107886
+ };
107887
+ const isProvenStaticCallableReference = (expression, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
107888
+ const reference = stripParenExpression(expression);
107889
+ if (isNodeOfType(reference, "MemberExpression")) return getImportedStaticReferenceKey(reference, scopes) !== null;
107890
+ if (!isNodeOfType(reference, "Identifier")) return false;
107891
+ const symbol = scopes.referenceFor(reference)?.resolvedSymbol;
107892
+ if (!symbol) return scopes.isGlobalReference(reference);
107893
+ if (!isSymbolStable(symbol) || visitedSymbolIds.has(symbol.id)) return false;
107894
+ if (symbol.kind === "import" || symbol.kind === "function") return true;
107895
+ if (symbol.kind !== "const" || !symbol.initializer) return false;
107896
+ visitedSymbolIds.add(symbol.id);
107897
+ const initializer = stripParenExpression(symbol.initializer);
107898
+ if (isFunctionLike$1(initializer)) return true;
107899
+ return isNodeOfType(initializer, "Identifier") || isNodeOfType(initializer, "MemberExpression") ? isProvenStaticCallableReference(initializer, scopes, visitedSymbolIds) : false;
107900
+ };
107901
+ const isProvenStaticCallCallee = (identifier, scopes) => {
107902
+ let callee = climbTransparentExpressionWrappers(identifier);
107903
+ while (isNodeOfType(callee.parent, "MemberExpression") && callee.parent.object === callee) callee = climbTransparentExpressionWrappers(callee.parent);
107904
+ return isNodeOfType(callee.parent, "CallExpression") && callee.parent.callee === callee && isProvenStaticCallableReference(callee, scopes);
107905
+ };
107906
+ const isInsideComparisonOperand = (identifier) => {
107907
+ let descendant = climbTransparentExpressionWrappers(identifier);
107908
+ let ancestor = descendant.parent;
107909
+ while (isNodeOfType(ancestor, "MemberExpression") && (ancestor.object === descendant || ancestor.property === descendant)) {
107910
+ descendant = climbTransparentExpressionWrappers(ancestor);
107911
+ ancestor = descendant.parent;
107912
+ }
107913
+ return isNodeOfType(ancestor, "BinaryExpression") && [
107914
+ "==",
107915
+ "!=",
107916
+ "===",
107917
+ "!==",
107918
+ "<",
107919
+ "<=",
107920
+ ">",
107921
+ ">=",
107922
+ "in",
107923
+ "instanceof"
107924
+ ].includes(ancestor.operator);
107925
+ };
107926
+ const expressionReadsOnlyInput = (expression, inputReferences, scopes) => {
107927
+ if (!expressionReadsInput(expression, inputReferences, scopes)) return false;
107928
+ const selector = getFinalSequenceExpressionValue(expression);
107929
+ let hasUnrelatedRead = false;
107930
+ const visitedSymbolIds = /* @__PURE__ */ new Set();
107931
+ const inspectExpression = (candidate) => {
107932
+ walkAst(candidate, (node) => {
107933
+ if (hasUnrelatedRead) return false;
107934
+ if (node !== candidate && (isFunctionLike$1(node) || isNodeOfType(node, "ClassDeclaration") || isNodeOfType(node, "ClassExpression"))) return false;
107935
+ if (!isNodeOfType(node, "Identifier")) return;
107936
+ const parent = node.parent;
107937
+ if (isNodeOfType(parent, "MemberExpression") && parent.property === node && !parent.computed || isNodeOfType(parent, "Property") && parent.key === node && !parent.computed || isProvenStaticCallCallee(node, scopes)) return;
107938
+ const symbol = scopes.referenceFor(node)?.resolvedSymbol;
107939
+ const isDirectInput = inputReferences.some((inputReference) => inputReference.isStable && inputReference.propertyName === null && inputReference.symbolId === symbol?.id);
107940
+ const isInputContainer = isNodeOfType(parent, "MemberExpression") && parent.object === node && inputReferences.some((inputReference) => inputReference.isStable && inputReference.propertyName === getStaticPropertyName(parent) && inputReference.symbolId === symbol?.id);
107941
+ if (isDirectInput || isInputContainer) return;
107942
+ if (symbol?.kind === "import" && isInsideComparisonOperand(node)) return;
107943
+ if (symbol?.kind === "const" && symbol.initializer && isSymbolStable(symbol) && visitedSymbolIds.has(symbol.id)) return;
107944
+ if (symbol?.kind === "const" && symbol.initializer && isSymbolStable(symbol) && !visitedSymbolIds.has(symbol.id)) {
107945
+ visitedSymbolIds.add(symbol.id);
107946
+ const initializers = getConstInitializerExpressions(symbol);
107947
+ if (!initializers.some((initializer) => expressionReadsInput(initializer, inputReferences, scopes)) && initializers.some((initializer) => readStaticSelectorTruthiness(initializer, scopes) === null)) {
107948
+ hasUnrelatedRead = true;
107949
+ return false;
107950
+ }
107951
+ for (const initializer of initializers) inspectExpression(initializer);
107952
+ return;
107953
+ }
107954
+ hasUnrelatedRead = true;
107955
+ return false;
107956
+ });
107957
+ };
107958
+ inspectExpression(selector);
107959
+ return !hasUnrelatedRead;
107960
+ };
107961
+ const hasInputDependentRenderedRootDifference = (expression, inputReferences, scopes) => {
107962
+ const alternativesHaveInputDependentDifference = (alternatives, eligibleFactKeys) => {
107963
+ for (let firstAlternativeIndex = 0; firstAlternativeIndex < alternatives.length; firstAlternativeIndex += 1) {
107964
+ const firstAlternative = alternatives[firstAlternativeIndex];
107965
+ for (let secondAlternativeIndex = firstAlternativeIndex + 1; secondAlternativeIndex < alternatives.length; secondAlternativeIndex += 1) {
107966
+ const secondAlternative = alternatives[secondAlternativeIndex];
107967
+ if (JSON.stringify(firstAlternative.roots) === JSON.stringify(secondAlternative.roots)) continue;
107968
+ let hasInputDependentDifference = false;
107969
+ let hasAmbientConflict = false;
107970
+ for (const [key, firstFact] of firstAlternative.facts) {
107971
+ const secondFact = secondAlternative.facts.get(key);
107972
+ if (!secondFact || firstFact.outcome === secondFact.outcome) continue;
107973
+ if ((!eligibleFactKeys || eligibleFactKeys.has(key)) && expressionReadsOnlyInput(firstFact.selector, inputReferences, scopes) && expressionReadsOnlyInput(secondFact.selector, inputReferences, scopes)) hasInputDependentDifference = true;
107974
+ else hasAmbientConflict = true;
107975
+ }
107976
+ if (hasInputDependentDifference && !hasAmbientConflict) return true;
107977
+ }
107978
+ }
107979
+ return false;
107980
+ };
107981
+ const renderedExpression = getFinalSequenceExpressionValue(expression);
107982
+ const fragmentChildren = getFlattenedFragmentChildren(renderedExpression, scopes);
107983
+ if (fragmentChildren !== null) {
107984
+ const childAlternatives = [];
107985
+ for (const child of fragmentChildren) {
107986
+ const alternatives = getStaticRenderedRootAlternatives(child, scopes);
107987
+ if (alternatives === null) return false;
107988
+ childAlternatives.push(alternatives);
107989
+ }
107990
+ const futureFactKeyCounts = /* @__PURE__ */ new Map();
107991
+ for (const alternatives of childAlternatives) {
107992
+ const childFactKeys = /* @__PURE__ */ new Set();
107993
+ for (const alternative of alternatives) for (const key of alternative.facts.keys()) childFactKeys.add(key);
107994
+ for (const key of childFactKeys) futureFactKeyCounts.set(key, (futureFactKeyCounts.get(key) ?? 0) + 1);
107995
+ }
107996
+ let prefixAlternatives = [{
107997
+ facts: /* @__PURE__ */ new Map(),
107998
+ roots: []
107999
+ }];
108000
+ for (const alternatives of childAlternatives) {
108001
+ const currentFactKeys = /* @__PURE__ */ new Set();
108002
+ for (const alternative of alternatives) for (const key of alternative.facts.keys()) currentFactKeys.add(key);
108003
+ for (const key of currentFactKeys) futureFactKeyCounts.set(key, (futureFactKeyCounts.get(key) ?? 1) - 1);
108004
+ const mergedAlternatives = mergeRenderedRootShapeAlternatives(prefixAlternatives, alternatives);
108005
+ if (mergedAlternatives === null) return false;
108006
+ prefixAlternatives = mergedAlternatives;
108007
+ const finalFactKeys = /* @__PURE__ */ new Set();
108008
+ for (const alternative of prefixAlternatives) for (const key of alternative.facts.keys()) if (futureFactKeyCounts.get(key) === 0) finalFactKeys.add(key);
108009
+ if (finalFactKeys.size > 0 && alternativesHaveInputDependentDifference(prefixAlternatives, finalFactKeys)) return true;
108010
+ const remainingAlternatives = forgetFinalizedRenderedRootFacts(prefixAlternatives, futureFactKeyCounts);
108011
+ if (remainingAlternatives === null) return false;
108012
+ prefixAlternatives = remainingAlternatives;
108013
+ }
108014
+ return false;
108015
+ }
108016
+ const alternatives = getStaticRenderedRootAlternatives(renderedExpression, scopes);
108017
+ return alternatives !== null && alternativesHaveInputDependentDifference(alternatives);
108018
+ };
108019
+ const getKnownReturnedRootNames = (expression, scopes) => {
108020
+ const returnedExpression = getFinalSequenceExpressionValue(expression);
108021
+ if (isNodeOfType(returnedExpression, "JSXElement") || isNodeOfType(returnedExpression, "JSXFragment")) {
108022
+ const rootNames = getRenderedRootNames(returnedExpression, scopes);
108023
+ return rootNames === null ? null : new Set(rootNames);
108024
+ }
108025
+ if (isStaticallyEmptyJsxChild(returnedExpression)) return new Set([EMPTY_RENDERED_ROOT_NAME]);
108026
+ let branches;
108027
+ if (isNodeOfType(returnedExpression, "ConditionalExpression")) branches = [returnedExpression.consequent, returnedExpression.alternate];
108028
+ else if (isNodeOfType(returnedExpression, "LogicalExpression")) branches = getStaticLogicalExpressionResultBranches(returnedExpression);
108029
+ else return null;
108030
+ const rootNames = /* @__PURE__ */ new Set();
108031
+ for (const branch of branches) {
108032
+ const branchRootNames = getKnownReturnedRootNames(branch, scopes);
108033
+ if (branchRootNames === null) return null;
108034
+ for (const rootName of branchRootNames) rootNames.add(rootName);
108035
+ }
108036
+ return rootNames;
108037
+ };
108038
+ const collectKnownStatementRootNames = (statement, scopes) => {
108039
+ const rootNames = /* @__PURE__ */ new Set();
108040
+ let hasUnknownRoot = false;
108041
+ walkAst(statement, (node) => {
108042
+ if (hasUnknownRoot) return false;
108043
+ if (node !== statement && (isFunctionLike$1(node) || isNodeOfType(node, "ClassDeclaration") || isNodeOfType(node, "ClassExpression"))) return false;
108044
+ if (!isNodeOfType(node, "ReturnStatement")) return;
108045
+ const returnedRootNames = node.argument ? getKnownReturnedRootNames(node.argument, scopes) : new Set([EMPTY_RENDERED_ROOT_NAME]);
108046
+ if (returnedRootNames === null) {
108047
+ hasUnknownRoot = true;
108048
+ return false;
108049
+ }
108050
+ for (const rootName of returnedRootNames) rootNames.add(rootName);
108051
+ return false;
108052
+ });
108053
+ return hasUnknownRoot || rootNames.size === 0 ? null : rootNames;
108054
+ };
108055
+ const collectKnownContinuationRootNames = (ifStatement, scopes) => {
108056
+ const parent = ifStatement.parent;
108057
+ if (!parent || !isNodeOfType(parent, "BlockStatement")) return null;
108058
+ const statementIndex = parent.body.findIndex((statement) => statement === ifStatement);
108059
+ if (statementIndex < 0) return null;
108060
+ const rootNames = /* @__PURE__ */ new Set();
108061
+ for (const statement of parent.body.slice(statementIndex + 1)) {
108062
+ const statementRootNames = collectKnownStatementRootNames(statement, scopes);
108063
+ if (statementRootNames) for (const rootName of statementRootNames) rootNames.add(rootName);
108064
+ if (isUnconditionallyTerminalStatement(statement)) break;
108065
+ }
108066
+ return rootNames.size === 0 ? null : rootNames;
108067
+ };
108068
+ const getDirectStatementRootAlternatives = (statement, scopes) => {
108069
+ if (isNodeOfType(statement, "ReturnStatement")) return statement.argument ? getStaticRenderedRootAlternatives(statement.argument, scopes) : [{
108070
+ facts: /* @__PURE__ */ new Map(),
108071
+ roots: []
108072
+ }];
108073
+ if (isNodeOfType(statement, "BlockStatement") && statement.body.length === 1) return getDirectStatementRootAlternatives(statement.body[0], scopes);
108074
+ return null;
108075
+ };
108076
+ const getContinuationRootAlternatives = (ifStatement, scopes) => {
108077
+ const parent = ifStatement.parent;
108078
+ if (!parent || !isNodeOfType(parent, "BlockStatement")) return null;
108079
+ const statementIndex = parent.body.findIndex((statement) => statement === ifStatement);
108080
+ if (statementIndex < 0) return null;
108081
+ for (const statement of parent.body.slice(statementIndex + 1)) {
108082
+ const alternatives = getDirectStatementRootAlternatives(statement, scopes);
108083
+ if (alternatives !== null) return alternatives;
108084
+ if (isUnconditionallyTerminalStatement(statement)) return null;
108085
+ }
108086
+ return null;
108087
+ };
108088
+ const renderedRootFactsAreCompatible = (firstFacts, secondFacts) => {
108089
+ for (const [key, firstFact] of firstFacts) {
108090
+ const secondFact = secondFacts.get(key);
108091
+ if (secondFact && secondFact.outcome !== firstFact.outcome) return false;
108092
+ }
108093
+ return true;
108094
+ };
108095
+ const hasDistinctKnownIfRootOutcomes = (ifStatement, scopes) => {
108096
+ if (!isUnconditionallyTerminalStatement(ifStatement.consequent)) return false;
108097
+ const consequentAlternatives = getDirectStatementRootAlternatives(ifStatement.consequent, scopes);
108098
+ const alternateAlternatives = ifStatement.alternate ? isUnconditionallyTerminalStatement(ifStatement.alternate) ? getDirectStatementRootAlternatives(ifStatement.alternate, scopes) : null : getContinuationRootAlternatives(ifStatement, scopes);
108099
+ if (consequentAlternatives && alternateAlternatives) return consequentAlternatives.some((consequentAlternative) => alternateAlternatives.some((alternateAlternative) => renderedRootFactsAreCompatible(consequentAlternative.facts, alternateAlternative.facts) && JSON.stringify(consequentAlternative.roots) !== JSON.stringify(alternateAlternative.roots)));
108100
+ const consequentRootNames = collectKnownStatementRootNames(ifStatement.consequent, scopes);
108101
+ const alternateRootNames = ifStatement.alternate ? isUnconditionallyTerminalStatement(ifStatement.alternate) ? collectKnownStatementRootNames(ifStatement.alternate, scopes) : null : collectKnownContinuationRootNames(ifStatement, scopes);
108102
+ if (!consequentRootNames || !alternateRootNames) return false;
108103
+ return [...consequentRootNames].some((rootName) => !alternateRootNames.has(rootName)) || [...alternateRootNames].some((rootName) => !consequentRootNames.has(rootName));
108104
+ };
108105
+ const hasDistinctKnownSwitchRootOutcomes = (switchStatement, scopes) => {
108106
+ if (!switchStatement.cases.some((switchCase) => switchCase.test === null) || !switchStatement.cases.every((switchCase) => switchCase.consequent.some(isUnconditionallyTerminalStatement))) return false;
108107
+ const caseRootNames = [];
108108
+ for (const switchCase of switchStatement.cases) {
108109
+ const rootNames = collectKnownStatementRootNames(switchCase, scopes);
108110
+ if (!rootNames) return false;
108111
+ caseRootNames.push(rootNames);
108112
+ }
108113
+ for (let firstCaseIndex = 0; firstCaseIndex < caseRootNames.length; firstCaseIndex += 1) {
108114
+ const firstRootNames = caseRootNames[firstCaseIndex];
108115
+ for (let secondCaseIndex = firstCaseIndex + 1; secondCaseIndex < caseRootNames.length; secondCaseIndex += 1) {
108116
+ const secondRootNames = caseRootNames[secondCaseIndex];
108117
+ if ([...firstRootNames].every((rootName) => !secondRootNames.has(rootName))) return true;
108118
+ }
108119
+ }
108120
+ return false;
108121
+ };
108122
+ const readStaticSelectorTruthiness = (expression, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
108123
+ const selector = getFinalSequenceExpressionValue(expression);
108124
+ if (isStaticallyTruthyContainer(selector)) return true;
108125
+ if (isNodeOfType(selector, "Literal")) return Boolean(selector.value);
108126
+ if (isNodeOfType(selector, "Identifier")) {
108127
+ const symbol = scopes.symbolFor(selector);
108128
+ if (symbol && (symbol.kind === "function" || symbol.kind === "class") && isSymbolStable(symbol)) return true;
108129
+ if (symbol?.kind === "const" && symbol.initializer && isSymbolStable(symbol) && getSymbolVariableDeclarator(symbol)?.id === symbol.bindingIdentifier && !visitedSymbolIds.has(symbol.id)) {
108130
+ visitedSymbolIds.add(symbol.id);
108131
+ return readStaticSelectorTruthiness(symbol.initializer, scopes, visitedSymbolIds);
108132
+ }
108133
+ }
108134
+ if (isNodeOfType(selector, "UnaryExpression") && selector.operator === "!") {
108135
+ const argumentTruthiness = readStaticSelectorTruthiness(selector.argument, scopes, visitedSymbolIds);
108136
+ return argumentTruthiness === null ? null : !argumentTruthiness;
108137
+ }
108138
+ if (!isNodeOfType(selector, "LogicalExpression")) return null;
108139
+ const leftTruthiness = readStaticSelectorTruthiness(selector.left, scopes, new Set(visitedSymbolIds));
108140
+ const rightTruthiness = readStaticSelectorTruthiness(selector.right, scopes, new Set(visitedSymbolIds));
108141
+ if (selector.operator === "&&") {
108142
+ if (leftTruthiness === false || rightTruthiness === false) return false;
108143
+ return leftTruthiness === true ? rightTruthiness : null;
108144
+ }
108145
+ if (selector.operator === "||") {
108146
+ if (leftTruthiness === true || rightTruthiness === true) return true;
108147
+ return leftTruthiness === false ? rightTruthiness : null;
108148
+ }
108149
+ return leftTruthiness;
108150
+ };
108151
+ const analyzeReturnedExpressionSelections = (expression, inputReferences, scopes) => {
108152
+ const returnedExpression = getFinalSequenceExpressionValue(expression);
108153
+ if (isNodeOfType(returnedExpression, "JSXExpressionContainer")) return analyzeReturnedExpressionSelections(returnedExpression.expression, inputReferences, scopes);
108154
+ if (isNodeOfType(returnedExpression, "JSXFragment") || isNodeOfType(returnedExpression, "JSXElement") && isJsxFragmentElement(returnedExpression.openingElement, scopes)) {
108155
+ let hasInputDependentSelection = false;
108156
+ let hasUnrelatedSelection = false;
108157
+ for (const child of returnedExpression.children) {
108158
+ const childAnalysis = analyzeReturnedExpressionSelections(child, inputReferences, scopes);
108159
+ hasInputDependentSelection ||= childAnalysis.hasInputDependentSelection;
108160
+ hasUnrelatedSelection ||= childAnalysis.hasUnrelatedSelection;
108161
+ }
108162
+ return {
108163
+ hasInputDependentSelection,
108164
+ hasProvenInputDependentRootSelection: hasInputDependentRenderedRootDifference(returnedExpression, inputReferences, scopes),
108165
+ hasUnrelatedSelection
108166
+ };
108167
+ }
108168
+ if (isNodeOfType(returnedExpression, "ConditionalExpression")) {
108169
+ const staticTestValue = readStaticSelectorTruthiness(returnedExpression.test, scopes);
108170
+ if (staticTestValue !== null) return analyzeReturnedExpressionSelections(staticTestValue ? returnedExpression.consequent : returnedExpression.alternate, inputReferences, scopes);
108171
+ const consequentAnalysis = analyzeReturnedExpressionSelections(returnedExpression.consequent, inputReferences, scopes);
108172
+ const alternateAnalysis = analyzeReturnedExpressionSelections(returnedExpression.alternate, inputReferences, scopes);
108173
+ const selectorReadsInput = expressionReadsOnlyInput(returnedExpression.test, inputReferences, scopes);
108174
+ const selectedRootNames = getKnownReturnedRootNames(returnedExpression, scopes);
108175
+ return {
108176
+ hasInputDependentSelection: selectorReadsInput || consequentAnalysis.hasInputDependentSelection || alternateAnalysis.hasInputDependentSelection,
108177
+ hasProvenInputDependentRootSelection: selectorReadsInput && selectedRootNames !== null && selectedRootNames.size > 1 || consequentAnalysis.hasProvenInputDependentRootSelection || alternateAnalysis.hasProvenInputDependentRootSelection,
108178
+ hasUnrelatedSelection: !selectorReadsInput && (selectedRootNames === null || selectedRootNames.size > 1) || consequentAnalysis.hasUnrelatedSelection || alternateAnalysis.hasUnrelatedSelection
108179
+ };
108180
+ }
108181
+ if (isNodeOfType(returnedExpression, "LogicalExpression")) {
108182
+ const resultBranches = getStaticLogicalExpressionResultBranches(returnedExpression);
108183
+ if (resultBranches.length < 2) {
108184
+ const onlyResult = resultBranches[0];
108185
+ return onlyResult ? analyzeReturnedExpressionSelections(onlyResult, inputReferences, scopes) : {
108186
+ hasInputDependentSelection: false,
108187
+ hasProvenInputDependentRootSelection: false,
108188
+ hasUnrelatedSelection: false
108189
+ };
108190
+ }
108191
+ const leftAnalysis = analyzeReturnedExpressionSelections(returnedExpression.left, inputReferences, scopes);
108192
+ const rightAnalysis = analyzeReturnedExpressionSelections(returnedExpression.right, inputReferences, scopes);
108193
+ const selectorReadsInput = expressionReadsOnlyInput(returnedExpression.left, inputReferences, scopes);
108194
+ const selectedRootNames = getKnownReturnedRootNames(returnedExpression, scopes);
108195
+ return {
108196
+ hasInputDependentSelection: selectorReadsInput || leftAnalysis.hasInputDependentSelection || rightAnalysis.hasInputDependentSelection,
108197
+ hasProvenInputDependentRootSelection: selectorReadsInput && selectedRootNames !== null && selectedRootNames.size > 1 || leftAnalysis.hasProvenInputDependentRootSelection || rightAnalysis.hasProvenInputDependentRootSelection,
108198
+ hasUnrelatedSelection: !selectorReadsInput && (selectedRootNames === null || selectedRootNames.size > 1) || leftAnalysis.hasUnrelatedSelection || rightAnalysis.hasUnrelatedSelection
108199
+ };
108200
+ }
108201
+ if (isNodeOfType(returnedExpression, "CallExpression") && isReactApiCall(returnedExpression, "createElement", scopes, {
108202
+ allowGlobalReactNamespace: true,
108203
+ resolveNamedAliases: true
108204
+ })) {
108205
+ const componentArgument = returnedExpression.arguments[0];
108206
+ if (componentArgument && !isNodeOfType(componentArgument, "SpreadElement")) return analyzeReturnedExpressionSelections(componentArgument, inputReferences, scopes);
108207
+ }
108208
+ return {
108209
+ hasInputDependentSelection: false,
108210
+ hasProvenInputDependentRootSelection: false,
108211
+ hasUnrelatedSelection: false
108212
+ };
108213
+ };
108214
+ const analyzeFunctionInputSelections = (functionNode, inputReferences, scopes) => {
108215
+ if (!isFunctionLike$1(functionNode)) return {
108216
+ hasInputDependentSelection: false,
108217
+ hasProvenInputDependentRootSelection: false,
108218
+ hasUnrelatedSelection: false
108219
+ };
108220
+ if (!isNodeOfType(functionNode.body, "BlockStatement")) return analyzeReturnedExpressionSelections(functionNode.body, inputReferences, scopes);
108221
+ let hasInputDependentSelection = false;
108222
+ let hasProvenInputDependentRootSelection = false;
108223
+ let hasUnrelatedSelection = false;
108224
+ const analyzedAncestors = /* @__PURE__ */ new Set();
108225
+ for (const returnStatement of getReachableFunctionReturnStatements(functionNode, scopes)) {
108226
+ const returnedRootNames = returnStatement.argument ? getKnownReturnedRootNames(returnStatement.argument, scopes) : /* @__PURE__ */ new Set();
108227
+ if (returnStatement.argument) {
108228
+ const returnAnalysis = analyzeReturnedExpressionSelections(returnStatement.argument, inputReferences, scopes);
108229
+ hasInputDependentSelection ||= returnAnalysis.hasInputDependentSelection;
108230
+ hasProvenInputDependentRootSelection ||= returnAnalysis.hasProvenInputDependentRootSelection;
108231
+ hasUnrelatedSelection ||= returnAnalysis.hasUnrelatedSelection;
108232
+ }
108233
+ if (returnedRootNames && [...returnedRootNames].every((rootName) => rootName === EMPTY_RENDERED_ROOT_NAME)) continue;
108234
+ let ancestor = returnStatement.parent;
108235
+ while (ancestor && ancestor !== functionNode) {
108236
+ if (analyzedAncestors.has(ancestor)) break;
108237
+ analyzedAncestors.add(ancestor);
108238
+ let selector = null;
108239
+ if (isNodeOfType(ancestor, "IfStatement")) selector = ancestor.test;
108240
+ else if (isNodeOfType(ancestor, "SwitchStatement")) selector = ancestor.discriminant;
108241
+ else if (isNodeOfType(ancestor, "TryStatement") || isNodeOfType(ancestor, "ForStatement") || isNodeOfType(ancestor, "ForInStatement") || isNodeOfType(ancestor, "ForOfStatement") || isNodeOfType(ancestor, "WhileStatement") || isNodeOfType(ancestor, "DoWhileStatement")) hasUnrelatedSelection = true;
108242
+ if (selector) if (expressionReadsOnlyInput(selector, inputReferences, scopes)) {
108243
+ hasInputDependentSelection = true;
108244
+ if (isNodeOfType(ancestor, "IfStatement") && hasDistinctKnownIfRootOutcomes(ancestor, scopes) || isNodeOfType(ancestor, "SwitchStatement") && hasDistinctKnownSwitchRootOutcomes(ancestor, scopes)) hasProvenInputDependentRootSelection = true;
108245
+ } else hasUnrelatedSelection = true;
108246
+ ancestor = ancestor.parent;
108247
+ }
108248
+ }
108249
+ return {
108250
+ hasInputDependentSelection,
108251
+ hasProvenInputDependentRootSelection,
108252
+ hasUnrelatedSelection
108253
+ };
108254
+ };
108255
+ const expressionHasOnlyInputDependentSelections = (expression, inputReferences, scopes) => {
108256
+ const selectionAnalysis = analyzeReturnedExpressionSelections(expression, inputReferences, scopes);
108257
+ return selectionAnalysis.hasInputDependentSelection && !selectionAnalysis.hasUnrelatedSelection;
108258
+ };
108259
+ const functionHasOnlyInputDependentSelections = (functionNode, inputReferences, scopes) => {
108260
+ const selectionAnalysis = analyzeFunctionInputSelections(functionNode, inputReferences, scopes);
108261
+ return selectionAnalysis.hasInputDependentSelection && !selectionAnalysis.hasUnrelatedSelection;
108262
+ };
108263
+ const getComponentExpressionIdentity = (expression, scopes) => {
108264
+ const componentExpression = stripParenExpression(expression);
108265
+ if (isNodeOfType(componentExpression, "Literal")) return typeof componentExpression.value === "string" ? `intrinsic:${componentExpression.value}` : null;
108266
+ if (isNodeOfType(componentExpression, "Identifier")) return getComponentReferenceIdentity(componentExpression, scopes);
108267
+ if (!isNodeOfType(componentExpression, "MemberExpression")) return null;
108268
+ return getComponentReferenceIdentity(componentExpression, scopes);
108269
+ };
108270
+ const collectStaticComponentIdentities = (expression, identities, scopes) => {
108271
+ const componentExpression = getFinalSequenceExpressionValue(expression);
108272
+ if (isNodeOfType(componentExpression, "ConditionalExpression")) return collectStaticComponentIdentities(componentExpression.consequent, identities, scopes) && collectStaticComponentIdentities(componentExpression.alternate, identities, scopes);
108273
+ if (isNodeOfType(componentExpression, "LogicalExpression")) return getStaticLogicalExpressionResultBranches(componentExpression).every((resultBranch) => collectStaticComponentIdentities(resultBranch, identities, scopes));
108274
+ const identity = getComponentExpressionIdentity(componentExpression, scopes);
108275
+ if (identity === null) return false;
108276
+ identities.add(identity);
108277
+ return true;
108278
+ };
108279
+ const isReactFragmentReference = (expression, scopes) => {
108280
+ const fragmentExpression = stripParenExpression(expression);
108281
+ const componentIdentity = getComponentReferenceIdentity(fragmentExpression, scopes);
108282
+ if (componentIdentity === "import:react:Fragment" || componentIdentity === "import:react:default.Fragment") return true;
108283
+ if (isNodeOfType(fragmentExpression, "Identifier")) {
108284
+ const symbol = resolveConstIdentifierAlias(fragmentExpression, scopes);
108285
+ return Boolean(symbol && isImportedFromReact(symbol) && getImportedName(symbol.declarationNode) === "Fragment");
108286
+ }
108287
+ if (!isNodeOfType(fragmentExpression, "MemberExpression") || getStaticPropertyName(fragmentExpression) !== "Fragment") return false;
108288
+ const receiver = stripParenExpression(fragmentExpression.object);
108289
+ return Boolean(isNodeOfType(receiver, "Identifier") && (isReactNamespaceImport(receiver, scopes) || receiver.name === "React" && scopes.isGlobalReference(receiver)));
108290
+ };
108291
+ const getForwardedInput = (expression, inputReferences, scopes) => {
108292
+ const forwardedExpression = stripParenExpression(expression);
108293
+ if (isNodeOfType(forwardedExpression, "Identifier")) {
108294
+ const reference = scopes.referenceFor(forwardedExpression);
108295
+ if (!reference?.resolvedSymbol) return null;
108296
+ const directInput = inputReferences.find((inputReference) => inputReference.isStable && inputReference.propertyName === null && inputReference.symbolId === reference.resolvedSymbol?.id);
108297
+ if (directInput) return {
108298
+ inputNames: new Set([directInput.inputName]),
108299
+ isWholeContainer: false
108300
+ };
108301
+ const containedInputNames = /* @__PURE__ */ new Set();
108302
+ for (const inputReference of inputReferences) if (inputReference.isStable && inputReference.propertyName !== null && inputReference.symbolId === reference.resolvedSymbol.id) containedInputNames.add(inputReference.inputName);
108303
+ return containedInputNames.size > 0 ? {
108304
+ inputNames: containedInputNames,
108305
+ isWholeContainer: true
108306
+ } : null;
108307
+ }
108308
+ if (!isNodeOfType(forwardedExpression, "MemberExpression")) return null;
108309
+ const propertyName = getStaticPropertyName(forwardedExpression);
108310
+ const receiver = stripParenExpression(forwardedExpression.object);
108311
+ if (propertyName === null || !isNodeOfType(receiver, "Identifier")) return null;
108312
+ const receiverReference = scopes.referenceFor(receiver);
108313
+ const matchedInput = inputReferences.find((inputReference) => inputReference.isStable && inputReference.propertyName === propertyName && inputReference.symbolId === receiverReference?.resolvedSymbol?.id);
108314
+ return matchedInput ? {
108315
+ inputNames: new Set([matchedInput.inputName]),
108316
+ isWholeContainer: false
108317
+ } : null;
108318
+ };
108319
+ const getParameterInputReferences = (parameter, forwardedInput, scopes) => {
108320
+ const unwrappedParameter = stripParenExpression(parameter);
108321
+ if (isNodeOfType(unwrappedParameter, "Identifier")) {
108322
+ if (forwardedInput.isWholeContainer) return [];
108323
+ const symbol = scopes.symbolFor(unwrappedParameter);
108324
+ const inputName = [...forwardedInput.inputNames][0];
108325
+ return symbol && inputName ? [{
108326
+ inputName,
108327
+ isStable: isSymbolStable(symbol),
108328
+ propertyName: null,
108329
+ symbolId: symbol.id
108330
+ }] : [];
108331
+ }
108332
+ if (!isNodeOfType(unwrappedParameter, "ObjectPattern")) return [];
108333
+ const references = [];
108334
+ for (const property of unwrappedParameter.properties) {
108335
+ if (!isNodeOfType(property, "Property")) continue;
108336
+ const propertyName = getStaticPropertyKeyName(property, { allowComputedString: true });
108337
+ if (propertyName === null || forwardedInput.isWholeContainer && !forwardedInput.inputNames.has(propertyName)) continue;
108338
+ const bindingIdentifier = getPatternBindingIdentifier(property.value);
108339
+ const symbol = bindingIdentifier ? scopes.symbolFor(bindingIdentifier) : null;
108340
+ if (symbol) references.push({
108341
+ inputName: propertyName,
108342
+ isStable: isSymbolStable(symbol),
108343
+ propertyName: null,
108344
+ symbolId: symbol.id
108345
+ });
108346
+ }
108347
+ return references;
108348
+ };
108349
+ const getComponentPropInputReferences = (openingElement, componentFunction, inputReferences, scopes) => {
108350
+ if (!isFunctionLike$1(componentFunction)) return [];
108351
+ const parameter = componentFunction.params[0];
108352
+ if (!parameter) return [];
108353
+ const references = [];
108354
+ for (const attribute of openingElement.attributes) {
108355
+ if (!isNodeOfType(attribute, "JSXAttribute") || !isNodeOfType(attribute.name, "JSXIdentifier") || !isNodeOfType(attribute.value, "JSXExpressionContainer")) continue;
108356
+ const attributeName = attribute.name.name;
108357
+ if (getAuthoritativeJsxAttribute(openingElement.attributes, attributeName) !== attribute) continue;
108358
+ const forwardedInput = getForwardedInput(attribute.value.expression, inputReferences, scopes);
108359
+ if (!forwardedInput || forwardedInput.isWholeContainer) continue;
108360
+ const unwrappedParameter = stripParenExpression(parameter);
108361
+ if (isNodeOfType(unwrappedParameter, "Identifier")) {
108362
+ const symbol = scopes.symbolFor(unwrappedParameter);
108363
+ if (symbol) references.push({
108364
+ inputName: attributeName,
108365
+ isStable: isSymbolStable(symbol),
108366
+ propertyName: attributeName,
108367
+ symbolId: symbol.id
108368
+ });
108369
+ continue;
108370
+ }
108371
+ const bindingIdentifier = getObjectPatternPropertyBinding(unwrappedParameter, attributeName);
108372
+ const symbol = bindingIdentifier ? scopes.symbolFor(bindingIdentifier) : null;
108373
+ if (symbol) references.push({
108374
+ inputName: attributeName,
108375
+ isStable: isSymbolStable(symbol),
108376
+ propertyName: null,
108377
+ symbolId: symbol.id
108378
+ });
108379
+ }
108380
+ return references;
108381
+ };
108382
+ const resolveLocalComponentFunction = (openingElement, scopes) => {
108383
+ if (!isNodeOfType(openingElement.name, "JSXIdentifier")) return null;
108384
+ const symbol = resolveConstIdentifierAlias(openingElement.name, scopes);
108385
+ if (!symbol || symbol.kind === "import" || !symbol.initializer || !isSymbolStable(symbol) || hasSymbolWriteBefore(symbol, openingElement.name, scopes)) return null;
108386
+ return unwrapProvenReactHocFunction(symbol.initializer, scopes);
108387
+ };
108388
+ const collectFunctionRenderedRootNames = (functionNode, names, scopes, analysis) => {
108389
+ if (!isFunctionLike$1(functionNode) || analysis.visitedFunctionNodes.has(functionNode)) return;
108390
+ analysis.visitedFunctionNodes.add(functionNode);
108391
+ if (!isNodeOfType(functionNode.body, "BlockStatement")) {
108392
+ collectReturnedJsxRootNames(functionNode.body, names, scopes, analysis);
108393
+ return;
108394
+ }
108395
+ for (const returnStatement of getReachableFunctionReturnStatements(functionNode, scopes)) if (returnStatement.argument) collectReturnedJsxRootNames(returnStatement.argument, names, scopes, analysis);
108396
+ };
108397
+ const collectLocalComponentRenderedRootNames = (element, names, scopes, analysis) => {
108398
+ if (!analysis.canFollowLocalRenderer) return false;
108399
+ const componentFunction = resolveLocalComponentFunction(element.openingElement, scopes);
108400
+ if (!componentFunction) return false;
108401
+ if (analysis.visitedFunctionNodes.has(componentFunction)) return true;
108402
+ const componentInputReferences = getComponentPropInputReferences(element.openingElement, componentFunction, analysis.inputReferences, scopes);
108403
+ if (componentInputReferences.length === 0 || !functionHasOnlyInputDependentSelections(componentFunction, componentInputReferences, scopes)) return false;
108404
+ const componentRootNames = /* @__PURE__ */ new Set();
108405
+ collectFunctionRenderedRootNames(componentFunction, componentRootNames, scopes, {
108406
+ canFollowLocalRenderer: false,
108407
+ inputReferences: componentInputReferences,
108408
+ visitedFunctionNodes: analysis.visitedFunctionNodes,
108409
+ visitedSymbolIds: analysis.visitedSymbolIds
108410
+ });
108411
+ if (componentRootNames.size === 0) return false;
108412
+ for (const componentRootName of componentRootNames) names.add(componentRootName);
108413
+ return true;
108414
+ };
108415
+ const collectItemSelectedComponentRootNames = (element, names, scopes, analysis) => {
108416
+ const componentName = element.openingElement.name;
108417
+ if (!isNodeOfType(componentName, "JSXIdentifier")) return false;
108418
+ const symbol = resolveConstIdentifierAlias(componentName, scopes);
108419
+ if (symbol?.kind !== "const" || !symbol.initializer || analysis.visitedSymbolIds.has(symbol.id) || hasSymbolWriteBefore(symbol, componentName, scopes) || !expressionHasOnlyInputDependentSelections(symbol.initializer, analysis.inputReferences, scopes)) return false;
108420
+ analysis.visitedSymbolIds.add(symbol.id);
108421
+ const componentIdentities = /* @__PURE__ */ new Set();
108422
+ const didResolveEveryComponent = collectStaticComponentIdentities(symbol.initializer, componentIdentities, scopes);
108423
+ analysis.visitedSymbolIds.delete(symbol.id);
108424
+ if (!didResolveEveryComponent || componentIdentities.size === 0) return false;
108425
+ for (const componentIdentity of componentIdentities) names.add(componentIdentity);
108426
+ return true;
108427
+ };
108428
+ const collectReactCreateElementRootNames = (callExpression, names, scopes, analysis) => {
108429
+ if (!isReactApiCall(callExpression, "createElement", scopes, {
108430
+ allowGlobalReactNamespace: true,
108431
+ resolveNamedAliases: true
108432
+ })) return false;
108433
+ const componentArgument = callExpression.arguments[0];
108434
+ if (!componentArgument || isNodeOfType(componentArgument, "SpreadElement") || isReactFragmentReference(componentArgument, scopes)) return false;
108435
+ const componentIdentities = /* @__PURE__ */ new Set();
108436
+ if (!collectStaticComponentIdentities(componentArgument, componentIdentities, scopes)) return false;
108437
+ if (componentIdentities.size > 1 && !expressionHasOnlyInputDependentSelections(componentArgument, analysis.inputReferences, scopes)) return false;
108438
+ for (const componentIdentity of componentIdentities) names.add(componentIdentity);
108439
+ return componentIdentities.size > 0;
108440
+ };
108441
+ const collectLocalHelperRenderedRootNames = (callExpression, names, scopes, analysis) => {
108442
+ if (!analysis.canFollowLocalRenderer) return false;
108443
+ const helperCallee = stripParenExpression(callExpression.callee);
108444
+ if (!isNodeOfType(helperCallee, "Identifier")) return false;
108445
+ const helperFunction = resolveStaticLocalCallFunction(callExpression, scopes);
108446
+ if (!helperFunction || !isFunctionLike$1(helperFunction) || helperFunction.async || helperFunction.generator || analysis.visitedFunctionNodes.has(helperFunction)) return false;
108447
+ const helperSymbol = scopes.symbolFor(helperCallee);
108448
+ const functionSymbol = isNodeOfType(helperFunction, "FunctionDeclaration") && helperFunction.id ? scopes.symbolFor(helperFunction.id) : null;
108449
+ if (helperSymbol && !isSymbolStable(helperSymbol) || functionSymbol && !isSymbolStable(functionSymbol)) return false;
108450
+ const helperInputReferences = [];
108451
+ for (let argumentIndex = 0; argumentIndex < callExpression.arguments.length; argumentIndex += 1) {
108452
+ const argument = callExpression.arguments[argumentIndex];
108453
+ const parameter = helperFunction.params[argumentIndex];
108454
+ if (!argument || isNodeOfType(argument, "SpreadElement") || !parameter) continue;
108455
+ const forwardedInput = getForwardedInput(argument, analysis.inputReferences, scopes);
108456
+ if (!forwardedInput) continue;
108457
+ helperInputReferences.push(...getParameterInputReferences(parameter, forwardedInput, scopes));
108458
+ }
108459
+ if (helperInputReferences.length === 0 || !functionHasOnlyInputDependentSelections(helperFunction, helperInputReferences, scopes)) return false;
108460
+ const helperRootNames = /* @__PURE__ */ new Set();
108461
+ collectFunctionRenderedRootNames(helperFunction, helperRootNames, scopes, {
108462
+ canFollowLocalRenderer: false,
108463
+ inputReferences: helperInputReferences,
108464
+ visitedFunctionNodes: analysis.visitedFunctionNodes,
108465
+ visitedSymbolIds: analysis.visitedSymbolIds
108466
+ });
108467
+ if (helperRootNames.size === 0) return false;
108468
+ for (const helperRootName of helperRootNames) names.add(helperRootName);
108469
+ return true;
108470
+ };
108471
+ const collectReturnedJsxRootNames = (expression, names, scopes, analysis) => {
108472
+ const unwrappedExpression = getFinalSequenceExpressionValue(expression);
108473
+ if (isNodeOfType(unwrappedExpression, "JSXElement")) {
108474
+ if (collectItemSelectedComponentRootNames(unwrappedExpression, names, scopes, analysis) || collectLocalComponentRenderedRootNames(unwrappedExpression, names, scopes, analysis)) return;
108475
+ const rootNames = getRenderedRootNames(unwrappedExpression, scopes);
108476
+ if (rootNames) for (const rootName of rootNames) names.add(rootName);
108477
+ return;
108478
+ }
108479
+ if (isNodeOfType(unwrappedExpression, "JSXFragment")) {
108480
+ const rootNames = getRenderedRootNames(unwrappedExpression, scopes);
108481
+ if (rootNames) for (const rootName of rootNames) names.add(rootName);
108482
+ return;
108483
+ }
108484
+ if (isNodeOfType(unwrappedExpression, "CallExpression")) {
108485
+ if (collectReactCreateElementRootNames(unwrappedExpression, names, scopes, analysis) || collectLocalHelperRenderedRootNames(unwrappedExpression, names, scopes, analysis)) return;
108486
+ }
108487
+ if (isNodeOfType(unwrappedExpression, "Identifier")) {
108488
+ const symbol = resolveConstIdentifierAlias(unwrappedExpression, scopes);
108489
+ if (symbol?.kind === "const" && symbol.initializer && !analysis.visitedSymbolIds.has(symbol.id) && !hasSymbolWriteBefore(symbol, unwrappedExpression, scopes) && expressionHasOnlyInputDependentSelections(symbol.initializer, analysis.inputReferences, scopes)) {
108490
+ analysis.visitedSymbolIds.add(symbol.id);
108491
+ collectReturnedJsxRootNames(symbol.initializer, names, scopes, analysis);
108492
+ analysis.visitedSymbolIds.delete(symbol.id);
108493
+ return;
108494
+ }
108495
+ }
108496
+ if (isNodeOfType(unwrappedExpression, "ConditionalExpression")) {
108497
+ const staticTestValue = readStaticSelectorTruthiness(unwrappedExpression.test, scopes);
108498
+ if (staticTestValue !== null) {
108499
+ collectReturnedJsxRootNames(staticTestValue ? unwrappedExpression.consequent : unwrappedExpression.alternate, names, scopes, analysis);
108500
+ return;
108501
+ }
108502
+ collectReturnedJsxRootNames(unwrappedExpression.consequent, names, scopes, analysis);
108503
+ collectReturnedJsxRootNames(unwrappedExpression.alternate, names, scopes, analysis);
108504
+ return;
108505
+ }
108506
+ if (isNodeOfType(unwrappedExpression, "LogicalExpression")) {
108507
+ for (const resultBranch of getStaticLogicalExpressionResultBranches(unwrappedExpression)) collectReturnedJsxRootNames(resultBranch, names, scopes, analysis);
108508
+ return;
108509
+ }
108510
+ };
108511
+ const resolveFunctionFromInitializer = (initializer, resultSymbol, scopes) => {
108512
+ const expression = stripParenExpression(initializer);
108513
+ if (isNodeOfType(expression, "ArrowFunctionExpression") || isNodeOfType(expression, "FunctionExpression") || isNodeOfType(expression, "FunctionDeclaration")) return expression;
108514
+ const callbackArgument = getTransparentReactCallbackWrapperArgument(expression, resultSymbol, scopes);
108515
+ if (callbackArgument && (isNodeOfType(callbackArgument, "ArrowFunctionExpression") || isNodeOfType(callbackArgument, "FunctionExpression"))) return callbackArgument;
108516
+ return null;
108517
+ };
108518
+ const resolveRenderItemFunction = (attribute, scopes) => {
108519
+ if (!isNodeOfType(attribute.value, "JSXExpressionContainer")) return null;
108520
+ const expression = stripParenExpression(attribute.value.expression);
108521
+ const directFunction = resolveFunctionFromInitializer(expression, null, scopes);
108522
+ if (directFunction) return directFunction;
108523
+ if (!isNodeOfType(expression, "Identifier")) return null;
108524
+ const localFunction = resolveExactLocalFunction(expression, scopes);
108525
+ if (localFunction) return localFunction;
108526
+ const symbol = scopes.symbolFor(expression);
108527
+ if (symbol?.kind !== "const" || !symbol.initializer) return null;
108528
+ return resolveFunctionFromInitializer(symbol.initializer, symbol, scopes);
108529
+ };
108530
+ const renderItemHasHeterogeneousRootTypes = (attribute, scopes, resultCache) => {
108531
+ const renderItemFunction = resolveRenderItemFunction(attribute, scopes);
108532
+ if (!renderItemFunction || !isNodeOfType(renderItemFunction, "ArrowFunctionExpression") && !isNodeOfType(renderItemFunction, "FunctionExpression") && !isNodeOfType(renderItemFunction, "FunctionDeclaration")) return false;
108533
+ const cachedResult = resultCache.get(renderItemFunction);
108534
+ if (cachedResult !== void 0) return cachedResult;
108535
+ const returnedRootNames = /* @__PURE__ */ new Set();
108536
+ const inputReferences = getRenderItemInputReferences(renderItemFunction, scopes);
108537
+ const selectionAnalysis = analyzeFunctionInputSelections(renderItemFunction, inputReferences, scopes);
108538
+ const returnStatements = isNodeOfType(renderItemFunction.body, "BlockStatement") ? getReachableFunctionReturnStatements(renderItemFunction, scopes) : [];
108539
+ if (selectionAnalysis.hasUnrelatedSelection && !selectionAnalysis.hasProvenInputDependentRootSelection || returnStatements.length > 1 && !selectionAnalysis.hasInputDependentSelection) {
108540
+ resultCache.set(renderItemFunction, false);
108541
+ return false;
108542
+ }
108543
+ collectFunctionRenderedRootNames(renderItemFunction, returnedRootNames, scopes, {
108544
+ canFollowLocalRenderer: true,
108545
+ inputReferences,
108546
+ visitedFunctionNodes: /* @__PURE__ */ new Set(),
108547
+ visitedSymbolIds: /* @__PURE__ */ new Set()
108548
+ });
108549
+ const hasHeterogeneousRootTypes = returnedRootNames.size > 1;
108550
+ resultCache.set(renderItemFunction, hasHeterogeneousRootTypes);
108551
+ return hasHeterogeneousRootTypes;
108552
+ };
107057
108553
  const rnListRecyclableWithoutTypes = defineRule({
107058
108554
  id: "rn-list-recyclable-without-types",
107059
108555
  title: "Recyclable list missing getItemType",
107060
108556
  tags: ["test-noise"],
107061
108557
  requires: ["react-native"],
107062
108558
  severity: "warn",
107063
- recommendation: "When rows have different shapes, reused cells can show the wrong layout. Add `getItemType={item => item.kind}` so FlashList keeps a separate pool per row type.",
108559
+ recommendation: "When rows have different shapes, reused cells can show the wrong layout. Add `getItemType` that returns a stable type for each row shape so FlashList keeps separate recycling pools.",
107064
108560
  create: (context) => {
107065
108561
  let fileImportsRecycler = false;
108562
+ const renderItemResultCache = /* @__PURE__ */ new WeakMap();
107066
108563
  return {
107067
108564
  Program(node) {
107068
108565
  fileImportsRecycler = hasImportFromModules(node, RECYCLABLE_LIST_PACKAGE_SOURCES);
@@ -107071,20 +108568,20 @@ const rnListRecyclableWithoutTypes = defineRule({
107071
108568
  if (!fileImportsRecycler) return;
107072
108569
  const elementName = resolveJsxElementName(node);
107073
108570
  if (!elementName) return;
107074
- if (resolveImportedRecyclerName(node, elementName, { allowNamespaceMemberAccess: true }) === null) return;
107075
- let hasRecycleItemsEnabled = false;
107076
- let hasGetItemType = false;
107077
- for (const attr of node.attributes ?? []) {
107078
- if (!isNodeOfType(attr, "JSXAttribute")) continue;
107079
- if (!isNodeOfType(attr.name, "JSXIdentifier")) continue;
107080
- if (attr.name.name === "recycleItems") if (!attr.value) hasRecycleItemsEnabled = true;
107081
- else if (isNodeOfType(attr.value, "JSXExpressionContainer") && isNodeOfType(attr.value.expression, "Literal")) hasRecycleItemsEnabled = attr.value.expression.value === true;
107082
- else hasRecycleItemsEnabled = true;
107083
- if (attr.name.name === "getItemType") hasGetItemType = true;
107084
- }
107085
- if (hasRecycleItemsEnabled && !hasGetItemType) context.report({
108571
+ const canonicalRecyclerName = resolveImportedRecyclerName(node, context.scopes, { allowNamespaceMemberAccess: true });
108572
+ if (canonicalRecyclerName === null) return;
108573
+ let hasRecycleItemsEnabled = SHOPIFY_FLASH_LIST_COMPONENTS.has(canonicalRecyclerName) && isFlashListV2OrNewer(context);
108574
+ const recycleItemsAttribute = getAuthoritativeJsxAttribute(node.attributes, "recycleItems");
108575
+ if (recycleItemsAttribute) if (!recycleItemsAttribute.value) hasRecycleItemsEnabled = true;
108576
+ else if (isNodeOfType(recycleItemsAttribute.value, "JSXExpressionContainer") && isNodeOfType(recycleItemsAttribute.value.expression, "Literal")) hasRecycleItemsEnabled = recycleItemsAttribute.value.expression.value === true;
108577
+ else hasRecycleItemsEnabled = true;
108578
+ else if (node.attributes.some((attribute) => isNodeOfType(attribute, "JSXSpreadAttribute") && canExpressionOverrideJsxAttribute(attribute.argument, "recycleItems", true, context.scopes))) hasRecycleItemsEnabled = false;
108579
+ const hasPossibleSpreadGetItemType = node.attributes.some((attribute) => isNodeOfType(attribute, "JSXSpreadAttribute") && canExpressionOverrideJsxAttribute(attribute.argument, "getItemType", true, context.scopes));
108580
+ const hasGetItemType = getAuthoritativeJsxAttribute(node.attributes, "getItemType") !== null || hasPossibleSpreadGetItemType;
108581
+ const renderItemAttribute = getAuthoritativeJsxAttribute(node.attributes, "renderItem");
108582
+ if (hasRecycleItemsEnabled && !hasGetItemType && renderItemAttribute && renderItemHasHeterogeneousRootTypes(renderItemAttribute, context.scopes, renderItemResultCache)) context.report({
107086
108583
  node,
107087
- message: `Your users see rows of different shapes reuse the wrong cells when <${elementName} recycleItems> has no \`getItemType\`.`
108584
+ message: `Your users see rows of different shapes reuse the wrong cells when <${elementName}> recycles them without \`getItemType\`.`
107088
108585
  });
107089
108586
  }
107090
108587
  };
@@ -107731,7 +109228,7 @@ const rnNoNonNativeNavigator = defineRule({
107731
109228
  tags: ["test-noise"],
107732
109229
  requires: ["react-native"],
107733
109230
  severity: "warn",
107734
- recommendation: "Use `@react-navigation/native-stack` (or `native-tabs` in v7+) for real native transitions and gestures.",
109231
+ recommendation: "Use `@react-navigation/native-stack` for stack navigation. Treat drawers separately because standalone React Navigation has no native drawer replacement.",
107735
109232
  create: (context) => ({ ImportDeclaration(node) {
107736
109233
  const source = node.source?.value;
107737
109234
  if (typeof source !== "string") return;
@@ -108305,6 +109802,28 @@ const rnNoSingleElementStyleArray = defineRule({
108305
109802
  } })
108306
109803
  });
108307
109804
  //#endregion
109805
+ //#region src/plugin/rules/react-native/rn-platform-shaking-use-direct-import.ts
109806
+ const REACT_NATIVE_MODULE_SOURCE = "react-native";
109807
+ const rnPlatformShakingUseDirectImport = defineRule({
109808
+ id: "rn-platform-shaking-use-direct-import",
109809
+ title: "Platform reached through React Native namespace",
109810
+ tags: ["test-noise"],
109811
+ requires: ["expo:54"],
109812
+ severity: "warn",
109813
+ recommendation: "Import `Platform` directly with `import { Platform } from \"react-native\"` so Expo can remove code for the other platform.",
109814
+ create: (context) => ({ MemberExpression(node) {
109815
+ if (node.computed) return;
109816
+ if (!isNodeOfType(node.object, "Identifier")) return;
109817
+ if (!isNodeOfType(node.property, "Identifier") || node.property.name !== "Platform") return;
109818
+ if (context.scopes.symbolFor(node.object)?.kind !== "import") return;
109819
+ if (!isNamespaceImportFromModule$1(node, node.object.name, REACT_NATIVE_MODULE_SOURCE)) return;
109820
+ context.report({
109821
+ node,
109822
+ message: "Expo cannot tree-shake platform branches reached through the React Native namespace, so both platform paths stay in the bundle."
109823
+ });
109824
+ } })
109825
+ });
109826
+ //#endregion
108308
109827
  //#region src/plugin/rules/react-native/rn-prefer-content-inset-adjustment.ts
108309
109828
  const rnPreferContentInsetAdjustment = defineRetiredRule({
108310
109829
  id: "rn-prefer-content-inset-adjustment",
@@ -108671,6 +110190,97 @@ const rnPressableSharedValueMutation = defineRule({
108671
110190
  }
108672
110191
  });
108673
110192
  //#endregion
110193
+ //#region src/plugin/rules/react-native/utils/resolve-reanimated-api-name.ts
110194
+ const REANIMATED_MODULE_SOURCE = "react-native-reanimated";
110195
+ const resolveReanimatedApiName = (callExpression, scopes, supportedApiNames) => {
110196
+ const reference = resolveImportedApiReference(callExpression.callee, scopes);
110197
+ if (reference?.source !== REANIMATED_MODULE_SOURCE || reference.importedName === null || !supportedApiNames.has(reference.importedName)) return null;
110198
+ return reference.importedName;
110199
+ };
110200
+ //#endregion
110201
+ //#region src/plugin/rules/react-native/rn-reanimated-4-no-legacy-spring-thresholds.ts
110202
+ const WITH_SPRING_API_NAMES = new Set(["withSpring"]);
110203
+ const LEGACY_SPRING_THRESHOLD_NAMES = new Set(["restDisplacementThreshold", "restSpeedThreshold"]);
110204
+ const rnReanimated4NoLegacySpringThresholds = defineRule({
110205
+ id: "rn-reanimated-4-no-legacy-spring-thresholds",
110206
+ title: "Legacy Reanimated spring threshold",
110207
+ tags: ["migration-hint"],
110208
+ requires: ["reanimated:4"],
110209
+ severity: "warn",
110210
+ recommendation: "Replace Reanimated 3 rest thresholds with Reanimated 4's `energyThreshold` spring option.",
110211
+ create: (context) => ({ CallExpression(node) {
110212
+ if (!resolveReanimatedApiName(node, context.scopes, WITH_SPRING_API_NAMES)) return;
110213
+ const configArgument = node.arguments[1];
110214
+ if (!configArgument || isNodeOfType(configArgument, "SpreadElement")) return;
110215
+ const unwrappedConfig = stripParenExpression(configArgument);
110216
+ if (!isNodeOfType(unwrappedConfig, "ObjectExpression")) return;
110217
+ for (const property of unwrappedConfig.properties) {
110218
+ if (!isNodeOfType(property, "Property")) continue;
110219
+ const propertyName = getStaticPropertyKeyName(property, { allowComputedString: true });
110220
+ if (!propertyName || !LEGACY_SPRING_THRESHOLD_NAMES.has(propertyName)) continue;
110221
+ context.report({
110222
+ node: property,
110223
+ message: `Reanimated 4 removed \`${propertyName}\`; use the \`energyThreshold\` spring option instead.`
110224
+ });
110225
+ }
110226
+ } })
110227
+ });
110228
+ //#endregion
110229
+ //#region src/plugin/rules/react-native/rn-reanimated-4-no-removed-api.ts
110230
+ const REMOVED_API_MESSAGE_BY_NAME = new Map([
110231
+ ["useAnimatedGestureHandler", "Reanimated 4 removed `useAnimatedGestureHandler`; migrate this gesture to the Gesture API."],
110232
+ ["useWorkletCallback", "Reanimated 4 removed `useWorkletCallback`; use React's `useCallback` with a `worklet` directive instead."],
110233
+ ["combineTransition", "Reanimated 4 removed `combineTransition`; compose the transition with `EntryExitTransition` instead."],
110234
+ ["addWhitelistedNativeProps", "Reanimated 4 removed `addWhitelistedNativeProps` because prop whitelisting is no longer needed."],
110235
+ ["addWhitelistedUIProps", "Reanimated 4 removed `addWhitelistedUIProps` because prop whitelisting is no longer needed."]
110236
+ ]);
110237
+ const REMOVED_API_NAMES = new Set(REMOVED_API_MESSAGE_BY_NAME.keys());
110238
+ const rnReanimated4NoRemovedApi = defineRule({
110239
+ id: "rn-reanimated-4-no-removed-api",
110240
+ title: "API removed in Reanimated 4",
110241
+ tags: ["migration-hint"],
110242
+ requires: ["reanimated:4"],
110243
+ severity: "warn",
110244
+ recommendation: "Migrate removed Reanimated APIs to their Reanimated 4 or Gesture API replacements before upgrading.",
110245
+ create: (context) => ({ CallExpression(node) {
110246
+ const apiName = resolveReanimatedApiName(node, context.scopes, REMOVED_API_NAMES);
110247
+ if (!apiName) return;
110248
+ const message = REMOVED_API_MESSAGE_BY_NAME.get(apiName);
110249
+ if (!message) return;
110250
+ context.report({
110251
+ node,
110252
+ message
110253
+ });
110254
+ } })
110255
+ });
110256
+ //#endregion
110257
+ //#region src/plugin/rules/react-native/rn-reanimated-4-use-worklets-scheduler.ts
110258
+ const WORKLETS_MIGRATION_BY_REANIMATED_API = new Map([
110259
+ ["runOnUI", "replace `runOnUI(fn)(...args)` with `scheduleOnUI(fn, ...args)`"],
110260
+ ["runOnJS", "replace `runOnJS(fn)(...args)` with `scheduleOnRN(fn, ...args)`"],
110261
+ ["executeOnUIRuntimeSync", "replace `executeOnUIRuntimeSync(fn)(...args)` with `runOnUISync(fn, ...args)`"],
110262
+ ["runOnRuntime", "replace `runOnRuntime(runtime, fn)(...args)` with `scheduleOnRuntime(runtime, fn, ...args)`"]
110263
+ ]);
110264
+ const REANIMATED_SCHEDULER_API_NAMES = new Set(WORKLETS_MIGRATION_BY_REANIMATED_API.keys());
110265
+ const rnReanimated4UseWorkletsScheduler = defineRule({
110266
+ id: "rn-reanimated-4-use-worklets-scheduler",
110267
+ title: "Scheduler moved to Worklets",
110268
+ tags: ["migration-hint"],
110269
+ requires: ["reanimated:4"],
110270
+ severity: "warn",
110271
+ recommendation: "Import the corresponding scheduler from `react-native-worklets` when migrating to Reanimated 4.",
110272
+ create: (context) => ({ CallExpression(node) {
110273
+ const apiName = resolveReanimatedApiName(node, context.scopes, REANIMATED_SCHEDULER_API_NAMES);
110274
+ if (!apiName) return;
110275
+ const migration = WORKLETS_MIGRATION_BY_REANIMATED_API.get(apiName);
110276
+ if (!migration) return;
110277
+ context.report({
110278
+ node,
110279
+ message: `For Reanimated 4, ${migration} from \`react-native-worklets\`.`
110280
+ });
110281
+ } })
110282
+ });
110283
+ //#endregion
108674
110284
  //#region src/plugin/rules/react-native/utils/scrollview_names.ts
108675
110285
  const SCROLLVIEW_NAMES = new Set([
108676
110286
  "ScrollView",
@@ -108934,7 +110544,7 @@ const rnStylePreferBoxShadow = defineRule({
108934
110544
  tags: ["test-noise"],
108935
110545
  requires: ["react-native"],
108936
110546
  severity: "warn",
108937
- recommendation: "These shadow keys only work on one platform. On RN v7+, use the CSS `boxShadow` string instead, like `boxShadow: \"0 2px 8px rgba(0,0,0,0.1)\"`, which works on both.",
110547
+ recommendation: "These shadow keys only work on one platform. On the New Architecture, use a CSS `boxShadow` string like `boxShadow: \"0 2px 8px rgba(0,0,0,0.1)\"`, which works on both.",
108938
110548
  create: (context) => {
108939
110549
  if (context.filename && isLegacyArchReactNativeFile(normalizeFilename(context.filename))) return EMPTY_VISITORS$3;
108940
110550
  return {
@@ -130125,6 +131735,30 @@ const reactDoctorRules = [
130125
131735
  tags: [...new Set(["react-native", ...rnAnimationReactionAsDerived.tags ?? []])]
130126
131736
  }
130127
131737
  },
131738
+ {
131739
+ key: "react-doctor/rn-bottom-sheet-no-ignored-scroll-prop",
131740
+ id: "rn-bottom-sheet-no-ignored-scroll-prop",
131741
+ source: "react-doctor",
131742
+ originallyExternal: false,
131743
+ rule: {
131744
+ ...rnBottomSheetNoIgnoredScrollProp,
131745
+ framework: "react-native",
131746
+ category: "Bugs",
131747
+ tags: [...new Set(["react-native", ...rnBottomSheetNoIgnoredScrollProp.tags ?? []])]
131748
+ }
131749
+ },
131750
+ {
131751
+ key: "react-doctor/rn-bottom-sheet-no-state-in-on-animate",
131752
+ id: "rn-bottom-sheet-no-state-in-on-animate",
131753
+ source: "react-doctor",
131754
+ originallyExternal: false,
131755
+ rule: {
131756
+ ...rnBottomSheetNoStateInOnAnimate,
131757
+ framework: "react-native",
131758
+ category: "Bugs",
131759
+ tags: [...new Set(["react-native", ...rnBottomSheetNoStateInOnAnimate.tags ?? []])]
131760
+ }
131761
+ },
130128
131762
  {
130129
131763
  key: "react-doctor/rn-bottom-sheet-prefer-native",
130130
131764
  id: "rn-bottom-sheet-prefer-native",
@@ -130137,6 +131771,18 @@ const reactDoctorRules = [
130137
131771
  tags: [...new Set(["react-native", ...rnBottomSheetPreferNative.tags ?? []])]
130138
131772
  }
130139
131773
  },
131774
+ {
131775
+ key: "react-doctor/rn-bottom-sheet-use-integrated-scrollable",
131776
+ id: "rn-bottom-sheet-use-integrated-scrollable",
131777
+ source: "react-doctor",
131778
+ originallyExternal: false,
131779
+ rule: {
131780
+ ...rnBottomSheetUseIntegratedScrollable,
131781
+ framework: "react-native",
131782
+ category: "Bugs",
131783
+ tags: [...new Set(["react-native", ...rnBottomSheetUseIntegratedScrollable.tags ?? []])]
131784
+ }
131785
+ },
130140
131786
  {
130141
131787
  key: "react-doctor/rn-detox-missing-await",
130142
131788
  id: "rn-detox-missing-await",
@@ -130401,6 +132047,18 @@ const reactDoctorRules = [
130401
132047
  tags: [...new Set(["react-native", ...rnNoSingleElementStyleArray.tags ?? []])]
130402
132048
  }
130403
132049
  },
132050
+ {
132051
+ key: "react-doctor/rn-platform-shaking-use-direct-import",
132052
+ id: "rn-platform-shaking-use-direct-import",
132053
+ source: "react-doctor",
132054
+ originallyExternal: false,
132055
+ rule: {
132056
+ ...rnPlatformShakingUseDirectImport,
132057
+ framework: "react-native",
132058
+ category: "Bugs",
132059
+ tags: [...new Set(["react-native", ...rnPlatformShakingUseDirectImport.tags ?? []])]
132060
+ }
132061
+ },
130404
132062
  {
130405
132063
  key: "react-doctor/rn-prefer-content-inset-adjustment",
130406
132064
  id: "rn-prefer-content-inset-adjustment",
@@ -130473,6 +132131,42 @@ const reactDoctorRules = [
130473
132131
  tags: [...new Set(["react-native", ...rnPressableSharedValueMutation.tags ?? []])]
130474
132132
  }
130475
132133
  },
132134
+ {
132135
+ key: "react-doctor/rn-reanimated-4-no-legacy-spring-thresholds",
132136
+ id: "rn-reanimated-4-no-legacy-spring-thresholds",
132137
+ source: "react-doctor",
132138
+ originallyExternal: false,
132139
+ rule: {
132140
+ ...rnReanimated4NoLegacySpringThresholds,
132141
+ framework: "react-native",
132142
+ category: "Bugs",
132143
+ tags: [...new Set(["react-native", ...rnReanimated4NoLegacySpringThresholds.tags ?? []])]
132144
+ }
132145
+ },
132146
+ {
132147
+ key: "react-doctor/rn-reanimated-4-no-removed-api",
132148
+ id: "rn-reanimated-4-no-removed-api",
132149
+ source: "react-doctor",
132150
+ originallyExternal: false,
132151
+ rule: {
132152
+ ...rnReanimated4NoRemovedApi,
132153
+ framework: "react-native",
132154
+ category: "Bugs",
132155
+ tags: [...new Set(["react-native", ...rnReanimated4NoRemovedApi.tags ?? []])]
132156
+ }
132157
+ },
132158
+ {
132159
+ key: "react-doctor/rn-reanimated-4-use-worklets-scheduler",
132160
+ id: "rn-reanimated-4-use-worklets-scheduler",
132161
+ source: "react-doctor",
132162
+ originallyExternal: false,
132163
+ rule: {
132164
+ ...rnReanimated4UseWorkletsScheduler,
132165
+ framework: "react-native",
132166
+ category: "Bugs",
132167
+ tags: [...new Set(["react-native", ...rnReanimated4UseWorkletsScheduler.tags ?? []])]
132168
+ }
132169
+ },
130476
132170
  {
130477
132171
  key: "react-doctor/rn-scrollview-dynamic-padding",
130478
132172
  id: "rn-scrollview-dynamic-padding",