1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@babel/helper-split-export-declara.../lib/index.js

68 lines
2.7 KiB
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = splitExportDeclaration;
function t() {
2024-01-16 21:26:16 +08:00
var data = _interopRequireWildcard(require("@babel/types"));
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
t = function t() {
2023-12-18 13:12:25 +08:00
return data;
};
return data;
}
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function splitExportDeclaration(exportDeclaration) {
if (!exportDeclaration.isExportDeclaration()) {
throw new Error("Only export declarations can be splitted.");
}
2024-01-16 21:26:16 +08:00
var isDefault = exportDeclaration.isExportDefaultDeclaration();
var declaration = exportDeclaration.get("declaration");
var isClassDeclaration = declaration.isClassDeclaration();
2023-12-18 13:12:25 +08:00
if (isDefault) {
2024-01-16 21:26:16 +08:00
var standaloneDeclaration = declaration.isFunctionDeclaration() || isClassDeclaration;
var scope = declaration.isScope() ? declaration.scope.parent : declaration.scope;
var id = declaration.node.id;
var needBindingRegistration = false;
2023-12-18 13:12:25 +08:00
if (!id) {
needBindingRegistration = true;
id = scope.generateUidIdentifier("default");
if (standaloneDeclaration || declaration.isFunctionExpression() || declaration.isClassExpression()) {
declaration.node.id = t().cloneNode(id);
}
}
2024-01-16 21:26:16 +08:00
var updatedDeclaration = standaloneDeclaration ? declaration : t().variableDeclaration("var", [t().variableDeclarator(t().cloneNode(id), declaration.node)]);
var updatedExportDeclaration = t().exportNamedDeclaration(null, [t().exportSpecifier(t().cloneNode(id), t().identifier("default"))]);
2023-12-18 13:12:25 +08:00
exportDeclaration.insertAfter(updatedExportDeclaration);
exportDeclaration.replaceWith(updatedDeclaration);
if (needBindingRegistration) {
2024-01-16 21:26:16 +08:00
scope.registerBinding(isClassDeclaration ? "let" : "var", exportDeclaration);
2023-12-18 13:12:25 +08:00
}
return exportDeclaration;
}
if (exportDeclaration.get("specifiers").length > 0) {
throw new Error("It doesn't make sense to split exported specifiers.");
}
2024-01-16 21:26:16 +08:00
var bindingIdentifiers = declaration.getOuterBindingIdentifiers();
var specifiers = Object.keys(bindingIdentifiers).map(function (name) {
2023-12-18 13:12:25 +08:00
return t().exportSpecifier(t().identifier(name), t().identifier(name));
});
2024-01-16 21:26:16 +08:00
var aliasDeclar = t().exportNamedDeclaration(null, specifiers);
2023-12-18 13:12:25 +08:00
exportDeclaration.insertAfter(aliasDeclar);
exportDeclaration.replaceWith(declaration.node);
return exportDeclaration;
}