aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@babel/helper-split-export-declaration/lib
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/@babel/helper-split-export-declaration/lib
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/@babel/helper-split-export-declaration/lib')
-rw-r--r--node_modules/@babel/helper-split-export-declaration/lib/index.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/node_modules/@babel/helper-split-export-declaration/lib/index.js b/node_modules/@babel/helper-split-export-declaration/lib/index.js
new file mode 100644
index 00000000..8cffb19b
--- /dev/null
+++ b/node_modules/@babel/helper-split-export-declaration/lib/index.js
@@ -0,0 +1,68 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = splitExportDeclaration;
+
+function t() {
+ const data = _interopRequireWildcard(require("@babel/types"));
+
+ t = function t() {
+ 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.");
+ }
+
+ const isDefault = exportDeclaration.isExportDefaultDeclaration();
+ const declaration = exportDeclaration.get("declaration");
+ const isClassDeclaration = declaration.isClassDeclaration();
+
+ if (isDefault) {
+ const standaloneDeclaration = declaration.isFunctionDeclaration() || isClassDeclaration;
+ const scope = declaration.isScope() ? declaration.scope.parent : declaration.scope;
+ let id = declaration.node.id;
+ let needBindingRegistration = false;
+
+ if (!id) {
+ needBindingRegistration = true;
+ id = scope.generateUidIdentifier("default");
+
+ if (standaloneDeclaration || declaration.isFunctionExpression() || declaration.isClassExpression()) {
+ declaration.node.id = t().cloneNode(id);
+ }
+ }
+
+ const updatedDeclaration = standaloneDeclaration ? declaration : t().variableDeclaration("var", [t().variableDeclarator(t().cloneNode(id), declaration.node)]);
+ const updatedExportDeclaration = t().exportNamedDeclaration(null, [t().exportSpecifier(t().cloneNode(id), t().identifier("default"))]);
+ exportDeclaration.insertAfter(updatedExportDeclaration);
+ exportDeclaration.replaceWith(updatedDeclaration);
+
+ if (needBindingRegistration) {
+ scope.registerBinding(isClassDeclaration ? "let" : "var", exportDeclaration);
+ }
+
+ return exportDeclaration;
+ }
+
+ if (exportDeclaration.get("specifiers").length > 0) {
+ throw new Error("It doesn't make sense to split exported specifiers.");
+ }
+
+ const bindingIdentifiers = declaration.getOuterBindingIdentifiers();
+ const specifiers = Object.keys(bindingIdentifiers).map(name => {
+ return t().exportSpecifier(t().identifier(name), t().identifier(name));
+ });
+ const aliasDeclar = t().exportNamedDeclaration(null, specifiers);
+ exportDeclaration.insertAfter(aliasDeclar);
+ exportDeclaration.replaceWith(declaration.node);
+ return exportDeclaration;
+} \ No newline at end of file