1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@babel/plugin-transform-classes/lib/index.js

73 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
2024-01-16 21:26:16 +08:00
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _helperCompilationTargets = require("@babel/helper-compilation-targets");
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
var _helperFunctionName = require("@babel/helper-function-name");
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
var _core = require("@babel/core");
var _globals = require("globals");
var _transformClass = require("./transformClass.js");
const getBuiltinClasses = category => Object.keys(_globals[category]).filter(name => /^[A-Z]/.test(name));
2023-12-18 13:12:25 +08:00
const builtinClasses = new Set([...getBuiltinClasses("builtin"), ...getBuiltinClasses("browser")]);
2024-01-16 21:26:16 +08:00
var _default = exports.default = (0, _helperPluginUtils.declare)((api, options) => {
var _api$assumption, _api$assumption2, _api$assumption3, _api$assumption4;
2023-12-18 13:12:25 +08:00
api.assertVersion(7);
const {
2024-01-16 21:26:16 +08:00
loose = false
2023-12-18 13:12:25 +08:00
} = options;
2024-01-16 21:26:16 +08:00
const setClassMethods = (_api$assumption = api.assumption("setClassMethods")) != null ? _api$assumption : loose;
const constantSuper = (_api$assumption2 = api.assumption("constantSuper")) != null ? _api$assumption2 : loose;
const superIsCallableConstructor = (_api$assumption3 = api.assumption("superIsCallableConstructor")) != null ? _api$assumption3 : loose;
const noClassCalls = (_api$assumption4 = api.assumption("noClassCalls")) != null ? _api$assumption4 : loose;
const supportUnicodeId = !(0, _helperCompilationTargets.isRequired)("transform-unicode-escapes", api.targets());
const VISITED = new WeakSet();
2023-12-18 13:12:25 +08:00
return {
name: "transform-classes",
visitor: {
ExportDefaultDeclaration(path) {
if (!path.get("declaration").isClassDeclaration()) return;
2024-01-16 21:26:16 +08:00
(0, _helperSplitExportDeclaration.default)(path);
2023-12-18 13:12:25 +08:00
},
ClassDeclaration(path) {
const {
node
} = path;
const ref = node.id || path.scope.generateUidIdentifier("class");
2024-01-16 21:26:16 +08:00
path.replaceWith(_core.types.variableDeclaration("let", [_core.types.variableDeclarator(ref, _core.types.toExpression(node))]));
2023-12-18 13:12:25 +08:00
},
ClassExpression(path, state) {
const {
node
} = path;
2024-01-16 21:26:16 +08:00
if (VISITED.has(node)) return;
const inferred = (0, _helperFunctionName.default)(path, undefined, supportUnicodeId);
2023-12-18 13:12:25 +08:00
if (inferred && inferred !== node) {
path.replaceWith(inferred);
return;
}
2024-01-16 21:26:16 +08:00
VISITED.add(node);
const [replacedPath] = path.replaceWith((0, _transformClass.default)(path, state.file, builtinClasses, loose, {
setClassMethods,
constantSuper,
superIsCallableConstructor,
noClassCalls
}, supportUnicodeId));
if (replacedPath.isCallExpression()) {
(0, _helperAnnotateAsPure.default)(replacedPath);
const callee = replacedPath.get("callee");
if (callee.isArrowFunctionExpression()) {
callee.arrowFunctionToExpression();
2023-12-18 13:12:25 +08:00
}
}
}
}
};
});
2024-01-16 21:26:16 +08:00
//# sourceMappingURL=index.js.map