You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
7.4 KiB
1 line
7.4 KiB
4 weeks ago
|
{"version":3,"names":["_helperPluginUtils","require","_helperCompilationTargets","_helperAnnotateAsPure","_core","_globals","_transformClass","getBuiltinClasses","category","Object","keys","globals","filter","name","test","builtinClasses","Set","_default","exports","default","declare","api","options","_api$assumption","_api$assumption2","_api$assumption3","_api$assumption4","assertVersion","loose","setClassMethods","assumption","constantSuper","superIsCallableConstructor","noClassCalls","supportUnicodeId","isRequired","targets","VISITED","WeakSet","visitor","ExportDefaultDeclaration","path","get","isClassDeclaration","_path$splitExportDecl","splitExportDeclaration","NodePath","prototype","ClassDeclaration","node","ref","id","t","cloneNode","scope","generateUidIdentifier","replaceWith","variableDeclaration","variableDeclarator","toExpression","ClassExpression","state","has","_path$ensureFunctionN","ensureFunctionName","replacement","add","replacedPath","transformClass","file","isCallExpression","annotateAsPure","callee","isArrowFunctionExpression","arrowFunctionToExpression"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport { isRequired } from \"@babel/helper-compilation-targets\";\nimport annotateAsPure from \"@babel/helper-annotate-as-pure\";\nimport { types as t } from \"@babel/core\";\nimport globals from \"globals\";\nimport transformClass from \"./transformClass.ts\";\n\nconst getBuiltinClasses = (category: keyof typeof globals) =>\n Object.keys(globals[category]).filter(name => /^[A-Z]/.test(name));\n\nconst builtinClasses = new Set([\n ...getBuiltinClasses(\"builtin\"),\n ...getBuiltinClasses(\"browser\"),\n]);\n\nexport interface Options {\n loose?: boolean;\n}\n\nexport default declare((api, options: Options) => {\n api.assertVersion(REQUIRED_VERSION(7));\n\n const { loose = false } = options;\n\n const setClassMethods = api.assumption(\"setClassMethods\") ?? loose;\n const constantSuper = api.assumption(\"constantSuper\") ?? loose;\n const superIsCallableConstructor =\n api.assumption(\"superIsCallableConstructor\") ?? loose;\n const noClassCalls = api.assumption(\"noClassCalls\") ?? loose;\n const supportUnicodeId = !isRequired(\n \"transform-unicode-escapes\",\n api.targets(),\n );\n\n // todo: investigate traversal requeueing\n const VISITED = new WeakSet();\n\n return {\n name: \"transform-classes\",\n\n visitor: {\n ExportDefaultDeclaration(path) {\n if (!path.get(\"declaration\").isClassDeclaration()) return;\n if (!process.env.BABEL_8_BREAKING && !USE_ESM && !IS_STANDALONE) {\n // polyfill when being run by an older Babel version\n path.splitExportDeclaration ??=\n // eslint-disable-next-line no-restricted-globals\n require(\"@babel/traverse\").NodePath.prototype.splitExportDeclaration;\n }\n path.splitExportDeclaration();\n },\n\n ClassDeclaration(path) {\n const { node } = path;\n\n const ref = node.id\n ? t.cloneNode(node.id)\n : path.scope.generateUidIdentifier(\"class\");\n\n path.replaceWith(\n t.variableDeclaration(\"let\", [\n t.variableDeclarator(ref, t.toExpression(node)),\n ]),\n );\n },\n\n ClassExpression(path, state) {\n const { node } = path;\n if (VISITED.has(node)) return;\n\n if (!process.env.BABEL_8_BREAKING && !USE_ESM && !IS_STANDALONE) {\n // polyfill when being run by an older Babel version\n path.ensureFunctionName ??=\n // eslint-disable-next-line no-restricted-globals\n require(\"@babel/traverse\").NodePath.prototype.ensureFunctionName;\n }\n const replacement = path.ensureFunctionName(supportUnicodeId);\n if (replacement && replacement.node !== node) return;\n\n VISITED.add(node);\n\n const [replacedPath] = path.replaceWith(\n transformClass(\n path,\n state.file,\n builtinClasses,\n
|