{"version":3,"names":["_index","require","getBindingIdentifiers","node","duplicates","outerOnly","newBindingsOnly","search","concat","ids","Object","create","length","id","shift","isAssignmentExpression","isUnaryExpression","keys","type","isIdentifier","_ids","name","push","isExportDeclaration","isExportAllDeclaration","isDeclaration","declaration","isFunctionDeclaration","isFunctionExpression","i","key","nodes","Array","isArray","DeclareClass","DeclareFunction","DeclareModule","DeclareVariable","DeclareInterface","DeclareTypeAlias","DeclareOpaqueType","InterfaceDeclaration","TypeAlias","OpaqueType","CatchClause","LabeledStatement","UnaryExpression","AssignmentExpression","ImportSpecifier","ImportNamespaceSpecifier","ImportDefaultSpecifier","ImportDeclaration","ExportSpecifier","ExportNamespaceSpecifier","ExportDefaultSpecifier","FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","ObjectMethod","ClassMethod","ClassPrivateMethod","ForInStatement","ForOfStatement","ClassDeclaration","ClassExpression","RestElement","UpdateExpression","ObjectProperty","AssignmentPattern","ArrayPattern","ObjectPattern","VariableDeclaration","VariableDeclarator"],"sources":["../../src/retrievers/getBindingIdentifiers.ts"],"sourcesContent":["import {\n  isExportDeclaration,\n  isIdentifier,\n  isDeclaration,\n  isFunctionDeclaration,\n  isFunctionExpression,\n  isExportAllDeclaration,\n  isAssignmentExpression,\n  isUnaryExpression,\n} from \"../validators/generated/index.ts\";\nimport type * as t from \"../index.ts\";\n\nexport { getBindingIdentifiers as default };\n\nfunction getBindingIdentifiers(\n  node: t.Node,\n  duplicates: true,\n  outerOnly?: boolean,\n  newBindingsOnly?: boolean,\n): Record<string, Array<t.Identifier>>;\n\nfunction getBindingIdentifiers(\n  node: t.Node,\n  duplicates?: false,\n  outerOnly?: boolean,\n  newBindingsOnly?: boolean,\n): Record<string, t.Identifier>;\n\nfunction getBindingIdentifiers(\n  node: t.Node,\n  duplicates?: boolean,\n  outerOnly?: boolean,\n  newBindingsOnly?: boolean,\n): Record<string, t.Identifier> | Record<string, Array<t.Identifier>>;\n\n/**\n * Return a list of binding identifiers associated with the input `node`.\n */\nfunction getBindingIdentifiers(\n  node: t.Node,\n  duplicates?: boolean,\n  outerOnly?: boolean,\n  newBindingsOnly?: boolean,\n): Record<string, t.Identifier> | Record<string, Array<t.Identifier>> {\n  const search: t.Node[] = [].concat(node);\n  const ids = Object.create(null);\n\n  while (search.length) {\n    const id = search.shift();\n    if (!id) continue;\n\n    if (\n      newBindingsOnly &&\n      // These two nodes do not introduce _new_ bindings, but they are included\n      // in getBindingIdentifiers.keys for backwards compatibility.\n      // TODO(@nicolo-ribaudo): Check if we can remove them from .keys in a\n      // backward-compatible way, and if not what we need to do to remove them\n      // in Babel 8.\n      (isAssignmentExpression(id) || isUnaryExpression(id))\n    ) {\n      continue;\n    }\n\n    const keys =\n      // @ts-expect-error getBindingIdentifiers.keys do not cover all AST types\n      getBindingIdentifiers.keys[id.type];\n\n    if (isIdentifier(id)) {\n      if (duplicates) {\n        const _ids = (ids[id.name] = ids[id.name] || []);\n        _ids.push(id);\n      } else {\n        ids[id.name] = id;\n      }\n      continue;\n    }\n\n    if (isExportDeclaration(id) && !isExportAllDeclaration(id)) {\n      if (isDeclaration(id.declaration)) {\n        search.push(id.declaration);\n      }\n      continue;\n    }\n\n    if (outerOnly) {\n      if (isFunctionDeclaration(id)) {\n        search.push(id.id);\n        continue;\n      }\n\n      if (isFunctionExpression(id)) {\n        continue;\n      }\n    }\n\n    if (keys) {\n      for (let i = 0; i < keys.length; i++) {\n        const key = keys[i];\n        const nodes =\n          // @ts-expect-error key must present in id\n          id[key] as t.Node[] | t.Node | undefined | null;\n        if (nodes) {\n          Array.isArray(nodes) ? search.push(...nodes) : search.push(nodes);\n        }\n      }\n    }\n  }\n\n  // $FlowIssue Object.create() seems broken\n  return ids;\n}\n\n/**\n * Mapping of types to their identifier keys.\n */\ngetBindingIdentifiers.keys = {\n  DeclareClass: [\"id\"],\n  DeclareFunction: [\"id\"],\n  DeclareModule: [\"id\"],\n  DeclareVariable: [\"id\"],\n  DeclareInterface: [\"id\"],\n  DeclareTypeAlias: [\"id\"],\n  DeclareOpaqueType: [\"id\"],\n  InterfaceDeclaration: [\"id\"],\n  TypeAlias: [\"id\"],\n  OpaqueType: [\"id\"],\n\n  CatchClause: [\"param\"],\n  LabeledStatement: [\"label\"],\n  UnaryExpression: [\"argument\"],\n  AssignmentExpression: [\"left\"],\n\n  ImportSpecifier: [\"local\"],\n  ImportNamespaceSpecifier: [\"local\"],\n  ImportDefaultSpecifier: [\"local\"],\n  ImportDeclaration: [\"specifiers\"],\n\n  ExportSpecifier: [\"exported\"],\n  ExportNamespaceSpecifier: [\"exported\"],\n  ExportDefaultSpecifier: [\"exported\"],\n\n  FunctionDeclaration: [\"id\", \"params\"],\n  FunctionExpression: [\"id\", \"params\"],\n  ArrowFunctionExpression: [\"params\"],\n  ObjectMethod: [\"params\"],\n  ClassMethod: [\"params\"],\n  ClassPrivateMethod: [\"params\"],\n\n  ForInStatement: [\"left\"],\n  ForOfStatement: [\"left\"],\n\n  ClassDeclaration: [\"id\"],\n  ClassExpression: [\"id\"],\n\n  RestElement: [\"argument\"],\n  UpdateExpression: [\"argument\"],\n\n  ObjectProperty: [\"value\"],\n\n  AssignmentPattern: [\"left\"],\n  ArrayPattern: [\"elements\"],\n  ObjectPattern: [\"properties\"],\n\n  VariableDeclaration: [\"declarations\"],\n  VariableDeclarator: [\"id\"],\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAsCA,SAASC,qBAAqBA,CAC5BC,IAAY,EACZC,UAAoB,EACpBC,SAAmB,EACnBC,eAAyB,EAC2C;EACpE,MAAMC,MAAgB,GAAG,EAAE,CAACC,MAAM,CAACL,IAAI,CAAC;EACxC,MAAMM,GAAG,GAAGC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EAE/B,OAAOJ,MAAM,CAACK,MAAM,EAAE;IACpB,MAAMC,EAAE,GAAGN,MAAM,CAACO,KAAK,CAAC,CAAC;IACzB,IAAI,CAACD,EAAE,EAAE;IAET,IACEP,eAAe,K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