amis-rpc-design/node_modules/@babel/plugin-transform-react-display-name/lib/index.js.map
2023-10-07 19:42:30 +08:00

1 line
7.0 KiB
Plaintext

{"version":3,"names":["_helperPluginUtils","require","_path","_core","_default","declare","api","assertVersion","addDisplayName","id","call","props","arguments","properties","safe","i","length","prop","t","isSpreadElement","key","toComputedKey","isStringLiteral","value","unshift","objectProperty","identifier","stringLiteral","isCreateClassCallExpression","buildMatchMemberExpression","isCreateClassAddon","callee","isIdentifier","name","isCreateClass","node","isCallExpression","args","first","isObjectExpression","visitor","ExportDefaultDeclaration","state","declaration","filename","displayName","path","basename","extname","dirname","CallExpression","find","isAssignmentExpression","left","isObjectProperty","isVariableDeclarator","isStatement","isMemberExpression","property","exports","default"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport path from \"path\";\nimport { types as t } from \"@babel/core\";\n\ntype ReactCreateClassCall = t.CallExpression & {\n arguments: [t.ObjectExpression];\n};\n\nexport default declare(api => {\n api.assertVersion(7);\n\n function addDisplayName(id: string, call: ReactCreateClassCall) {\n const props = call.arguments[0].properties;\n let safe = true;\n\n for (let i = 0; i < props.length; i++) {\n const prop = props[i];\n if (t.isSpreadElement(prop)) {\n continue;\n }\n const key = t.toComputedKey(prop);\n if (t.isStringLiteral(key, { value: \"displayName\" })) {\n safe = false;\n break;\n }\n }\n\n if (safe) {\n props.unshift(\n t.objectProperty(t.identifier(\"displayName\"), t.stringLiteral(id)),\n );\n }\n }\n\n const isCreateClassCallExpression =\n t.buildMatchMemberExpression(\"React.createClass\");\n const isCreateClassAddon = (callee: t.CallExpression[\"callee\"]) =>\n t.isIdentifier(callee, { name: \"createReactClass\" });\n\n function isCreateClass(node?: t.Node): node is ReactCreateClassCall {\n if (!node || !t.isCallExpression(node)) return false;\n\n // not createReactClass nor React.createClass call member object\n if (\n !isCreateClassCallExpression(node.callee) &&\n !isCreateClassAddon(node.callee)\n ) {\n return false;\n }\n\n // no call arguments\n const args = node.arguments;\n if (args.length !== 1) return false;\n\n // first node arg is not an object\n const first = args[0];\n if (!t.isObjectExpression(first)) return false;\n\n return true;\n }\n\n return {\n name: \"transform-react-display-name\",\n\n visitor: {\n ExportDefaultDeclaration({ node }, state) {\n if (isCreateClass(node.declaration)) {\n const filename = state.filename || \"unknown\";\n\n let displayName = path.basename(filename, path.extname(filename));\n\n // ./{module name}/index.js\n if (displayName === \"index\") {\n displayName = path.basename(path.dirname(filename));\n }\n\n addDisplayName(displayName, node.declaration);\n }\n },\n\n CallExpression(path) {\n const { node } = path;\n if (!isCreateClass(node)) return;\n\n let id: t.LVal | t.Expression | t.PrivateName | null;\n\n // crawl up the ancestry looking for possible candidates for displayName inference\n path.find(function (path) {\n if (path.isAssignmentExpression()) {\n id = path.node.left;\n } else if (path.isObjectProperty()) {\n id = path.node.key;\n } else if (path.isVariableDeclarator()) {\n id = path.node.id;\n } else if (path.isStatement()) {\n // we've hit a statement, we should stop crawling up\n return true;\n }\n\n // we've got an id! no need to continue\n if (id) return true;\n });\n\n // ensure that we have an identifier we can inherit from\n if (!id) return;\n\n // foo.bar -> bar\n if (t.isMemberExpression(id)) {\n id = id.property;\n }\n\n // identifiers are the only thing we can reliably get a name from\n if (t.isIdentifier(id)) {\n addDisplayName(id.name, node);\n }\n },\n },\n };\n});\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAAyC,IAAAG,QAAA,GAM1B,IAAAC,0BAAO,EAACC,GAAG,IAAI;EAC5BA,GAAG,CAACC,aAAa,CAAC,CAAC,CAAC;EAEpB,SAASC,cAAcA,CAACC,EAAU,EAAEC,IAA0B,EAAE;IAC9D,MAAMC,KAAK,GAAGD,IAAI,CAACE,SAAS,CAAC,CAAC,CAAC,CAACC,UAAU;IAC1C,IAAIC,IAAI,GAAG,IAAI;IAEf,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG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