[79a0317] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = void 0;
|
---|
| 7 | var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
---|
| 8 | var _helperCompilationTargets = require("@babel/helper-compilation-targets");
|
---|
| 9 | var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
|
---|
| 10 | var _core = require("@babel/core");
|
---|
| 11 | var _globals = require("globals");
|
---|
| 12 | var _transformClass = require("./transformClass.js");
|
---|
| 13 | const getBuiltinClasses = category => Object.keys(_globals[category]).filter(name => /^[A-Z]/.test(name));
|
---|
| 14 | const builtinClasses = new Set([...getBuiltinClasses("builtin"), ...getBuiltinClasses("browser")]);
|
---|
| 15 | var _default = exports.default = (0, _helperPluginUtils.declare)((api, options) => {
|
---|
| 16 | var _api$assumption, _api$assumption2, _api$assumption3, _api$assumption4;
|
---|
| 17 | api.assertVersion(7);
|
---|
| 18 | const {
|
---|
| 19 | loose = false
|
---|
| 20 | } = options;
|
---|
| 21 | const setClassMethods = (_api$assumption = api.assumption("setClassMethods")) != null ? _api$assumption : loose;
|
---|
| 22 | const constantSuper = (_api$assumption2 = api.assumption("constantSuper")) != null ? _api$assumption2 : loose;
|
---|
| 23 | const superIsCallableConstructor = (_api$assumption3 = api.assumption("superIsCallableConstructor")) != null ? _api$assumption3 : loose;
|
---|
| 24 | const noClassCalls = (_api$assumption4 = api.assumption("noClassCalls")) != null ? _api$assumption4 : loose;
|
---|
| 25 | const supportUnicodeId = !(0, _helperCompilationTargets.isRequired)("transform-unicode-escapes", api.targets());
|
---|
| 26 | const VISITED = new WeakSet();
|
---|
| 27 | return {
|
---|
| 28 | name: "transform-classes",
|
---|
| 29 | visitor: {
|
---|
| 30 | ExportDefaultDeclaration(path) {
|
---|
| 31 | if (!path.get("declaration").isClassDeclaration()) return;
|
---|
| 32 | {
|
---|
| 33 | var _path$splitExportDecl;
|
---|
| 34 | (_path$splitExportDecl = path.splitExportDeclaration) != null ? _path$splitExportDecl : path.splitExportDeclaration = require("@babel/traverse").NodePath.prototype.splitExportDeclaration;
|
---|
| 35 | }
|
---|
| 36 | path.splitExportDeclaration();
|
---|
| 37 | },
|
---|
| 38 | ClassDeclaration(path) {
|
---|
| 39 | const {
|
---|
| 40 | node
|
---|
| 41 | } = path;
|
---|
| 42 | const ref = node.id ? _core.types.cloneNode(node.id) : path.scope.generateUidIdentifier("class");
|
---|
| 43 | path.replaceWith(_core.types.variableDeclaration("let", [_core.types.variableDeclarator(ref, _core.types.toExpression(node))]));
|
---|
| 44 | },
|
---|
| 45 | ClassExpression(path, state) {
|
---|
| 46 | const {
|
---|
| 47 | node
|
---|
| 48 | } = path;
|
---|
| 49 | if (VISITED.has(node)) return;
|
---|
| 50 | {
|
---|
| 51 | var _path$ensureFunctionN;
|
---|
| 52 | (_path$ensureFunctionN = path.ensureFunctionName) != null ? _path$ensureFunctionN : path.ensureFunctionName = require("@babel/traverse").NodePath.prototype.ensureFunctionName;
|
---|
| 53 | }
|
---|
| 54 | const replacement = path.ensureFunctionName(supportUnicodeId);
|
---|
| 55 | if (replacement && replacement.node !== node) return;
|
---|
| 56 | VISITED.add(node);
|
---|
| 57 | const [replacedPath] = path.replaceWith((0, _transformClass.default)(path, state.file, builtinClasses, loose, {
|
---|
| 58 | setClassMethods,
|
---|
| 59 | constantSuper,
|
---|
| 60 | superIsCallableConstructor,
|
---|
| 61 | noClassCalls
|
---|
| 62 | }, supportUnicodeId));
|
---|
| 63 | if (replacedPath.isCallExpression()) {
|
---|
| 64 | (0, _helperAnnotateAsPure.default)(replacedPath);
|
---|
| 65 | const callee = replacedPath.get("callee");
|
---|
| 66 | if (callee.isArrowFunctionExpression()) {
|
---|
| 67 | callee.arrowFunctionToExpression();
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | };
|
---|
| 73 | });
|
---|
| 74 |
|
---|
| 75 | //# sourceMappingURL=index.js.map
|
---|