12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- Object.defineProperty(exports, "defineCommonJSHook", {
- enumerable: true,
- get: function () {
- return _hooks.defineCommonJSHook;
- }
- });
- var _helperPluginUtils = require("@babel/helper-plugin-utils");
- var _helperModuleTransforms = require("@babel/helper-module-transforms");
- var _core = require("@babel/core");
- var _dynamicImport = require("./dynamic-import.js");
- var _lazy = require("./lazy.js");
- var _hooks = require("./hooks.js");
- var _default = exports.default = (0, _helperPluginUtils.declare)((api, options) => {
- var _api$assumption, _api$assumption2, _api$assumption3;
- api.assertVersion(7);
- const {
- strictNamespace = false,
- mjsStrictNamespace = strictNamespace,
- allowTopLevelThis,
- strict,
- strictMode,
- noInterop,
- importInterop,
- lazy = false,
- allowCommonJSExports = true,
- loose = false
- } = options;
- const constantReexports = (_api$assumption = api.assumption("constantReexports")) != null ? _api$assumption : loose;
- const enumerableModuleMeta = (_api$assumption2 = api.assumption("enumerableModuleMeta")) != null ? _api$assumption2 : loose;
- const noIncompleteNsImportDetection = (_api$assumption3 = api.assumption("noIncompleteNsImportDetection")) != null ? _api$assumption3 : false;
- if (typeof lazy !== "boolean" && typeof lazy !== "function" && (!Array.isArray(lazy) || !lazy.every(item => typeof item === "string"))) {
- throw new Error(`.lazy must be a boolean, array of strings, or a function`);
- }
- if (typeof strictNamespace !== "boolean") {
- throw new Error(`.strictNamespace must be a boolean, or undefined`);
- }
- if (typeof mjsStrictNamespace !== "boolean") {
- throw new Error(`.mjsStrictNamespace must be a boolean, or undefined`);
- }
- const getAssertion = localName => _core.template.expression.ast`
- (function(){
- throw new Error(
- "The CommonJS '" + "${localName}" + "' variable is not available in ES6 modules." +
- "Consider setting setting sourceType:script or sourceType:unambiguous in your " +
- "Babel config for this file.");
- })()
- `;
- const moduleExportsVisitor = {
- ReferencedIdentifier(path) {
- const localName = path.node.name;
- if (localName !== "module" && localName !== "exports") return;
- const localBinding = path.scope.getBinding(localName);
- const rootBinding = this.scope.getBinding(localName);
- if (rootBinding !== localBinding || path.parentPath.isObjectProperty({
- value
|