/**
 * This file is part of the NocoBase (R) project.
 * Copyright (c) 2020-2024 NocoBase Co., Ltd.
 * Authors: NocoBase Team.
 *
 * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
 * For more information, please refer to: https://www.nocobase.com/agreement.
 */

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var react_exports = {};
__export(react_exports, {
  collectAstInvalidReactRuntimeBindingsFromAst: () => collectAstInvalidReactRuntimeBindingsFromAst,
  collectAstReactAsyncComponentReferences: () => collectAstReactAsyncComponentReferences,
  collectReactAsyncComponentBindingsFromAst: () => collectReactAsyncComponentBindingsFromAst,
  collectReactCreateElementAliasesFromAst: () => collectReactCreateElementAliasesFromAst,
  collectReactDefaultAliasesFromAst: () => collectReactDefaultAliasesFromAst,
  collectReactDefaultCarrierAliasesFromAst: () => collectReactDefaultCarrierAliasesFromAst,
  collectReactNamespaceAliasesFromAst: () => collectReactNamespaceAliasesFromAst,
  collectReactNamespaceCarrierAliasesFromAst: () => collectReactNamespaceCarrierAliasesFromAst,
  getAstNestedCarrierMemberName: () => getAstNestedCarrierMemberName,
  getReactCreateElementCallCapabilityFromAst: () => getReactCreateElementCallCapabilityFromAst,
  getReactCreateElementCapabilityFromAst: () => getReactCreateElementCapabilityFromAst,
  isAstAsyncFunctionLike: () => isAstAsyncFunctionLike,
  resolveAstAsyncComponentBinding: () => resolveAstAsyncComponentBinding
});
module.exports = __toCommonJS(react_exports);
var import_walk = require("../ast/walk");
var import_bindings = require("../ast/bindings");
var import_execution = require("../ast/execution");
var import_static_values = require("../ast/static-values");
var import_react_values = require("../ast/react-values");
function collectReactCreateElementAliasesFromAst(ast, source, identifierBindings, namespaceAliases, ctxRootAliases) {
  const aliases = [];
  const addAlias = (name, capability, node, ancestors, isVar = false) => {
    const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
    aliases.push({
      capability,
      name,
      declarationStart: typeof node.start === "number" ? node.start : scope.start,
      start: typeof node.start === "number" ? node.start : scope.start,
      end: scope.end
    });
  };
  (0, import_walk.walkAstAncestor)(ast, {
    AssignmentExpression(node, ancestors) {
      var _a;
      if (node.operator !== "=" || ((_a = node.left) == null ? void 0 : _a.type) !== "Identifier") {
        return;
      }
      const capability = getReactCreateElementCapabilityFromAst(
        node.right,
        identifierBindings,
        namespaceAliases,
        ctxRootAliases
      );
      if (capability) {
        addAlias(node.left.name, capability, node, ancestors);
      }
    },
    VariableDeclarator(node, ancestors) {
      var _a, _b;
      const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
      const isVar = (declaration == null ? void 0 : declaration.kind) === "var";
      if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
        const capability = getReactCreateElementCapabilityFromAst(
          node.init,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        if (capability) {
          addAlias(node.id.name, capability, node, ancestors, isVar);
        }
        return;
      }
      if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern" && (0, import_react_values.getReactNamespaceCapabilityFromAst)(node.init, identifierBindings, namespaceAliases, ctxRootAliases)) {
        const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          node.init,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        (0, import_static_values.collectAstObjectPatternAliases)(node.id, (name, member, aliasNode) => {
          if (member === "createElement") {
            addAlias(name, `${namespace}.createElement`, aliasNode || node, ancestors, isVar);
          }
        });
      }
    }
  });
  return aliases;
}
function collectReactNamespaceAliasesFromAst(ast, source, identifierBindings, ctxRootAliases) {
  const aliases = [];
  const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
  const addAlias = (name, capability, node, ancestors, isVar = false, scopeOverride, precedenceStart) => {
    const scope = scopeOverride || (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
    aliases.push({
      capability,
      name,
      declarationStart: typeof node.start === "number" ? node.start : scope.start,
      executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
      start: typeof node.start === "number" ? node.start : scope.start,
      end: scope.end,
      ...typeof precedenceStart === "number" ? { precedenceStart } : {}
    });
  };
  const getActiveAliases = () => (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
  (0, import_walk.walkAstAncestor)(ast, {
    AssignmentExpression(node, ancestors) {
      var _a, _b, _c, _d;
      if (!(0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator)) {
        return;
      }
      const activeAliases = getActiveAliases();
      const capability = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
        node.right,
        identifierBindings,
        activeAliases,
        ctxRootAliases
      );
      if (((_a = node.left) == null ? void 0 : _a.type) === "Identifier" && capability) {
        addAlias(
          node.left.name,
          capability,
          node,
          ancestors,
          false,
          (0, import_static_values.getAstAssignmentTargetScope)(node.left, ancestors, source.length, identifierBindings)
        );
        return;
      }
      if (((_b = node.left) == null ? void 0 : _b.type) === "MemberExpression" && capability) {
        const memberAlias = (0, import_static_values.getAstMemberAliasLookup)(node.left);
        if (memberAlias) {
          addAlias(
            memberAlias.aliasName,
            capability,
            node.left,
            ancestors,
            false,
            (0, import_static_values.getAstMemberAssignmentTargetScope)(node.left, ancestors, source.length, identifierBindings)
          );
        }
        return;
      }
      if (((_c = node.left) == null ? void 0 : _c.type) === "Identifier") {
        collectReactNamespaceCarrierAliasesFromAst(
          node.left.name,
          node.right,
          identifierBindings,
          activeAliases,
          ctxRootAliases,
          (member, capability2, aliasNode, precedenceStart) => {
            addAlias(
              `${node.left.name}.${member}`,
              capability2,
              aliasNode || node,
              ancestors,
              false,
              (0, import_static_values.getAstAssignmentTargetScope)(node.left, ancestors, source.length, identifierBindings),
              precedenceStart
            );
          }
        );
      }
      if (node.operator === "=" && ((_d = node.left) == null ? void 0 : _d.type) === "ObjectPattern" && (0, import_static_values.isCtxRootFromAst)(node.right, ctxRootAliases, identifierBindings)) {
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.left, (alias, members, aliasNode) => {
          if (members.length === 1 && members[0] === "React") {
            addAlias(
              alias,
              "ctx.React",
              aliasNode || node,
              ancestors,
              false,
              (0, import_static_values.getAstAssignmentTargetScope)(aliasNode, ancestors, source.length, identifierBindings)
            );
          }
        });
      }
      if (node.operator === "=") {
        collectReactNamespacePatternSourceAliasesFromAst(node.left, node.right, ancestors, false);
        collectReactNamespacePatternDefaultAliasesFromAst(node.left, ancestors, false, void 0, node.right);
      }
    },
    ForOfStatement(node, ancestors) {
      var _a;
      const target = (0, import_execution.getAstLoopPatternTarget)(node.left);
      if (!target) {
        return;
      }
      const isVar = ((_a = node.left) == null ? void 0 : _a.type) === "VariableDeclaration" && node.left.kind === "var";
      const activeAliases = getActiveAliases();
      (0, import_execution.collectAstForOfSourceTargets)(node.right, activeAliases, identifierBindings, (loopSourceTarget) => {
        collectReactNamespacePatternSourceTargetAliasesFromAst(target, loopSourceTarget, ancestors, isVar);
        collectReactNamespacePatternDefaultAliasesFromSourceTarget(
          target,
          ancestors,
          isVar,
          void 0,
          loopSourceTarget
        );
      });
    },
    VariableDeclarator(node, ancestors) {
      var _a, _b;
      const activeAliases = getActiveAliases();
      if ((0, import_execution.isAstForOfLoopVariableDeclaratorWithSourceTargets)(node, ancestors, activeAliases, identifierBindings)) {
        return;
      }
      const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
      const isVar = (declaration == null ? void 0 : declaration.kind) === "var";
      if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
        const capability = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          node.init,
          identifierBindings,
          activeAliases,
          ctxRootAliases
        );
        if (capability) {
          addAlias(node.id.name, capability, node, ancestors, isVar);
        }
        collectReactNamespaceCarrierAliasesFromAst(
          node.id.name,
          node.init,
          identifierBindings,
          activeAliases,
          ctxRootAliases,
          (member, memberCapability, aliasNode, precedenceStart) => {
            addAlias(
              `${node.id.name}.${member}`,
              memberCapability,
              aliasNode || node,
              ancestors,
              isVar,
              void 0,
              precedenceStart
            );
          }
        );
        collectReactNamespacePatternSourceAliasesFromAst(node.id, node.init, ancestors, isVar);
        return;
      }
      if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern" && (0, import_static_values.isCtxRootFromAst)(node.init, ctxRootAliases, identifierBindings)) {
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.id, (alias, members, aliasNode) => {
          if (members.length === 1 && members[0] === "React") {
            addAlias(alias, "ctx.React", aliasNode || node, ancestors, isVar);
          }
        });
      }
      collectReactNamespacePatternSourceAliasesFromAst(node.id, node.init, ancestors, isVar);
      collectReactNamespacePatternDefaultAliasesFromAst(node.id, ancestors, isVar, void 0, node.init);
    },
    FunctionDeclaration(node, ancestors) {
      collectReactNamespaceFunctionParamAliasesFromAst(node, ancestors);
    },
    FunctionExpression(node, ancestors) {
      collectReactNamespaceFunctionParamAliasesFromAst(node, ancestors);
    },
    ArrowFunctionExpression(node, ancestors) {
      collectReactNamespaceFunctionParamAliasesFromAst(node, ancestors);
    }
  });
  return (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
  function collectReactNamespaceFunctionParamAliasesFromAst(node, ancestors) {
    var _a, _b;
    const scope = {
      start: typeof node.start === "number" ? node.start : 0,
      end: typeof node.end === "number" ? node.end : source.length
    };
    const activeAliases = getActiveAliases();
    for (const param of node.params || []) {
      if ((param == null ? void 0 : param.type) !== "AssignmentPattern") {
        collectReactNamespacePatternDefaultAliasesFromAst(param, ancestors, false, scope);
        continue;
      }
      collectReactNamespacePatternDefaultAliasesFromAst(param.left, ancestors, false, scope, param.right);
      collectReactNamespacePatternSourceAliasesFromAst(param.left, param.right, ancestors, false, scope);
      if (((_a = param.left) == null ? void 0 : _a.type) === "Identifier") {
        const capability = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          param.right,
          identifierBindings,
          activeAliases,
          ctxRootAliases
        );
        if (capability) {
          addAlias(param.left.name, capability, param.left, ancestors, false, scope);
        }
        continue;
      }
      if (((_b = param.left) == null ? void 0 : _b.type) === "ObjectPattern" && (0, import_static_values.isCtxRootFromAst)(param.right, ctxRootAliases, identifierBindings)) {
        (0, import_static_values.collectAstObjectPatternPathAliases)(param.left, (alias, members, aliasNode) => {
          if (members.length === 1 && members[0] === "React") {
            addAlias(alias, "ctx.React", aliasNode || param, ancestors, false, scope);
          }
        });
      }
    }
  }
  function collectReactNamespacePatternSourceAliasesFromAst(pattern, sourceNode, ancestors, isVar = false, scopeOverride) {
    collectReactNamespacePatternSourceTargetAliasesFromAst(
      pattern,
      (0, import_static_values.createAstPatternSourceTarget)(sourceNode),
      ancestors,
      isVar,
      scopeOverride
    );
  }
  function collectReactNamespacePatternSourceTargetAliasesFromAst(pattern, sourceTarget, ancestors, isVar = false, scopeOverride) {
    const activeAliases = getActiveAliases();
    (0, import_static_values.collectAstPatternSourceTargetsRec)(pattern, sourceTarget, (target, patternSourceTarget) => {
      const capability = (0, import_react_values.getReactNamespaceCapabilityFromAstPatternSource)(
        patternSourceTarget,
        identifierBindings,
        activeAliases,
        ctxRootAliases
      );
      if (!capability) {
        return;
      }
      addReactNamespaceAliasTarget(target, capability, ancestors, isVar, scopeOverride);
    });
    const collectCarrierTarget = (carrierTarget) => {
      var _a, _b;
      if (carrierTarget.sourceAlias) {
        const precedenceStart = (0, import_static_values.getAstAliasPrecedenceStart)(carrierTarget.sourceAlias);
        addReactNamespaceAliasByName(
          carrierTarget.targetAliasName,
          carrierTarget.sourceAlias.capability,
          carrierTarget.target,
          ancestors,
          isVar,
          scopeOverride,
          (_a = carrierTarget.sourceTarget) == null ? void 0 : _a.node,
          precedenceStart
        );
        return;
      }
      const capability = (0, import_react_values.getReactNamespaceCapabilityFromAstPatternSource)(
        carrierTarget.sourceTarget,
        identifierBindings,
        activeAliases,
        ctxRootAliases
      );
      if (!capability) {
        return;
      }
      addReactNamespaceAliasByName(
        carrierTarget.targetAliasName,
        capability,
        carrierTarget.target,
        ancestors,
        isVar,
        scopeOverride,
        (_b = carrierTarget.sourceTarget) == null ? void 0 : _b.node
      );
    };
    (0, import_static_values.collectAstPatternCarrierSourceTargetsFromSourceTarget)(
      pattern,
      sourceTarget,
      activeAliases,
      identifierBindings,
      collectCarrierTarget
    );
    (0, import_static_values.collectAstPatternRestCarrierSourceTargetsRec)(
      pattern,
      sourceTarget,
      activeAliases,
      identifierBindings,
      collectCarrierTarget
    );
  }
  function collectReactNamespacePatternDefaultAliasesFromAst(pattern, ancestors, isVar = false, scopeOverride, sourceNode) {
    collectReactNamespacePatternDefaultAliasesFromSourceTarget(
      pattern,
      ancestors,
      isVar,
      scopeOverride,
      (0, import_static_values.createMaybeAstPatternSourceTarget)(sourceNode)
    );
  }
  function collectReactNamespacePatternDefaultAliasesFromSourceTarget(pattern, ancestors, isVar = false, scopeOverride, sourceTarget) {
    (0, import_static_values.collectAstPatternDefaultValueAliasesWithSource)(
      pattern,
      sourceTarget,
      (alias, valueNode, aliasNode, defaultPattern, sourceTarget2) => {
        if ((0, import_react_values.isAstPatternDefaultValueSuppressedByReactNamespace)(sourceTarget2, identifierBindings, aliases, ctxRootAliases)) {
          return;
        }
        const activeAliases = getActiveAliases();
        const capability = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          valueNode,
          identifierBindings,
          activeAliases,
          ctxRootAliases
        );
        if (capability && (defaultPattern == null ? void 0 : defaultPattern.type) === "Identifier") {
          addAlias(alias, capability, aliasNode || defaultPattern, ancestors, isVar, scopeOverride);
        }
        if ((defaultPattern == null ? void 0 : defaultPattern.type) === "Identifier") {
          collectReactNamespaceCarrierAliasesFromAst(
            alias,
            valueNode,
            identifierBindings,
            activeAliases,
            ctxRootAliases,
            (member, memberCapability, memberAliasNode, precedenceStart) => {
              addAlias(
                `${alias}.${member}`,
                memberCapability,
                memberAliasNode || aliasNode || defaultPattern,
                ancestors,
                isVar,
                scopeOverride,
                precedenceStart
              );
            }
          );
        }
        if ((defaultPattern == null ? void 0 : defaultPattern.type) === "ObjectPattern" && (0, import_static_values.isCtxRootFromAst)(valueNode, ctxRootAliases, identifierBindings)) {
          (0, import_static_values.collectAstObjectPatternPathAliases)(defaultPattern, (pathAlias, members, pathAliasNode) => {
            if (members.length === 1 && members[0] === "React") {
              addAlias(
                pathAlias,
                "ctx.React",
                pathAliasNode || aliasNode || defaultPattern,
                ancestors,
                isVar,
                scopeOverride
              );
            }
          });
        }
      }
    );
  }
  function addReactNamespaceAliasTarget(target, capability, ancestors, isVar = false, scopeOverride) {
    const unwrapped = (0, import_bindings.unwrapAstChainExpression)(target);
    if ((unwrapped == null ? void 0 : unwrapped.type) === "Identifier") {
      addAlias(
        unwrapped.name,
        capability,
        unwrapped,
        ancestors,
        isVar,
        scopeOverride || (0, import_static_values.getAstAssignmentTargetScope)(unwrapped, ancestors, source.length, identifierBindings)
      );
      return;
    }
    if ((unwrapped == null ? void 0 : unwrapped.type) === "MemberExpression") {
      const memberAlias = (0, import_static_values.getAstMemberAliasLookup)(unwrapped);
      if (!memberAlias) {
        return;
      }
      addAlias(
        memberAlias.aliasName,
        capability,
        unwrapped,
        ancestors,
        false,
        scopeOverride || (0, import_static_values.getAstMemberAssignmentTargetScope)(unwrapped, ancestors, source.length, identifierBindings)
      );
    }
  }
  function addReactNamespaceAliasByName(name, capability, target, ancestors, isVar = false, scopeOverride, aliasNode, precedenceStart) {
    const unwrapped = (0, import_bindings.unwrapAstChainExpression)(target);
    const scope = scopeOverride || ((unwrapped == null ? void 0 : unwrapped.type) === "MemberExpression" ? (0, import_static_values.getAstMemberAssignmentTargetScope)(unwrapped, ancestors, source.length, identifierBindings) : (0, import_static_values.getAstAssignmentTargetScope)(unwrapped, ancestors, source.length, identifierBindings));
    addAlias(
      name,
      capability,
      (0, import_bindings.unwrapAstChainExpression)(aliasNode) || aliasNode || unwrapped || target,
      ancestors,
      isVar,
      scope,
      precedenceStart
    );
  }
}
function collectReactDefaultAliasesFromAst(ast, source, identifierBindings, namespaceAliases, ctxRootAliases) {
  const aliases = [];
  const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
  const addAlias = (name, capability, node, ancestors, isVar = false, scopeOverride, precedenceStart) => {
    const scope = scopeOverride || (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
    aliases.push({
      capability,
      name,
      declarationStart: typeof node.start === "number" ? node.start : scope.start,
      executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
      start: typeof node.start === "number" ? node.start : scope.start,
      end: scope.end,
      ...typeof precedenceStart === "number" ? { precedenceStart } : {}
    });
  };
  const getActiveAliases = () => (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
  (0, import_walk.walkAstAncestor)(ast, {
    AssignmentExpression(node, ancestors) {
      var _a, _b, _c, _d;
      if (!(0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator)) {
        return;
      }
      const activeAliases = getActiveAliases();
      if (((_a = node.left) == null ? void 0 : _a.type) === "Identifier") {
        const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAst)(
          node.right,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases,
          activeAliases
        );
        if (capability) {
          addAlias(
            node.left.name,
            capability,
            node,
            ancestors,
            false,
            (0, import_static_values.getAstAssignmentTargetScope)(node.left, ancestors, source.length, identifierBindings)
          );
        }
        collectReactDefaultCarrierAliasesFromAst(
          node.left.name,
          node.right,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases,
          activeAliases,
          (member, capability2, aliasNode, precedenceStart) => {
            addAlias(
              `${node.left.name}.${member}`,
              capability2,
              aliasNode || node,
              ancestors,
              false,
              (0, import_static_values.getAstAssignmentTargetScope)(node.left, ancestors, source.length, identifierBindings),
              precedenceStart
            );
          }
        );
        return;
      }
      const memberAlias = (0, import_static_values.getAstMemberAliasLookup)(node.left);
      if (((_b = node.left) == null ? void 0 : _b.type) === "MemberExpression" && memberAlias) {
        const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAst)(
          node.right,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases,
          activeAliases
        );
        if (capability) {
          addAlias(
            memberAlias.aliasName,
            capability,
            node.left,
            ancestors,
            false,
            (0, import_static_values.getAstMemberAssignmentTargetScope)(node.left, ancestors, source.length, identifierBindings)
          );
        }
      }
      if (((_c = node.left) == null ? void 0 : _c.type) === "ObjectPattern" && (0, import_react_values.getReactNamespaceCapabilityFromAst)(node.right, identifierBindings, namespaceAliases, ctxRootAliases)) {
        const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          node.right,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.left, (alias, members, aliasNode) => {
          if (members.length === 1 && members[0] === "default") {
            addAlias(
              alias,
              `${namespace}.default`,
              aliasNode || node,
              ancestors,
              false,
              (0, import_static_values.getAstAssignmentTargetScope)(aliasNode, ancestors, source.length, identifierBindings)
            );
          }
        });
      }
      if (((_d = node.left) == null ? void 0 : _d.type) === "ObjectPattern" && (0, import_static_values.isCtxRootFromAst)(node.right, ctxRootAliases, identifierBindings)) {
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.left, (alias, members, aliasNode) => {
          if (members.length === 2 && members[0] === "React" && members[1] === "default") {
            addAlias(
              alias,
              "ctx.React.default",
              aliasNode || node,
              ancestors,
              false,
              (0, import_static_values.getAstAssignmentTargetScope)(aliasNode, ancestors, source.length, identifierBindings)
            );
          }
        });
      }
      if (node.operator === "=") {
        collectReactDefaultPatternSourceAliasesFromAst(node.left, node.right, ancestors, false);
        collectReactDefaultPatternDefaultAliasesFromAst(node.left, ancestors, false, void 0, node.right);
      }
    },
    ForOfStatement(node, ancestors) {
      var _a;
      const target = (0, import_execution.getAstLoopPatternTarget)(node.left);
      if (!target) {
        return;
      }
      const isVar = ((_a = node.left) == null ? void 0 : _a.type) === "VariableDeclaration" && node.left.kind === "var";
      const activeAliases = getActiveAliases();
      const sourceTargetAliases = [...namespaceAliases, ...activeAliases];
      (0, import_execution.collectAstForOfSourceTargets)(node.right, sourceTargetAliases, identifierBindings, (loopSourceTarget) => {
        collectReactDefaultPatternSourceTargetAliasesFromAst(target, loopSourceTarget, ancestors, isVar);
        collectReactDefaultPatternDefaultAliasesFromSourceTarget(target, ancestors, isVar, void 0, loopSourceTarget);
      });
    },
    VariableDeclarator(node, ancestors) {
      var _a, _b, _c;
      const activeAliases = getActiveAliases();
      const sourceTargetAliases = [...namespaceAliases, ...activeAliases];
      if ((0, import_execution.isAstForOfLoopVariableDeclaratorWithSourceTargets)(node, ancestors, sourceTargetAliases, identifierBindings)) {
        return;
      }
      const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
      const isVar = (declaration == null ? void 0 : declaration.kind) === "var";
      if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
        const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAst)(
          node.init,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases,
          getActiveAliases()
        );
        if (capability) {
          addAlias(node.id.name, capability, node, ancestors, isVar);
        }
        collectReactDefaultCarrierAliasesFromAst(
          node.id.name,
          node.init,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases,
          getActiveAliases(),
          (member, memberCapability, aliasNode, precedenceStart) => {
            addAlias(
              `${node.id.name}.${member}`,
              memberCapability,
              aliasNode || node,
              ancestors,
              isVar,
              void 0,
              precedenceStart
            );
          }
        );
        collectReactDefaultPatternSourceAliasesFromAst(node.id, node.init, ancestors, isVar);
        return;
      }
      if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern" && (0, import_react_values.getReactNamespaceCapabilityFromAst)(node.init, identifierBindings, namespaceAliases, ctxRootAliases)) {
        const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          node.init,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.id, (alias, members, aliasNode) => {
          if (members.length === 1 && members[0] === "default") {
            addAlias(alias, `${namespace}.default`, aliasNode || node, ancestors, isVar);
          }
        });
        collectReactDefaultPatternSourceAliasesFromAst(node.id, node.init, ancestors, isVar);
        return;
      }
      if (((_c = node.id) == null ? void 0 : _c.type) === "ObjectPattern" && (0, import_static_values.isCtxRootFromAst)(node.init, ctxRootAliases, identifierBindings)) {
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.id, (alias, members, aliasNode) => {
          if (members.length === 2 && members[0] === "React" && members[1] === "default") {
            addAlias(alias, "ctx.React.default", aliasNode || node, ancestors, isVar);
          }
        });
      }
      collectReactDefaultPatternSourceAliasesFromAst(node.id, node.init, ancestors, isVar);
      collectReactDefaultPatternDefaultAliasesFromAst(node.id, ancestors, isVar, void 0, node.init);
    },
    FunctionDeclaration(node, ancestors) {
      collectReactDefaultFunctionParamAliasesFromAst(node, ancestors);
    },
    FunctionExpression(node, ancestors) {
      collectReactDefaultFunctionParamAliasesFromAst(node, ancestors);
    },
    ArrowFunctionExpression(node, ancestors) {
      collectReactDefaultFunctionParamAliasesFromAst(node, ancestors);
    }
  });
  return (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
  function collectReactDefaultFunctionParamAliasesFromAst(node, ancestors) {
    var _a, _b;
    const scope = {
      start: typeof node.start === "number" ? node.start : 0,
      end: typeof node.end === "number" ? node.end : source.length
    };
    const activeAliases = getActiveAliases();
    for (const param of node.params || []) {
      if ((param == null ? void 0 : param.type) !== "AssignmentPattern") {
        collectReactDefaultPatternDefaultAliasesFromAst(param, ancestors, false, scope);
        continue;
      }
      collectReactDefaultPatternDefaultAliasesFromAst(param.left, ancestors, false, scope, param.right);
      collectReactDefaultPatternSourceAliasesFromAst(param.left, param.right, ancestors, false, scope);
      if (((_a = param.left) == null ? void 0 : _a.type) === "Identifier") {
        const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAst)(
          param.right,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases,
          activeAliases
        );
        if (capability) {
          addAlias(param.left.name, capability, param.left, ancestors, false, scope);
        }
        continue;
      }
      if (((_b = param.left) == null ? void 0 : _b.type) === "ObjectPattern") {
        const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          param.right,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        if (namespace) {
          (0, import_static_values.collectAstObjectPatternPathAliases)(param.left, (alias, members, aliasNode) => {
            if (members.length === 1 && members[0] === "default") {
              addAlias(alias, `${namespace}.default`, aliasNode || param, ancestors, false, scope);
            }
          });
        }
        if ((0, import_static_values.isCtxRootFromAst)(param.right, ctxRootAliases, identifierBindings)) {
          (0, import_static_values.collectAstObjectPatternPathAliases)(param.left, (alias, members, aliasNode) => {
            if (members.length === 2 && members[0] === "React" && members[1] === "default") {
              addAlias(alias, "ctx.React.default", aliasNode || param, ancestors, false, scope);
            }
          });
        }
      }
    }
  }
  function collectReactDefaultPatternSourceAliasesFromAst(pattern, sourceNode, ancestors, isVar = false, scopeOverride) {
    collectReactDefaultPatternSourceTargetAliasesFromAst(
      pattern,
      (0, import_static_values.createAstPatternSourceTarget)(sourceNode),
      ancestors,
      isVar,
      scopeOverride
    );
  }
  function collectReactDefaultPatternSourceTargetAliasesFromAst(pattern, sourceTarget, ancestors, isVar = false, scopeOverride) {
    const activeAliases = getActiveAliases();
    (0, import_static_values.collectAstPatternSourceTargetsRec)(pattern, sourceTarget, (target, patternSourceTarget) => {
      const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAstPatternSource)(
        patternSourceTarget,
        identifierBindings,
        namespaceAliases,
        ctxRootAliases,
        activeAliases
      );
      if (!capability) {
        return;
      }
      addReactDefaultAliasTarget(target, capability, ancestors, isVar, scopeOverride);
    });
    const collectCarrierTarget = (carrierTarget) => {
      var _a, _b;
      if (carrierTarget.sourceAlias) {
        const precedenceStart = (0, import_static_values.getAstAliasPrecedenceStart)(carrierTarget.sourceAlias);
        addReactDefaultAliasByName(
          carrierTarget.targetAliasName,
          carrierTarget.sourceAlias.capability,
          carrierTarget.target,
          ancestors,
          isVar,
          scopeOverride,
          (_a = carrierTarget.sourceTarget) == null ? void 0 : _a.node,
          precedenceStart
        );
        return;
      }
      const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAstPatternSource)(
        carrierTarget.sourceTarget,
        identifierBindings,
        namespaceAliases,
        ctxRootAliases,
        activeAliases
      );
      if (!capability) {
        return;
      }
      addReactDefaultAliasByName(
        carrierTarget.targetAliasName,
        capability,
        carrierTarget.target,
        ancestors,
        isVar,
        scopeOverride,
        (_b = carrierTarget.sourceTarget) == null ? void 0 : _b.node
      );
    };
    (0, import_static_values.collectAstPatternCarrierSourceTargetsFromSourceTarget)(
      pattern,
      sourceTarget,
      activeAliases,
      identifierBindings,
      collectCarrierTarget
    );
    (0, import_static_values.collectAstPatternRestCarrierSourceTargetsRec)(
      pattern,
      sourceTarget,
      activeAliases,
      identifierBindings,
      collectCarrierTarget
    );
  }
  function collectReactDefaultPatternDefaultAliasesFromAst(pattern, ancestors, isVar = false, scopeOverride, sourceNode) {
    collectReactDefaultPatternDefaultAliasesFromSourceTarget(
      pattern,
      ancestors,
      isVar,
      scopeOverride,
      (0, import_static_values.createMaybeAstPatternSourceTarget)(sourceNode)
    );
  }
  function collectReactDefaultPatternDefaultAliasesFromSourceTarget(pattern, ancestors, isVar = false, scopeOverride, sourceTarget) {
    (0, import_static_values.collectAstPatternDefaultValueAliasesWithSource)(
      pattern,
      sourceTarget,
      (alias, valueNode, aliasNode, defaultPattern, sourceTarget2) => {
        if ((0, import_react_values.isAstPatternDefaultValueSuppressedByReactNamespace)(
          sourceTarget2,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        )) {
          return;
        }
        const activeAliases = getActiveAliases();
        const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAst)(
          valueNode,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases,
          activeAliases
        );
        if (capability && (defaultPattern == null ? void 0 : defaultPattern.type) === "Identifier") {
          addAlias(alias, capability, aliasNode || defaultPattern, ancestors, isVar, scopeOverride);
        }
        if ((defaultPattern == null ? void 0 : defaultPattern.type) === "Identifier") {
          collectReactDefaultCarrierAliasesFromAst(
            alias,
            valueNode,
            identifierBindings,
            namespaceAliases,
            ctxRootAliases,
            activeAliases,
            (member, memberCapability, memberAliasNode, precedenceStart) => {
              addAlias(
                `${alias}.${member}`,
                memberCapability,
                memberAliasNode || aliasNode || defaultPattern,
                ancestors,
                isVar,
                scopeOverride,
                precedenceStart
              );
            }
          );
        }
        if ((defaultPattern == null ? void 0 : defaultPattern.type) !== "ObjectPattern") {
          return;
        }
        const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          valueNode,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        if (namespace) {
          (0, import_static_values.collectAstObjectPatternPathAliases)(defaultPattern, (pathAlias, members, pathAliasNode) => {
            if (members.length === 1 && members[0] === "default") {
              addAlias(
                pathAlias,
                `${namespace}.default`,
                pathAliasNode || aliasNode || defaultPattern,
                ancestors,
                isVar,
                scopeOverride
              );
            }
          });
        }
        if ((0, import_static_values.isCtxRootFromAst)(valueNode, ctxRootAliases, identifierBindings)) {
          (0, import_static_values.collectAstObjectPatternPathAliases)(defaultPattern, (pathAlias, members, pathAliasNode) => {
            if (members.length === 2 && members[0] === "React" && members[1] === "default") {
              addAlias(
                pathAlias,
                "ctx.React.default",
                pathAliasNode || aliasNode || defaultPattern,
                ancestors,
                isVar,
                scopeOverride
              );
            }
          });
        }
      }
    );
  }
  function addReactDefaultAliasTarget(target, capability, ancestors, isVar = false, scopeOverride) {
    const unwrapped = (0, import_bindings.unwrapAstChainExpression)(target);
    if ((unwrapped == null ? void 0 : unwrapped.type) === "Identifier") {
      addAlias(
        unwrapped.name,
        capability,
        unwrapped,
        ancestors,
        isVar,
        scopeOverride || (0, import_static_values.getAstAssignmentTargetScope)(unwrapped, ancestors, source.length, identifierBindings)
      );
      return;
    }
    if ((unwrapped == null ? void 0 : unwrapped.type) === "MemberExpression") {
      const memberAlias = (0, import_static_values.getAstMemberAliasLookup)(unwrapped);
      if (!memberAlias) {
        return;
      }
      addAlias(
        memberAlias.aliasName,
        capability,
        unwrapped,
        ancestors,
        false,
        scopeOverride || (0, import_static_values.getAstMemberAssignmentTargetScope)(unwrapped, ancestors, source.length, identifierBindings)
      );
    }
  }
  function addReactDefaultAliasByName(name, capability, target, ancestors, isVar = false, scopeOverride, aliasNode, precedenceStart) {
    const unwrapped = (0, import_bindings.unwrapAstChainExpression)(target);
    const scope = scopeOverride || ((unwrapped == null ? void 0 : unwrapped.type) === "MemberExpression" ? (0, import_static_values.getAstMemberAssignmentTargetScope)(unwrapped, ancestors, source.length, identifierBindings) : (0, import_static_values.getAstAssignmentTargetScope)(unwrapped, ancestors, source.length, identifierBindings));
    addAlias(
      name,
      capability,
      (0, import_bindings.unwrapAstChainExpression)(aliasNode) || aliasNode || unwrapped || target,
      ancestors,
      isVar,
      scope,
      precedenceStart
    );
  }
}
function collectAstInvalidReactRuntimeBindingsFromAst(ast, source, identifierBindings, namespaceAliases, ctxRootAliases, defaultAliases = []) {
  const entries = [];
  const addEntry = (binding, capability, node, ancestors) => {
    const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
    const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, (declaration == null ? void 0 : declaration.kind) === "var");
    entries.push({
      binding,
      capability,
      declarationStart: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
      index: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
      ruleId: "runjs-react-default-alias-forbidden",
      start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
      end: typeof (node == null ? void 0 : node.end) === "number" ? node.end : scope.end
    });
  };
  (0, import_walk.walkAstAncestor)(ast, {
    AssignmentExpression(node, ancestors) {
      var _a, _b, _c;
      if (!(0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator)) {
        return;
      }
      if (((_a = node.left) == null ? void 0 : _a.type) === "Identifier" && node.left.name === "React") {
        const capability = getInvalidReactDefaultCapabilityFromSource(node.right);
        if (capability) {
          addEntry(node.left.name, capability, node.left, ancestors);
        }
        return;
      }
      if (((_b = node.left) == null ? void 0 : _b.type) === "ObjectPattern" && (0, import_react_values.getReactNamespaceCapabilityFromAst)(node.right, identifierBindings, namespaceAliases, ctxRootAliases)) {
        const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          node.right,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.left, (alias, members, aliasNode) => {
          if (members.length === 1 && members[0] === "default" && alias === "React") {
            addEntry(alias, `${namespace}.default`, aliasNode || node, ancestors);
          }
        });
      }
      if (((_c = node.left) == null ? void 0 : _c.type) === "ObjectPattern" && (0, import_static_values.isCtxRootFromAst)(node.right, ctxRootAliases, identifierBindings)) {
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.left, (alias, members, aliasNode) => {
          if (members.length === 2 && members[0] === "React" && members[1] === "default" && alias === "React") {
            addEntry(alias, "ctx.React.default", aliasNode || node, ancestors);
          }
        });
      }
      if (node.operator === "=") {
        collectInvalidReactPatternSourceBindingsFromAst(node.left, node.right, ancestors);
        collectInvalidReactPatternDefaultBindingsFromAst(node.left, ancestors, node.right);
      }
    },
    ForOfStatement(node, ancestors) {
      const target = (0, import_execution.getAstLoopPatternTarget)(node.left);
      if (!target) {
        return;
      }
      const sourceTargetAliases = [...namespaceAliases, ...defaultAliases];
      (0, import_execution.collectAstForOfSourceTargets)(node.right, sourceTargetAliases, identifierBindings, (loopSourceTarget) => {
        collectInvalidReactPatternSourceTargetBindingsFromAst(target, loopSourceTarget, ancestors);
        collectInvalidReactPatternDefaultBindingsFromSourceTarget(target, ancestors, loopSourceTarget);
      });
    },
    VariableDeclarator(node, ancestors) {
      var _a, _b, _c;
      const sourceTargetAliases = [...namespaceAliases, ...defaultAliases];
      if ((0, import_execution.isAstForOfLoopVariableDeclaratorWithSourceTargets)(node, ancestors, sourceTargetAliases, identifierBindings)) {
        return;
      }
      if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier" && node.id.name === "React") {
        const capability = getInvalidReactDefaultCapabilityFromSource(node.init);
        if (capability) {
          addEntry(node.id.name, capability, node.id, ancestors);
        }
        return;
      }
      if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern" && (0, import_react_values.getReactNamespaceCapabilityFromAst)(node.init, identifierBindings, namespaceAliases, ctxRootAliases)) {
        const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          node.init,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.id, (alias, members, aliasNode) => {
          if (members.length === 1 && members[0] === "default" && alias === "React") {
            addEntry(alias, `${namespace}.default`, aliasNode || node, ancestors);
          }
        });
        collectInvalidReactPatternSourceBindingsFromAst(node.id, node.init, ancestors);
        return;
      }
      if (((_c = node.id) == null ? void 0 : _c.type) === "ObjectPattern" && (0, import_static_values.isCtxRootFromAst)(node.init, ctxRootAliases, identifierBindings)) {
        (0, import_static_values.collectAstObjectPatternPathAliases)(node.id, (alias, members, aliasNode) => {
          if (members.length === 2 && members[0] === "React" && members[1] === "default" && alias === "React") {
            addEntry(alias, "ctx.React.default", aliasNode || node, ancestors);
          }
        });
      }
      collectInvalidReactPatternSourceBindingsFromAst(node.id, node.init, ancestors);
      collectInvalidReactPatternDefaultBindingsFromAst(node.id, ancestors, node.init);
    },
    FunctionDeclaration(node, ancestors) {
      collectInvalidReactFunctionParamBindingsFromAst(node, ancestors);
    },
    FunctionExpression(node, ancestors) {
      collectInvalidReactFunctionParamBindingsFromAst(node, ancestors);
    },
    ArrowFunctionExpression(node, ancestors) {
      collectInvalidReactFunctionParamBindingsFromAst(node, ancestors);
    }
  });
  return entries;
  function collectInvalidReactFunctionParamBindingsFromAst(node, ancestors) {
    var _a, _b;
    for (const param of node.params || []) {
      if ((param == null ? void 0 : param.type) !== "AssignmentPattern") {
        collectInvalidReactPatternDefaultBindingsFromAst(param, ancestors);
        continue;
      }
      collectInvalidReactPatternDefaultBindingsFromAst(param.left, ancestors, param.right);
      collectInvalidReactPatternSourceBindingsFromAst(param.left, param.right, ancestors);
      if (((_a = param.left) == null ? void 0 : _a.type) === "Identifier" && param.left.name === "React") {
        const capability = getInvalidReactDefaultCapabilityFromSource(param.right);
        if (capability) {
          addEntry(param.left.name, capability, param.left, ancestors);
        }
        continue;
      }
      if (((_b = param.left) == null ? void 0 : _b.type) !== "ObjectPattern") {
        continue;
      }
      const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
        param.right,
        identifierBindings,
        namespaceAliases,
        ctxRootAliases
      );
      if (namespace) {
        (0, import_static_values.collectAstObjectPatternPathAliases)(param.left, (alias, members, aliasNode) => {
          if (members.length === 1 && members[0] === "default" && alias === "React") {
            addEntry(alias, `${namespace}.default`, aliasNode || param, ancestors);
          }
        });
      }
      if ((0, import_static_values.isCtxRootFromAst)(param.right, ctxRootAliases, identifierBindings)) {
        (0, import_static_values.collectAstObjectPatternPathAliases)(param.left, (alias, members, aliasNode) => {
          if (members.length === 2 && members[0] === "React" && members[1] === "default" && alias === "React") {
            addEntry(alias, "ctx.React.default", aliasNode || param, ancestors);
          }
        });
      }
    }
  }
  function getInvalidReactDefaultCapabilityFromSource(sourceNode) {
    if (!sourceNode) {
      return "";
    }
    return (0, import_react_values.getReactDefaultNamespaceCapabilityFromAstPatternSource)(
      (0, import_static_values.createAstPatternSourceTarget)(sourceNode),
      identifierBindings,
      namespaceAliases,
      ctxRootAliases,
      defaultAliases
    );
  }
  function collectInvalidReactPatternSourceBindingsFromAst(pattern, sourceNode, ancestors) {
    collectInvalidReactPatternSourceTargetBindingsFromAst(pattern, (0, import_static_values.createAstPatternSourceTarget)(sourceNode), ancestors);
  }
  function collectInvalidReactPatternSourceTargetBindingsFromAst(pattern, sourceTarget, ancestors) {
    (0, import_static_values.collectAstPatternSourceTargetsRec)(pattern, sourceTarget, (target, patternSourceTarget) => {
      const unwrapped = (0, import_bindings.unwrapAstChainExpression)(target);
      if ((unwrapped == null ? void 0 : unwrapped.type) !== "Identifier" || unwrapped.name !== "React") {
        return;
      }
      const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAstPatternSource)(
        patternSourceTarget,
        identifierBindings,
        namespaceAliases,
        ctxRootAliases,
        defaultAliases
      );
      if (capability) {
        addEntry(unwrapped.name, capability, unwrapped, ancestors);
      }
    });
  }
  function collectInvalidReactPatternDefaultBindingsFromAst(pattern, ancestors, sourceNode) {
    collectInvalidReactPatternDefaultBindingsFromSourceTarget(
      pattern,
      ancestors,
      (0, import_static_values.createMaybeAstPatternSourceTarget)(sourceNode)
    );
  }
  function collectInvalidReactPatternDefaultBindingsFromSourceTarget(pattern, ancestors, sourceTarget) {
    (0, import_static_values.collectAstPatternDefaultValueAliasesWithSource)(
      pattern,
      sourceTarget,
      (alias, valueNode, aliasNode, defaultPattern, sourceTarget2) => {
        if ((0, import_react_values.isAstPatternDefaultValueSuppressedByReactNamespace)(
          sourceTarget2,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        )) {
          return;
        }
        const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAst)(
          valueNode,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases,
          defaultAliases
        );
        if (capability && alias === "React" && (defaultPattern == null ? void 0 : defaultPattern.type) === "Identifier") {
          addEntry(alias, capability, aliasNode || defaultPattern, ancestors);
        }
        if ((defaultPattern == null ? void 0 : defaultPattern.type) !== "ObjectPattern") {
          return;
        }
        const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
          valueNode,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        if (namespace) {
          (0, import_static_values.collectAstObjectPatternPathAliases)(defaultPattern, (pathAlias, members, pathAliasNode) => {
            if (members.length === 1 && members[0] === "default" && pathAlias === "React") {
              addEntry(pathAlias, `${namespace}.default`, pathAliasNode || aliasNode || defaultPattern, ancestors);
            }
          });
        }
        if ((0, import_static_values.isCtxRootFromAst)(valueNode, ctxRootAliases, identifierBindings)) {
          (0, import_static_values.collectAstObjectPatternPathAliases)(defaultPattern, (pathAlias, members, pathAliasNode) => {
            if (members.length === 2 && members[0] === "React" && members[1] === "default" && pathAlias === "React") {
              addEntry(pathAlias, "ctx.React.default", pathAliasNode || aliasNode || defaultPattern, ancestors);
            }
          });
        }
      }
    );
  }
}
function collectReactNamespaceCarrierAliasesFromAst(containerName, sourceNode, identifierBindings, namespaceAliases, ctxRootAliases, addAlias) {
  const visitedTargets = /* @__PURE__ */ new Set();
  const collectAliases = (targetAliasName, sourceTarget) => {
    var _a, _b;
    if (!sourceTarget) {
      return;
    }
    const visitKey = `${targetAliasName}:${sourceTarget.aliasName || ""}:${((_a = sourceTarget.node) == null ? void 0 : _a.start) || 0}:${((_b = sourceTarget.node) == null ? void 0 : _b.end) || 0}:${sourceTarget.index || 0}`;
    if (visitedTargets.has(visitKey)) {
      return;
    }
    visitedTargets.add(visitKey);
    (0, import_static_values.collectAstCarrierSourceTargets)(
      void 0,
      targetAliasName,
      sourceTarget,
      namespaceAliases,
      identifierBindings,
      (carrierTarget) => {
        var _a2, _b2;
        const member = getAstNestedCarrierMemberName(containerName, carrierTarget.targetAliasName);
        if (!member) {
          return;
        }
        if (carrierTarget.sourceAlias) {
          addAlias(
            member,
            carrierTarget.sourceAlias.capability,
            (_a2 = carrierTarget.sourceTarget) == null ? void 0 : _a2.node,
            (0, import_static_values.getAstAliasPrecedenceStart)(carrierTarget.sourceAlias)
          );
          return;
        }
        const capability = (0, import_react_values.getReactNamespaceCapabilityFromAstPatternSource)(
          carrierTarget.sourceTarget,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases
        );
        if (capability) {
          addAlias(member, capability, (_b2 = carrierTarget.sourceTarget) == null ? void 0 : _b2.node);
        }
        collectAliases(carrierTarget.targetAliasName, carrierTarget.sourceTarget);
      }
    );
  };
  collectAliases(containerName, (0, import_static_values.createAstPatternSourceTarget)(sourceNode));
}
function collectReactDefaultCarrierAliasesFromAst(containerName, sourceNode, identifierBindings, namespaceAliases, ctxRootAliases, defaultAliases, addAlias) {
  const carrierAliases = [...namespaceAliases, ...defaultAliases];
  const visitedTargets = /* @__PURE__ */ new Set();
  const collectAliases = (targetAliasName, sourceTarget) => {
    var _a, _b;
    if (!sourceTarget) {
      return;
    }
    const visitKey = `${targetAliasName}:${sourceTarget.aliasName || ""}:${((_a = sourceTarget.node) == null ? void 0 : _a.start) || 0}:${((_b = sourceTarget.node) == null ? void 0 : _b.end) || 0}:${sourceTarget.index || 0}`;
    if (visitedTargets.has(visitKey)) {
      return;
    }
    visitedTargets.add(visitKey);
    (0, import_static_values.collectAstCarrierSourceTargets)(
      void 0,
      targetAliasName,
      sourceTarget,
      carrierAliases,
      identifierBindings,
      (carrierTarget) => {
        var _a2, _b2;
        const member = getAstNestedCarrierMemberName(containerName, carrierTarget.targetAliasName);
        if (!member) {
          return;
        }
        if (carrierTarget.sourceAlias) {
          const capability2 = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAstPatternSource)(
            {
              aliasName: carrierTarget.sourceAlias.name,
              index: carrierTarget.sourceAlias.start,
              rootName: (0, import_static_values.getAstAliasRootName)(carrierTarget.sourceAlias.name)
            },
            identifierBindings,
            namespaceAliases,
            ctxRootAliases,
            defaultAliases
          );
          if (capability2) {
            addAlias(
              member,
              capability2,
              (_a2 = carrierTarget.sourceTarget) == null ? void 0 : _a2.node,
              (0, import_static_values.getAstAliasPrecedenceStart)(carrierTarget.sourceAlias)
            );
          }
          return;
        }
        const capability = (0, import_react_values.getReactDefaultNamespaceCapabilityFromAstPatternSource)(
          carrierTarget.sourceTarget,
          identifierBindings,
          namespaceAliases,
          ctxRootAliases,
          defaultAliases
        );
        if (capability) {
          addAlias(member, capability, (_b2 = carrierTarget.sourceTarget) == null ? void 0 : _b2.node);
        }
        collectAliases(carrierTarget.targetAliasName, carrierTarget.sourceTarget);
      }
    );
  };
  collectAliases(containerName, (0, import_static_values.createAstPatternSourceTarget)(sourceNode));
}
function getAstNestedCarrierMemberName(containerName, targetAliasName) {
  const prefix = `${containerName}.`;
  return targetAliasName.startsWith(prefix) ? targetAliasName.slice(prefix.length) : "";
}
function collectReactAsyncComponentBindingsFromAst(ast, source, identifierBindings) {
  const bindings = [];
  const addBinding = (name, componentNode, scope, declarationNode) => {
    if (!/^[A-Z][\w$]*$/.test(name)) {
      return;
    }
    const declarationStart = typeof (declarationNode == null ? void 0 : declarationNode.start) === "number" ? declarationNode.start : typeof (componentNode == null ? void 0 : componentNode.start) === "number" ? componentNode.start : scope.start;
    bindings.push({
      capability: name,
      component: name,
      declarationStart,
      name,
      start: scope.start,
      end: scope.end
    });
  };
  (0, import_walk.walkAstAncestor)(ast, {
    FunctionDeclaration(node, ancestors) {
      var _a;
      if (!node.async || ((_a = node.id) == null ? void 0 : _a.type) !== "Identifier") {
        return;
      }
      const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors.slice(0, -1), source.length);
      addBinding(node.id.name, node.id, scope, node);
    },
    VariableDeclarator(node, ancestors) {
      var _a;
      if (((_a = node.id) == null ? void 0 : _a.type) !== "Identifier" || !isAstAsyncFunctionLike(node.init)) {
        return;
      }
      const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
      const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, (declaration == null ? void 0 : declaration.kind) === "var");
      addBinding(node.id.name, node.id, scope, node);
    },
    AssignmentExpression(node, ancestors) {
      var _a;
      if (node.operator !== "=" || ((_a = node.left) == null ? void 0 : _a.type) !== "Identifier" || !isAstAsyncFunctionLike(node.right)) {
        return;
      }
      const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length);
      addBinding(node.left.name, node.left, scope, node);
    }
  });
  return bindings;
}
function collectAstReactAsyncComponentReferences(node, asyncComponentBindings, reactCreateElementAliases, identifierBindings) {
  var _a, _b, _c;
  const capability = getReactCreateElementCallCapabilityFromAst(node, reactCreateElementAliases, identifierBindings);
  if (!capability) {
    return [];
  }
  const component = resolveAstAsyncComponentBinding((_a = node.arguments) == null ? void 0 : _a[0], asyncComponentBindings, identifierBindings);
  return component ? [
    {
      capability,
      component: component.component,
      index: typeof ((_c = (_b = node.arguments) == null ? void 0 : _b[0]) == null ? void 0 : _c.start) === "number" ? node.arguments[0].start : node.start || 0
    }
  ] : [];
}
function resolveAstAsyncComponentBinding(node, bindings, identifierBindings) {
  const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
  if (!unwrapped || unwrapped.type !== "Identifier") {
    return void 0;
  }
  return (0, import_static_values.resolveAstAliasBinding)(unwrapped.name, unwrapped.start || 0, bindings, identifierBindings);
}
function getReactCreateElementCallCapabilityFromAst(node, aliases, identifierBindings) {
  const callee = (0, import_bindings.unwrapAstChainExpression)(node.callee);
  if ((callee == null ? void 0 : callee.type) === "Identifier") {
    const alias = (0, import_static_values.resolveAstAliasBinding)(callee.name, node.start || 0, aliases, identifierBindings);
    return (alias == null ? void 0 : alias.capability) || "";
  }
  return getReactCreateElementCapabilityFromAst(callee, identifierBindings, []);
}
function getReactCreateElementCapabilityFromAst(node, identifierBindings, namespaceAliases, ctxRootAliases = []) {
  const member = (0, import_bindings.unwrapAstChainExpression)(node);
  if (!member || member.type !== "MemberExpression") {
    return "";
  }
  const propertyName = (0, import_static_values.getAstStaticPropertyName)(member);
  if (propertyName !== "createElement") {
    return "";
  }
  const namespace = (0, import_react_values.getReactNamespaceCapabilityFromAst)(
    member.object,
    identifierBindings,
    namespaceAliases,
    ctxRootAliases
  );
  return namespace ? `${namespace}.createElement` : "";
}
function isAstAsyncFunctionLike(node) {
  const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
  return !!(unwrapped == null ? void 0 : unwrapped.async) && (unwrapped.type === "FunctionExpression" || unwrapped.type === "ArrowFunctionExpression");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  collectAstInvalidReactRuntimeBindingsFromAst,
  collectAstReactAsyncComponentReferences,
  collectReactAsyncComponentBindingsFromAst,
  collectReactCreateElementAliasesFromAst,
  collectReactDefaultAliasesFromAst,
  collectReactDefaultCarrierAliasesFromAst,
  collectReactNamespaceAliasesFromAst,
  collectReactNamespaceCarrierAliasesFromAst,
  getAstNestedCarrierMemberName,
  getReactCreateElementCallCapabilityFromAst,
  getReactCreateElementCapabilityFromAst,
  isAstAsyncFunctionLike,
  resolveAstAsyncComponentBinding
});
