{"version":3,"names":["_index","require","getNameFromLiteralId","id","isNullLiteral","isRegExpLiteral","pattern","flags","isTemplateLiteral","quasis","map","quasi","value","raw","join","undefined","String","getObjectMemberKey","node","computed","isLiteral","key","getFunctionName","parent","name","originalNode","prefix","isObjectProperty","isObjectMethod","isClassMethod","kind","isVariableDeclarator","init","isAssignmentExpression","operator","right","left","isIdentifier","isPrivateName"],"sources":["../../src/retrievers/getFunctionName.ts"],"sourcesContent":["import type * as t from \"../index.ts\";\n\nimport {\n isAssignmentExpression,\n isClassMethod,\n isIdentifier,\n isLiteral,\n isNullLiteral,\n isObjectMethod,\n isObjectProperty,\n isPrivateName,\n isRegExpLiteral,\n isTemplateLiteral,\n isVariableDeclarator,\n} from \"../validators/generated/index.ts\";\n\nfunction getNameFromLiteralId(id: t.Literal): string {\n if (isNullLiteral(id)) {\n return \"null\";\n }\n\n if (isRegExpLiteral(id)) {\n return `/${id.pattern}/${id.flags}`;\n }\n\n if (isTemplateLiteral(id)) {\n return id.quasis.map(quasi => quasi.value.raw).join(\"\");\n }\n\n if (id.value !== undefined) {\n return String(id.value);\n }\n\n return null;\n}\n\nfunction getObjectMemberKey(\n node: t.ObjectProperty | t.ObjectMethod | t.ClassProperty | t.ClassMethod,\n): t.Expression | t.PrivateName {\n if (!node.computed || isLiteral(node.key)) {\n return node.key;\n }\n}\n\ntype GetFunctionNameResult = {\n name: string;\n originalNode: t.Node;\n} | null;\n\nexport default function getFunctionName(\n node: t.ObjectMethod | t.ClassMethod,\n): GetFunctionNameResult;\nexport default function getFunctionName(\n node: t.Function | t.Class,\n parent: t.Node,\n): GetFunctionNameResult;\nexport default function getFunctionName(\n node: t.Function | t.Class,\n parent?: t.Node,\n): GetFunctionNameResult {\n if (\"id\" in node && node.id) {\n return {\n name: node.id.name,\n originalNode: node.id,\n };\n }\n\n let prefix = \"\";\n\n let id;\n if (isObjectProperty(parent, { value: node })) {\n // { foo: () => {} };\n id = getObjectMemberKey(parent);\n } else if (isObjectMethod(node) || isClassMethod(node)) {\n // { foo() {} };\n id = getObjectMemberKey(node);\n if (node.kind === \"get\") prefix = \"get \";\n else if (node.kind === \"set\") prefix = \"set \";\n } else if (isVariableDeclarator(parent, { init: node })) {\n // let foo = function () {};\n id = parent.id;\n } else if (isAssignmentExpression(parent, { operator: \"=\", right: node })) {\n // foo = function () {};\n id = parent.left;\n }\n\n if (!id) return null;\n\n const name = isLiteral(id)\n ? getNameFromLiteralId(id)\n : isIdentifier(id)\n ? id.name\n : isPrivateName(id)\n ? id.id.name\n : null;\n if (name == null) return null;\n\n return { name: prefix + name, originalNode: id };\n}\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAcA,SAASC,oBAAoBA,CAACC,EAAa,EAAU;EACnD,IAAI,IAAAC,oBAAa,EAACD,EAAE,CAAC,EAAE;IACrB,OAAO,MAAM;EACf;EAEA,IAAI,IAAAE,sBAAe,EAACF,EAAE,CAAC,EAAE;IACvB,OAAO,IAAIA,EAAE,CAACG,OAAO,IAAIH,EAAE,CAACI,KAAK,EAAE;EACrC;EAEA,IAAI,IAAAC,wBAAiB,EAACL,EAAE,CAAC,EAAE;IACzB,OAAOA,EAAE,CAACM,MAAM,CAACC,GAAG,CAACC,KAAK,IAAIA,KAAK,CAACC,KAAK,CAACC,GAAG,CAAC,CAACC,IAAI,CAAC,EAAE,CAAC;EACzD;EAEA,IAAIX,EAAE,CAACS,KAAK,KAAKG,SAAS,EAAE;IAC1B,OAAOC,MAAM,CAACb,EAAE,CAACS,KAAK,CAAC;EACzB;EAEA,OAAO,IAAI;AACb;AAEA,SAASK,kBAAkBA,CACzBC,IAAyE,EAC3C;EAC9B,IAAI,CAACA,IAAI,CAACC,QAAQ,IAAI,IAAAC,gBAAS,EAACF,IAAI,CAACG,GAAG,CAAC,EAAE;IACzC,OAAOH,IAAI,CAACG,GAAG;EACjB;AACF;AAce,SAASC,eAAeA,CACrCJ,IAA0B,EAC1BK,MAAe,EACQ;EACvB,IAAI,IAAI,IAA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