aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@babel/helper-module-transforms/lib
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@babel/helper-module-transforms/lib')
-rw-r--r--node_modules/@babel/helper-module-transforms/lib/index.js466
-rw-r--r--node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata.js421
-rw-r--r--node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js327
-rw-r--r--node_modules/@babel/helper-module-transforms/lib/rewrite-this.js25
4 files changed, 0 insertions, 1239 deletions
diff --git a/node_modules/@babel/helper-module-transforms/lib/index.js b/node_modules/@babel/helper-module-transforms/lib/index.js
deleted file mode 100644
index 996f8b9d..00000000
--- a/node_modules/@babel/helper-module-transforms/lib/index.js
+++ /dev/null
@@ -1,466 +0,0 @@
-"use strict";
-
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.rewriteModuleStatementsAndPrepareHeader = rewriteModuleStatementsAndPrepareHeader;
-exports.ensureStatementsHoisted = ensureStatementsHoisted;
-exports.wrapInterop = wrapInterop;
-exports.buildNamespaceInitStatements = buildNamespaceInitStatements;
-Object.defineProperty(exports, "isModule", {
- enumerable: true,
- get: function get() {
- return _helperModuleImports().isModule;
- }
-});
-Object.defineProperty(exports, "hasExports", {
- enumerable: true,
- get: function get() {
- return _normalizeAndLoadMetadata.hasExports;
- }
-});
-Object.defineProperty(exports, "isSideEffectImport", {
- enumerable: true,
- get: function get() {
- return _normalizeAndLoadMetadata.isSideEffectImport;
- }
-});
-
-function _assert() {
- const data = _interopRequireDefault(require("assert"));
-
- _assert = function _assert() {
- return data;
- };
-
- return data;
-}
-
-function t() {
- const data = _interopRequireWildcard(require("@babel/types"));
-
- t = function t() {
- return data;
- };
-
- return data;
-}
-
-function _template() {
- const data = _interopRequireDefault(require("@babel/template"));
-
- _template = function _template() {
- return data;
- };
-
- return data;
-}
-
-function _chunk() {
- const data = _interopRequireDefault(require("lodash/chunk"));
-
- _chunk = function _chunk() {
- return data;
- };
-
- return data;
-}
-
-function _helperModuleImports() {
- const data = require("@babel/helper-module-imports");
-
- _helperModuleImports = function _helperModuleImports() {
- return data;
- };
-
- return data;
-}
-
-var _rewriteThis = _interopRequireDefault(require("./rewrite-this"));
-
-var _rewriteLiveReferences = _interopRequireDefault(require("./rewrite-live-references"));
-
-var _normalizeAndLoadMetadata = _interopRequireWildcard(require("./normalize-and-load-metadata"));
-
-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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
-function rewriteModuleStatementsAndPrepareHeader(path, {
- exportName,
- strict,
- allowTopLevelThis,
- strictMode,
- loose,
- noInterop,
- lazy,
- esNamespaceOnly
-}) {
- (0, _assert().default)((0, _helperModuleImports().isModule)(path), "Cannot process module statements in a script");
- path.node.sourceType = "script";
- const meta = (0, _normalizeAndLoadMetadata.default)(path, exportName, {
- noInterop,
- loose,
- lazy,
- esNamespaceOnly
- });
-
- if (!allowTopLevelThis) {
- (0, _rewriteThis.default)(path);
- }
-
- (0, _rewriteLiveReferences.default)(path, meta);
-
- if (strictMode !== false) {
- const hasStrict = path.node.directives.some(directive => {
- return directive.value.value === "use strict";
- });
-
- if (!hasStrict) {
- path.unshiftContainer("directives", t().directive(t().directiveLiteral("use strict")));
- }
- }
-
- const headers = [];
-
- if ((0, _normalizeAndLoadMetadata.hasExports)(meta) && !strict) {
- headers.push(buildESModuleHeader(meta, loose));
- }
-
- const nameList = buildExportNameListDeclaration(path, meta);
-
- if (nameList) {
- meta.exportNameListName = nameList.name;
- headers.push(nameList.statement);
- }
-
- headers.push(...buildExportInitializationStatements(path, meta, loose));
- return {
- meta,
- headers
- };
-}
-
-function ensureStatementsHoisted(statements) {
- statements.forEach(header => {
- header._blockHoist = 3;
- });
-}
-
-function wrapInterop(programPath, expr, type) {
- if (type === "none") {
- return null;
- }
-
- let helper;
-
- if (type === "default") {
- helper = "interopRequireDefault";
- } else if (type === "namespace") {
- helper = "interopRequireWildcard";
- } else {
- throw new Error(`Unknown interop: ${type}`);
- }
-
- return t().callExpression(programPath.hub.file.addHelper(helper), [expr]);
-}
-
-function buildNamespaceInitStatements(metadata, sourceMetadata, loose = false) {
- const statements = [];
- let srcNamespace = t().identifier(sourceMetadata.name);
- if (sourceMetadata.lazy) srcNamespace = t().callExpression(srcNamespace, []);
-
- for (var _iterator = sourceMetadata.importsNamespace, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
- var _ref;
-
- if (_isArray) {
- if (_i >= _iterator.length) break;
- _ref = _iterator[_i++];
- } else {
- _i = _iterator.next();
- if (_i.done) break;
- _ref = _i.value;
- }
-
- const localName = _ref;
- if (localName === sourceMetadata.name) continue;
- statements.push(_template().default.statement`var NAME = SOURCE;`({
- NAME: localName,
- SOURCE: t().cloneNode(srcNamespace)
- }));
- }
-
- if (loose) {
- statements.push(...buildReexportsFromMeta(metadata, sourceMetadata, loose));
- }
-
- for (var _iterator2 = sourceMetadata.reexportNamespace, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
- var _ref2;
-
- if (_isArray2) {
- if (_i2 >= _iterator2.length) break;
- _ref2 = _iterator2[_i2++];
- } else {
- _i2 = _iterator2.next();
- if (_i2.done) break;
- _ref2 = _i2.value;
- }
-
- const exportName = _ref2;
- statements.push((sourceMetadata.lazy ? _template().default.statement`
- Object.defineProperty(EXPORTS, "NAME", {
- enumerable: true,
- get: function() {
- return NAMESPACE;
- }
- });
- ` : _template().default.statement`EXPORTS.NAME = NAMESPACE;`)({
- EXPORTS: metadata.exportName,
- NAME: exportName,
- NAMESPACE: t().cloneNode(srcNamespace)
- }));
- }
-
- if (sourceMetadata.reexportAll) {
- const statement = buildNamespaceReexport(metadata, t().cloneNode(srcNamespace), loose);
- statement.loc = sourceMetadata.reexportAll.loc;
- statements.push(statement);
- }
-
- return statements;
-}
-
-const getTemplateForReexport = loose => {
- return loose ? _template().default.statement`EXPORTS.EXPORT_NAME = NAMESPACE.IMPORT_NAME;` : _template().default`
- Object.defineProperty(EXPORTS, "EXPORT_NAME", {
- enumerable: true,
- get: function() {
- return NAMESPACE.IMPORT_NAME;
- },
- });
- `;
-};
-
-const buildReexportsFromMeta = (meta, metadata, loose) => {
- const namespace = metadata.lazy ? t().callExpression(t().identifier(metadata.name), []) : t().identifier(metadata.name);
- const templateForCurrentMode = getTemplateForReexport(loose);
- return Array.from(metadata.reexports, ([exportName, importName]) => templateForCurrentMode({
- EXPORTS: meta.exportName,
- EXPORT_NAME: exportName,
- NAMESPACE: t().cloneNode(namespace),
- IMPORT_NAME: importName
- }));
-};
-
-function buildESModuleHeader(metadata, enumerable = false) {
- return (enumerable ? _template().default.statement`
- EXPORTS.__esModule = true;
- ` : _template().default.statement`
- Object.defineProperty(EXPORTS, "__esModule", {
- value: true,
- });
- `)({
- EXPORTS: metadata.exportName
- });
-}
-
-function buildNamespaceReexport(metadata, namespace, loose) {
- return (loose ? _template().default.statement`
- Object.keys(NAMESPACE).forEach(function(key) {
- if (key === "default" || key === "__esModule") return;
- VERIFY_NAME_LIST;
-
- EXPORTS[key] = NAMESPACE[key];
- });
- ` : _template().default.statement`
- Object.keys(NAMESPACE).forEach(function(key) {
- if (key === "default" || key === "__esModule") return;
- VERIFY_NAME_LIST;
-
- Object.defineProperty(EXPORTS, key, {
- enumerable: true,
- get: function() {
- return NAMESPACE[key];
- },
- });
- });
- `)({
- NAMESPACE: namespace,
- EXPORTS: metadata.exportName,
- VERIFY_NAME_LIST: metadata.exportNameListName ? _template().default`
- if (Object.prototype.hasOwnProperty.call(EXPORTS_LIST, key)) return;
- `({
- EXPORTS_LIST: metadata.exportNameListName
- }) : null
- });
-}
-
-function buildExportNameListDeclaration(programPath, metadata) {
- const exportedVars = Object.create(null);
-
- for (var _iterator3 = metadata.local.values(), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
- var _ref3;
-
- if (_isArray3) {
- if (_i3 >= _iterator3.length) break;
- _ref3 = _iterator3[_i3++];
- } else {
- _i3 = _iterator3.next();
- if (_i3.done) break;
- _ref3 = _i3.value;
- }
-
- const data = _ref3;
-
- for (var _iterator5 = data.names, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
- var _ref5;
-
- if (_isArray5) {
- if (_i5 >= _iterator5.length) break;
- _ref5 = _iterator5[_i5++];
- } else {
- _i5 = _iterator5.next();
- if (_i5.done) break;
- _ref5 = _i5.value;
- }
-
- const name = _ref5;
- exportedVars[name] = true;
- }
- }
-
- let hasReexport = false;
-
- for (var _iterator4 = metadata.source.values(), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
- var _ref4;
-
- if (_isArray4) {
- if (_i4 >= _iterator4.length) break;
- _ref4 = _iterator4[_i4++];
- } else {
- _i4 = _iterator4.next();
- if (_i4.done) break;
- _ref4 = _i4.value;
- }
-
- const data = _ref4;
-
- for (var _iterator6 = data.reexports.keys(), _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
- var _ref6;
-
- if (_isArray6) {
- if (_i6 >= _iterator6.length) break;
- _ref6 = _iterator6[_i6++];
- } else {
- _i6 = _iterator6.next();
- if (_i6.done) break;
- _ref6 = _i6.value;
- }
-
- const exportName = _ref6;
- exportedVars[exportName] = true;
- }
-
- for (var _iterator7 = data.reexportNamespace, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
- var _ref7;
-
- if (_isArray7) {
- if (_i7 >= _iterator7.length) break;
- _ref7 = _iterator7[_i7++];
- } else {
- _i7 = _iterator7.next();
- if (_i7.done) break;
- _ref7 = _i7.value;
- }
-
- const exportName = _ref7;
- exportedVars[exportName] = true;
- }
-
- hasReexport = hasReexport || data.reexportAll;
- }
-
- if (!hasReexport || Object.keys(exportedVars).length === 0) return null;
- const name = programPath.scope.generateUidIdentifier("exportNames");
- delete exportedVars.default;
- return {
- name: name.name,
- statement: t().variableDeclaration("var", [t().variableDeclarator(name, t().valueToNode(exportedVars))])
- };
-}
-
-function buildExportInitializationStatements(programPath, metadata, loose = false) {
- const initStatements = [];
- const exportNames = [];
-
- for (var _iterator8 = metadata.local, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
- var _ref8;
-
- if (_isArray8) {
- if (_i8 >= _iterator8.length) break;
- _ref8 = _iterator8[_i8++];
- } else {
- _i8 = _iterator8.next();
- if (_i8.done) break;
- _ref8 = _i8.value;
- }
-
- const _ref10 = _ref8,
- localName = _ref10[0],
- data = _ref10[1];
-
- if (data.kind === "import") {} else if (data.kind === "hoisted") {
- initStatements.push(buildInitStatement(metadata, data.names, t().identifier(localName)));
- } else {
- exportNames.push(...data.names);
- }
- }
-
- for (var _iterator9 = metadata.source.values(), _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
- var _ref9;
-
- if (_isArray9) {
- if (_i9 >= _iterator9.length) break;
- _ref9 = _iterator9[_i9++];
- } else {
- _i9 = _iterator9.next();
- if (_i9.done) break;
- _ref9 = _i9.value;
- }
-
- const data = _ref9;
-
- if (!loose) {
- initStatements.push(...buildReexportsFromMeta(metadata, data, loose));
- }
-
- for (var _iterator10 = data.reexportNamespace, _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) {
- var _ref11;
-
- if (_isArray10) {
- if (_i10 >= _iterator10.length) break;
- _ref11 = _iterator10[_i10++];
- } else {
- _i10 = _iterator10.next();
- if (_i10.done) break;
- _ref11 = _i10.value;
- }
-
- const exportName = _ref11;
- exportNames.push(exportName);
- }
- }
-
- initStatements.push(...(0, _chunk().default)(exportNames, 100).map(members => {
- return buildInitStatement(metadata, members, programPath.scope.buildUndefinedNode());
- }));
- return initStatements;
-}
-
-function buildInitStatement(metadata, exportNames, initExpr) {
- return t().expressionStatement(exportNames.reduce((acc, exportName) => _template().default.expression`EXPORTS.NAME = VALUE`({
- EXPORTS: metadata.exportName,
- NAME: exportName,
- VALUE: acc
- }), initExpr));
-} \ No newline at end of file
diff --git a/node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata.js b/node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata.js
deleted file mode 100644
index 425f75df..00000000
--- a/node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata.js
+++ /dev/null
@@ -1,421 +0,0 @@
-"use strict";
-
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.hasExports = hasExports;
-exports.isSideEffectImport = isSideEffectImport;
-exports.default = normalizeModuleAndLoadMetadata;
-
-function _path() {
- const data = require("path");
-
- _path = function _path() {
- return data;
- };
-
- return data;
-}
-
-function _helperSplitExportDeclaration() {
- const data = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
-
- _helperSplitExportDeclaration = function _helperSplitExportDeclaration() {
- return data;
- };
-
- return data;
-}
-
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
-function hasExports(metadata) {
- const local = metadata.local,
- source = metadata.source;
- return local.size > 0 || Array.from(source).some(([, meta]) => {
- return meta.reexports.size > 0 || meta.reexportNamespace.size > 0 || !!meta.reexportAll;
- });
-}
-
-function isSideEffectImport(source) {
- return source.imports.size === 0 && source.importsNamespace.size === 0 && source.reexports.size === 0 && source.reexportNamespace.size === 0 && !source.reexportAll;
-}
-
-function normalizeModuleAndLoadMetadata(programPath, exportName, {
- noInterop = false,
- loose = false,
- lazy = false,
- esNamespaceOnly = false
-} = {}) {
- if (!exportName) {
- exportName = programPath.scope.generateUidIdentifier("exports").name;
- }
-
- nameAnonymousExports(programPath);
-
- const _getModuleMetadata = getModuleMetadata(programPath, {
- loose,
- lazy
- }),
- local = _getModuleMetadata.local,
- source = _getModuleMetadata.source;
-
- removeModuleDeclarations(programPath);
-
- for (var _iterator = source, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
- var _ref;
-
- if (_isArray) {
- if (_i >= _iterator.length) break;
- _ref = _iterator[_i++];
- } else {
- _i = _iterator.next();
- if (_i.done) break;
- _ref = _i.value;
- }
-
- const _ref2 = _ref,
- metadata = _ref2[1];
-
- if (metadata.importsNamespace.size > 0) {
- metadata.name = metadata.importsNamespace.values().next().value;
- }
-
- if (noInterop) metadata.interop = "none";else if (esNamespaceOnly) {
- if (metadata.interop === "namespace") {
- metadata.interop = "default";
- }
- }
- }
-
- return {
- exportName,
- exportNameListName: null,
- local,
- source
- };
-}
-
-function getModuleMetadata(programPath, {
- loose,
- lazy
-}) {
- const localData = getLocalExportMetadata(programPath, loose);
- const sourceData = new Map();
-
- const getData = sourceNode => {
- const source = sourceNode.value;
- let data = sourceData.get(source);
-
- if (!data) {
- data = {
- name: programPath.scope.generateUidIdentifier((0, _path().basename)(source, (0, _path().extname)(source))).name,
- interop: "none",
- loc: null,
- imports: new Map(),
- importsNamespace: new Set(),
- reexports: new Map(),
- reexportNamespace: new Set(),
- reexportAll: null,
- lazy: false
- };
- sourceData.set(source, data);
- }
-
- return data;
- };
-
- programPath.get("body").forEach(child => {
- if (child.isImportDeclaration()) {
- const data = getData(child.node.source);
- if (!data.loc) data.loc = child.node.loc;
- child.get("specifiers").forEach(spec => {
- if (spec.isImportDefaultSpecifier()) {
- const localName = spec.get("local").node.name;
- data.imports.set(localName, "default");
- const reexport = localData.get(localName);
-
- if (reexport) {
- localData.delete(localName);
- reexport.names.forEach(name => {
- data.reexports.set(name, "default");
- });
- }
- } else if (spec.isImportNamespaceSpecifier()) {
- const localName = spec.get("local").node.name;
- data.importsNamespace.add(localName);
- const reexport = localData.get(localName);
-
- if (reexport) {
- localData.delete(localName);
- reexport.names.forEach(name => {
- data.reexportNamespace.add(name);
- });
- }
- } else if (spec.isImportSpecifier()) {
- const importName = spec.get("imported").node.name;
- const localName = spec.get("local").node.name;
- data.imports.set(localName, importName);
- const reexport = localData.get(localName);
-
- if (reexport) {
- localData.delete(localName);
- reexport.names.forEach(name => {
- data.reexports.set(name, importName);
- });
- }
- }
- });
- } else if (child.isExportAllDeclaration()) {
- const data = getData(child.node.source);
- if (!data.loc) data.loc = child.node.loc;
- data.reexportAll = {
- loc: child.node.loc
- };
- } else if (child.isExportNamedDeclaration() && child.node.source) {
- const data = getData(child.node.source);
- if (!data.loc) data.loc = child.node.loc;
- child.get("specifiers").forEach(spec => {
- if (!spec.isExportSpecifier()) {
- throw spec.buildCodeFrameError("Unexpected export specifier type");
- }
-
- const importName = spec.get("local").node.name;
- const exportName = spec.get("exported").node.name;
- data.reexports.set(exportName, importName);
-
- if (exportName === "__esModule") {
- throw exportName.buildCodeFrameError('Illegal export "__esModule".');
- }
- });
- }
- });
-
- for (var _iterator2 = sourceData.values(), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
- var _ref3;
-
- if (_isArray2) {
- if (_i2 >= _iterator2.length) break;
- _ref3 = _iterator2[_i2++];
- } else {
- _i2 = _iterator2.next();
- if (_i2.done) break;
- _ref3 = _i2.value;
- }
-
- const metadata = _ref3;
-
- if (metadata.importsNamespace.size > 0) {
- metadata.interop = "namespace";
- continue;
- }
-
- let needsDefault = false;
- let needsNamed = false;
-
- for (var _iterator4 = metadata.imports.values(), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
- var _ref5;
-
- if (_isArray4) {
- if (_i4 >= _iterator4.length) break;
- _ref5 = _iterator4[_i4++];
- } else {
- _i4 = _iterator4.next();
- if (_i4.done) break;
- _ref5 = _i4.value;
- }
-
- const importName = _ref5;
- if (importName === "default") needsDefault = true;else needsNamed = true;
- }
-
- for (var _iterator5 = metadata.reexports.values(), _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
- var _ref6;
-
- if (_isArray5) {
- if (_i5 >= _iterator5.length) break;
- _ref6 = _iterator5[_i5++];
- } else {
- _i5 = _iterator5.next();
- if (_i5.done) break;
- _ref6 = _i5.value;
- }
-
- const importName = _ref6;
- if (importName === "default") needsDefault = true;else needsNamed = true;
- }
-
- if (needsDefault && needsNamed) {
- metadata.interop = "namespace";
- } else if (needsDefault) {
- metadata.interop = "default";
- }
- }
-
- for (var _iterator3 = sourceData, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
- var _ref4;
-
- if (_isArray3) {
- if (_i3 >= _iterator3.length) break;
- _ref4 = _iterator3[_i3++];
- } else {
- _i3 = _iterator3.next();
- if (_i3.done) break;
- _ref4 = _i3.value;
- }
-
- const _ref7 = _ref4,
- source = _ref7[0],
- metadata = _ref7[1];
-
- if (lazy !== false && !(isSideEffectImport(metadata) || metadata.reexportAll)) {
- if (lazy === true) {
- metadata.lazy = !/\./.test(source);
- } else if (Array.isArray(lazy)) {
- metadata.lazy = lazy.indexOf(source);
- } else if (typeof lazy === "function") {
- metadata.lazy = lazy(source);
- } else {
- throw new Error(`.lazy must be a boolean, string array, or function`);
- }
- }
- }
-
- return {
- local: localData,
- source: sourceData
- };
-}
-
-function getLocalExportMetadata(programPath, loose) {
- const bindingKindLookup = new Map();
- programPath.get("body").forEach(child => {
- let kind;
-
- if (child.isImportDeclaration()) {
- kind = "import";
- } else {
- if (child.isExportDefaultDeclaration()) child = child.get("declaration");
-
- if (child.isExportNamedDeclaration()) {
- if (child.node.declaration) {
- child = child.get("declaration");
- } else if (loose && child.node.source && child.get("source").isStringLiteral()) {
- child.node.specifiers.forEach(specifier => {
- bindingKindLookup.set(specifier.local.name, "block");
- });
- return;
- }
- }
-
- if (child.isFunctionDeclaration()) {
- kind = "hoisted";
- } else if (child.isClassDeclaration()) {
- kind = "block";
- } else if (child.isVariableDeclaration({
- kind: "var"
- })) {
- kind = "var";
- } else if (child.isVariableDeclaration()) {
- kind = "block";
- } else {
- return;
- }
- }
-
- Object.keys(child.getOuterBindingIdentifiers()).forEach(name => {
- bindingKindLookup.set(name, kind);
- });
- });
- const localMetadata = new Map();
-
- const getLocalMetadata = idPath => {
- const localName = idPath.node.name;
- let metadata = localMetadata.get(localName);
-
- if (!metadata) {
- const kind = bindingKindLookup.get(localName);
-
- if (kind === undefined) {
- throw idPath.buildCodeFrameError(`Exporting local "${localName}", which is not declared.`);
- }
-
- metadata = {
- names: [],
- kind
- };
- localMetadata.set(localName, metadata);
- }
-
- return metadata;
- };
-
- programPath.get("body").forEach(child => {
- if (child.isExportNamedDeclaration() && (loose || !child.node.source)) {
- if (child.node.declaration) {
- const declaration = child.get("declaration");
- const ids = declaration.getOuterBindingIdentifierPaths();
- Object.keys(ids).forEach(name => {
- if (name === "__esModule") {
- throw declaration.buildCodeFrameError('Illegal export "__esModule".');
- }
-
- getLocalMetadata(ids[name]).names.push(name);
- });
- } else {
- child.get("specifiers").forEach(spec => {
- const local = spec.get("local");
- const exported = spec.get("exported");
-
- if (exported.node.name === "__esModule") {
- throw exported.buildCodeFrameError('Illegal export "__esModule".');
- }
-
- getLocalMetadata(local).names.push(exported.node.name);
- });
- }
- } else if (child.isExportDefaultDeclaration()) {
- const declaration = child.get("declaration");
-
- if (declaration.isFunctionDeclaration() || declaration.isClassDeclaration()) {
- getLocalMetadata(declaration.get("id")).names.push("default");
- } else {
- throw declaration.buildCodeFrameError("Unexpected default expression export.");
- }
- }
- });
- return localMetadata;
-}
-
-function nameAnonymousExports(programPath) {
- programPath.get("body").forEach(child => {
- if (!child.isExportDefaultDeclaration()) return;
- (0, _helperSplitExportDeclaration().default)(child);
- });
-}
-
-function removeModuleDeclarations(programPath) {
- programPath.get("body").forEach(child => {
- if (child.isImportDeclaration()) {
- child.remove();
- } else if (child.isExportNamedDeclaration()) {
- if (child.node.declaration) {
- child.node.declaration._blockHoist = child.node._blockHoist;
- child.replaceWith(child.node.declaration);
- } else {
- child.remove();
- }
- } else if (child.isExportDefaultDeclaration()) {
- const declaration = child.get("declaration");
-
- if (declaration.isFunctionDeclaration() || declaration.isClassDeclaration()) {
- declaration._blockHoist = child.node._blockHoist;
- child.replaceWith(declaration);
- } else {
- throw declaration.buildCodeFrameError("Unexpected default expression export.");
- }
- } else if (child.isExportAllDeclaration()) {
- child.remove();
- }
- });
-} \ No newline at end of file
diff --git a/node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js b/node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js
deleted file mode 100644
index 1a02039a..00000000
--- a/node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js
+++ /dev/null
@@ -1,327 +0,0 @@
-"use strict";
-
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.default = rewriteLiveReferences;
-
-function _assert() {
- const data = _interopRequireDefault(require("assert"));
-
- _assert = function _assert() {
- return data;
- };
-
- return data;
-}
-
-function t() {
- const data = _interopRequireWildcard(require("@babel/types"));
-
- t = function t() {
- return data;
- };
-
- return data;
-}
-
-function _template() {
- const data = _interopRequireDefault(require("@babel/template"));
-
- _template = function _template() {
- return data;
- };
-
- return data;
-}
-
-function _helperSimpleAccess() {
- const data = _interopRequireDefault(require("@babel/helper-simple-access"));
-
- _helperSimpleAccess = function _helperSimpleAccess() {
- 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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
-function rewriteLiveReferences(programPath, metadata) {
- const imported = new Map();
- const exported = new Map();
-
- const requeueInParent = path => {
- programPath.requeue(path);
- };
-
- for (var _iterator = metadata.source, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
- var _ref;
-
- if (_isArray) {
- if (_i >= _iterator.length) break;
- _ref = _iterator[_i++];
- } else {
- _i = _iterator.next();
- if (_i.done) break;
- _ref = _i.value;
- }
-
- const _ref3 = _ref,
- source = _ref3[0],
- data = _ref3[1];
-
- for (var _iterator3 = data.imports, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
- var _ref4;
-
- if (_isArray3) {
- if (_i3 >= _iterator3.length) break;
- _ref4 = _iterator3[_i3++];
- } else {
- _i3 = _iterator3.next();
- if (_i3.done) break;
- _ref4 = _i3.value;
- }
-
- const _ref6 = _ref4,
- localName = _ref6[0],
- importName = _ref6[1];
- imported.set(localName, [source, importName, null]);
- }
-
- for (var _iterator4 = data.importsNamespace, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
- var _ref5;
-
- if (_isArray4) {
- if (_i4 >= _iterator4.length) break;
- _ref5 = _iterator4[_i4++];
- } else {
- _i4 = _iterator4.next();
- if (_i4.done) break;
- _ref5 = _i4.value;
- }
-
- const localName = _ref5;
- imported.set(localName, [source, null, localName]);
- }
- }
-
- for (var _iterator2 = metadata.local, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
- var _ref2;
-
- if (_isArray2) {
- if (_i2 >= _iterator2.length) break;
- _ref2 = _iterator2[_i2++];
- } else {
- _i2 = _iterator2.next();
- if (_i2.done) break;
- _ref2 = _i2.value;
- }
-
- const _ref7 = _ref2,
- local = _ref7[0],
- data = _ref7[1];
- let exportMeta = exported.get(local);
-
- if (!exportMeta) {
- exportMeta = [];
- exported.set(local, exportMeta);
- }
-
- exportMeta.push(...data.names);
- }
-
- programPath.traverse(rewriteBindingInitVisitor, {
- metadata,
- requeueInParent,
- scope: programPath.scope,
- exported
- });
- (0, _helperSimpleAccess().default)(programPath, new Set([...Array.from(imported.keys()), ...Array.from(exported.keys())]));
- programPath.traverse(rewriteReferencesVisitor, {
- seen: new WeakSet(),
- metadata,
- requeueInParent,
- scope: programPath.scope,
- imported,
- exported,
- buildImportReference: ([source, importName, localName], identNode) => {
- const meta = metadata.source.get(source);
-
- if (localName) {
- if (meta.lazy) identNode = t().callExpression(identNode, []);
- return identNode;
- }
-
- let namespace = t().identifier(meta.name);
- if (meta.lazy) namespace = t().callExpression(namespace, []);
- return t().memberExpression(namespace, t().identifier(importName));
- }
- });
-}
-
-const rewriteBindingInitVisitor = {
- ClassProperty(path) {
- path.skip();
- },
-
- Function(path) {
- path.skip();
- },
-
- ClassDeclaration(path) {
- const requeueInParent = this.requeueInParent,
- exported = this.exported,
- metadata = this.metadata;
- const id = path.node.id;
- if (!id) throw new Error("Expected class to have a name");
- const localName = id.name;
- const exportNames = exported.get(localName) || [];
-
- if (exportNames.length > 0) {
- const statement = t().expressionStatement(buildBindingExportAssignmentExpression(metadata, exportNames, t().identifier(localName)));
- statement._blockHoist = path.node._blockHoist;
- requeueInParent(path.insertAfter(statement)[0]);
- }
- },
-
- VariableDeclaration(path) {
- const requeueInParent = this.requeueInParent,
- exported = this.exported,
- metadata = this.metadata;
- Object.keys(path.getOuterBindingIdentifiers()).forEach(localName => {
- const exportNames = exported.get(localName) || [];
-
- if (exportNames.length > 0) {
- const statement = t().expressionStatement(buildBindingExportAssignmentExpression(metadata, exportNames, t().identifier(localName)));
- statement._blockHoist = path.node._blockHoist;
- requeueInParent(path.insertAfter(statement)[0]);
- }
- });
- }
-
-};
-
-const buildBindingExportAssignmentExpression = (metadata, exportNames, localExpr) => {
- return (exportNames || []).reduce((expr, exportName) => {
- return t().assignmentExpression("=", t().memberExpression(t().identifier(metadata.exportName), t().identifier(exportName)), expr);
- }, localExpr);
-};
-
-const buildImportThrow = localName => {
- return _template().default.expression.ast`
- (function() {
- throw new Error('"' + '${localName}' + '" is read-only.');
- })()
- `;
-};
-
-const rewriteReferencesVisitor = {
- ReferencedIdentifier(path) {
- const seen = this.seen,
- buildImportReference = this.buildImportReference,
- scope = this.scope,
- imported = this.imported,
- requeueInParent = this.requeueInParent;
- if (seen.has(path.node)) return;
- seen.add(path.node);
- const localName = path.node.name;
- const localBinding = path.scope.getBinding(localName);
- const rootBinding = scope.getBinding(localName);
- if (rootBinding !== localBinding) return;
- const importData = imported.get(localName);
-
- if (importData) {
- const ref = buildImportReference(importData, path.node);
- ref.loc = path.node.loc;
-
- if (path.parentPath.isCallExpression({
- callee: path.node
- }) && t().isMemberExpression(ref)) {
- path.replaceWith(t().sequenceExpression([t().numericLiteral(0), ref]));
- } else if (path.isJSXIdentifier() && t().isMemberExpression(ref)) {
- const object = ref.object,
- property = ref.property;
- path.replaceWith(t().JSXMemberExpression(t().JSXIdentifier(object.name), t().JSXIdentifier(property.name)));
- } else {
- path.replaceWith(ref);
- }
-
- requeueInParent(path);
- path.skip();
- }
- },
-
- AssignmentExpression: {
- exit(path) {
- const scope = this.scope,
- seen = this.seen,
- imported = this.imported,
- exported = this.exported,
- requeueInParent = this.requeueInParent,
- buildImportReference = this.buildImportReference;
- if (seen.has(path.node)) return;
- seen.add(path.node);
- const left = path.get("left");
-
- if (left.isIdentifier()) {
- const localName = left.node.name;
-
- if (scope.getBinding(localName) !== path.scope.getBinding(localName)) {
- return;
- }
-
- const exportedNames = exported.get(localName) || [];
- const importData = imported.get(localName);
-
- if (exportedNames.length > 0 || importData) {
- (0, _assert().default)(path.node.operator === "=", "Path was not simplified");
- const assignment = path.node;
-
- if (importData) {
- assignment.left = buildImportReference(importData, assignment.left);
- assignment.right = t().sequenceExpression([assignment.right, buildImportThrow(localName)]);
- }
-
- path.replaceWith(buildBindingExportAssignmentExpression(this.metadata, exportedNames, assignment));
- requeueInParent(path);
- }
- } else if (left.isMemberExpression()) {} else {
- const ids = left.getOuterBindingIdentifiers();
- const id = Object.keys(ids).filter(localName => imported.has(localName)).pop();
-
- if (id) {
- path.node.right = t().sequenceExpression([path.node.right, buildImportThrow(id)]);
- }
-
- const items = [];
- Object.keys(ids).forEach(localName => {
- if (scope.getBinding(localName) !== path.scope.getBinding(localName)) {
- return;
- }
-
- const exportedNames = exported.get(localName) || [];
-
- if (exportedNames.length > 0) {
- items.push(buildBindingExportAssignmentExpression(this.metadata, exportedNames, t().identifier(localName)));
- }
- });
-
- if (items.length > 0) {
- let node = t().sequenceExpression(items);
-
- if (path.parentPath.isExpressionStatement()) {
- node = t().expressionStatement(node);
- node._blockHoist = path.parentPath.node._blockHoist;
- }
-
- const statement = path.insertAfter(node)[0];
- requeueInParent(statement);
- }
- }
- }
-
- }
-}; \ No newline at end of file
diff --git a/node_modules/@babel/helper-module-transforms/lib/rewrite-this.js b/node_modules/@babel/helper-module-transforms/lib/rewrite-this.js
deleted file mode 100644
index e75cc39a..00000000
--- a/node_modules/@babel/helper-module-transforms/lib/rewrite-this.js
+++ /dev/null
@@ -1,25 +0,0 @@
-"use strict";
-
-Object.defineProperty(exports, "__esModule", {
- value: true
-});
-exports.default = rewriteThis;
-
-function rewriteThis(programPath) {
- programPath.traverse(rewriteThisVisitor);
-}
-
-const rewriteThisVisitor = {
- ThisExpression(path) {
- path.replaceWith(path.scope.buildUndefinedNode());
- },
-
- Function(path) {
- if (!path.isArrowFunctionExpression()) path.skip();
- },
-
- ClassProperty(path) {
- path.skip();
- }
-
-}; \ No newline at end of file