@babel/plugin-transform-modules-commonjs
Advanced tools
Comparing version 7.0.0-beta.43 to 7.0.0-beta.44
170
lib/index.js
@@ -9,5 +9,5 @@ "use strict"; | ||
function _helperPluginUtils() { | ||
const data = require("@babel/helper-plugin-utils"); | ||
var data = require("@babel/helper-plugin-utils"); | ||
_helperPluginUtils = function () { | ||
_helperPluginUtils = function _helperPluginUtils() { | ||
return data; | ||
@@ -20,5 +20,5 @@ }; | ||
function _helperModuleTransforms() { | ||
const data = require("@babel/helper-module-transforms"); | ||
var data = require("@babel/helper-module-transforms"); | ||
_helperModuleTransforms = function () { | ||
_helperModuleTransforms = function _helperModuleTransforms() { | ||
return data; | ||
@@ -31,5 +31,5 @@ }; | ||
function _helperSimpleAccess() { | ||
const data = _interopRequireDefault(require("@babel/helper-simple-access")); | ||
var data = _interopRequireDefault(require("@babel/helper-simple-access")); | ||
_helperSimpleAccess = function () { | ||
_helperSimpleAccess = function _helperSimpleAccess() { | ||
return data; | ||
@@ -42,5 +42,5 @@ }; | ||
function _core() { | ||
const data = require("@babel/core"); | ||
var data = require("@babel/core"); | ||
_core = function () { | ||
_core = function _core() { | ||
return data; | ||
@@ -52,45 +52,50 @@ }; | ||
var _templateObject = _taggedTemplateLiteralLoose(["\n (function(){\n throw new Error(\n \"The CommonJS '\" + \"", "\" + \"' variable is not available in ES6 modules.\" +\n \"Consider setting setting sourceType:script or sourceType:unambiguous in your \" +\n \"Babel config for this file.\");\n })()\n "]), | ||
_templateObject2 = _taggedTemplateLiteralLoose(["\n function ", "() {\n const data = ", ";\n ", " = function(){ return data; };\n return data;\n }\n "]), | ||
_templateObject3 = _taggedTemplateLiteralLoose(["\n var ", " = ", ";\n "]); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _default = (0, _helperPluginUtils().declare)((api, options) => { | ||
function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; } | ||
var _default = (0, _helperPluginUtils().declare)(function (api, options) { | ||
api.assertVersion(7); | ||
const { | ||
loose, | ||
strictNamespace = false, | ||
mjsStrictNamespace = true, | ||
allowTopLevelThis, | ||
strict, | ||
strictMode, | ||
noInterop, | ||
lazy = false, | ||
allowCommonJSExports = true | ||
} = options; | ||
var loose = options.loose, | ||
_options$strictNamesp = options.strictNamespace, | ||
strictNamespace = _options$strictNamesp === void 0 ? false : _options$strictNamesp, | ||
_options$mjsStrictNam = options.mjsStrictNamespace, | ||
mjsStrictNamespace = _options$mjsStrictNam === void 0 ? true : _options$mjsStrictNam, | ||
allowTopLevelThis = options.allowTopLevelThis, | ||
strict = options.strict, | ||
strictMode = options.strictMode, | ||
noInterop = options.noInterop, | ||
_options$lazy = options.lazy, | ||
lazy = _options$lazy === void 0 ? false : _options$lazy, | ||
_options$allowCommonJ = options.allowCommonJSExports, | ||
allowCommonJSExports = _options$allowCommonJ === void 0 ? true : _options$allowCommonJ; | ||
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 lazy !== "boolean" && typeof lazy !== "function" && (!Array.isArray(lazy) || !lazy.every(function (item) { | ||
return 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`); | ||
throw new Error(".strictNamespace must be a boolean, or undefined"); | ||
} | ||
if (typeof mjsStrictNamespace !== "boolean") { | ||
throw new Error(`.mjsStrictNamespace must be a boolean, or undefined`); | ||
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."); | ||
})() | ||
`; | ||
var getAssertion = function getAssertion(localName) { | ||
return _core().template.expression.ast(_templateObject, localName); | ||
}; | ||
const moduleExportsVisitor = { | ||
ReferencedIdentifier(path) { | ||
const localName = path.node.name; | ||
var moduleExportsVisitor = { | ||
ReferencedIdentifier: function ReferencedIdentifier(path) { | ||
var localName = path.node.name; | ||
if (localName !== "module" && localName !== "exports") return; | ||
const localBinding = path.scope.getBinding(localName); | ||
const rootBinding = this.scope.getBinding(localName); | ||
var localBinding = path.scope.getBinding(localName); | ||
var rootBinding = this.scope.getBinding(localName); | ||
@@ -109,28 +114,29 @@ if (rootBinding !== localBinding || path.parentPath.isObjectProperty({ | ||
}, | ||
AssignmentExpression: function AssignmentExpression(path) { | ||
var _this = this; | ||
AssignmentExpression(path) { | ||
const left = path.get("left"); | ||
var left = path.get("left"); | ||
if (left.isIdentifier()) { | ||
const localName = path.node.name; | ||
var localName = path.node.name; | ||
if (localName !== "module" && localName !== "exports") return; | ||
const localBinding = path.scope.getBinding(localName); | ||
const rootBinding = this.scope.getBinding(localName); | ||
var localBinding = path.scope.getBinding(localName); | ||
var rootBinding = this.scope.getBinding(localName); | ||
if (rootBinding !== localBinding) return; | ||
const right = path.get("right"); | ||
var right = path.get("right"); | ||
right.replaceWith(_core().types.sequenceExpression([right.node, getAssertion(localName)])); | ||
} else if (left.isPattern()) { | ||
const ids = left.getOuterBindingIdentifiers(); | ||
const localName = Object.keys(ids).filter(localName => { | ||
var ids = left.getOuterBindingIdentifiers(); | ||
var _localName = Object.keys(ids).filter(function (localName) { | ||
if (localName !== "module" && localName !== "exports") return false; | ||
return this.scope.getBinding(localName) === path.scope.getBinding(localName); | ||
return _this.scope.getBinding(localName) === path.scope.getBinding(localName); | ||
})[0]; | ||
if (localName) { | ||
const right = path.get("right"); | ||
right.replaceWith(_core().types.sequenceExpression([right.node, getAssertion(localName)])); | ||
if (_localName) { | ||
var _right = path.get("right"); | ||
_right.replaceWith(_core().types.sequenceExpression([_right.node, getAssertion(_localName)])); | ||
} | ||
} | ||
} | ||
}; | ||
@@ -140,3 +146,3 @@ return { | ||
Program: { | ||
exit(path, state) { | ||
exit: function exit(path, state) { | ||
if (!(0, _helperModuleTransforms().isModule)(path)) return; | ||
@@ -156,23 +162,38 @@ path.scope.rename("exports"); | ||
let moduleName = this.getModuleName(); | ||
var moduleName = this.getModuleName(); | ||
if (moduleName) moduleName = _core().types.stringLiteral(moduleName); | ||
const { | ||
meta, | ||
headers | ||
} = (0, _helperModuleTransforms().rewriteModuleStatementsAndPrepareHeader)(path, { | ||
var _rewriteModuleStateme = (0, _helperModuleTransforms().rewriteModuleStatementsAndPrepareHeader)(path, { | ||
exportName: "exports", | ||
loose, | ||
strict, | ||
strictMode, | ||
allowTopLevelThis, | ||
noInterop, | ||
lazy, | ||
loose: loose, | ||
strict: strict, | ||
strictMode: strictMode, | ||
allowTopLevelThis: allowTopLevelThis, | ||
noInterop: noInterop, | ||
lazy: lazy, | ||
esNamespaceOnly: typeof state.filename === "string" && /\.mjs$/.test(state.filename) ? mjsStrictNamespace : strictNamespace | ||
}); | ||
}), | ||
meta = _rewriteModuleStateme.meta, | ||
headers = _rewriteModuleStateme.headers; | ||
for (const [source, metadata] of meta.source) { | ||
const loadExpr = _core().types.callExpression(_core().types.identifier("require"), [_core().types.stringLiteral(source)]); | ||
for (var _iterator = meta.source, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
let header; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var _ref2 = _ref, | ||
source = _ref2[0], | ||
metadata = _ref2[1]; | ||
var loadExpr = _core().types.callExpression(_core().types.identifier("require"), [_core().types.stringLiteral(source)]); | ||
var header = void 0; | ||
if ((0, _helperModuleTransforms().isSideEffectImport)(metadata)) { | ||
@@ -182,16 +203,8 @@ if (metadata.lazy) throw new Error("Assertion failure"); | ||
} else { | ||
const init = (0, _helperModuleTransforms().wrapInterop)(path, loadExpr, metadata.interop) || loadExpr; | ||
var init = (0, _helperModuleTransforms().wrapInterop)(path, loadExpr, metadata.interop) || loadExpr; | ||
if (metadata.lazy) { | ||
header = _core().template.ast` | ||
function ${metadata.name}() { | ||
const data = ${init}; | ||
${metadata.name} = function(){ return data; }; | ||
return data; | ||
} | ||
`; | ||
header = _core().template.ast(_templateObject2, metadata.name, init, metadata.name); | ||
} else { | ||
header = _core().template.ast` | ||
var ${metadata.name} = ${init}; | ||
`; | ||
header = _core().template.ast(_templateObject3, metadata.name, init); | ||
} | ||
@@ -202,3 +215,3 @@ } | ||
headers.push(header); | ||
headers.push(...(0, _helperModuleTransforms().buildNamespaceInitStatements)(meta, metadata, loose)); | ||
headers.push.apply(headers, (0, _helperModuleTransforms().buildNamespaceInitStatements)(meta, metadata, loose)); | ||
} | ||
@@ -209,3 +222,2 @@ | ||
} | ||
} | ||
@@ -212,0 +224,0 @@ } |
{ | ||
"name": "@babel/plugin-transform-modules-commonjs", | ||
"version": "7.0.0-beta.43", | ||
"version": "7.0.0-beta.44", | ||
"description": "This plugin transforms ES2015 modules to CommonJS", | ||
@@ -9,5 +9,5 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-modules-commonjs", | ||
"dependencies": { | ||
"@babel/helper-module-transforms": "7.0.0-beta.43", | ||
"@babel/helper-plugin-utils": "7.0.0-beta.43", | ||
"@babel/helper-simple-access": "7.0.0-beta.43" | ||
"@babel/helper-module-transforms": "7.0.0-beta.44", | ||
"@babel/helper-plugin-utils": "7.0.0-beta.44", | ||
"@babel/helper-simple-access": "7.0.0-beta.44" | ||
}, | ||
@@ -18,9 +18,9 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@babel/core": "7.0.0-beta.43" | ||
"@babel/core": "7.0.0-beta.44" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.43", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.43", | ||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.43" | ||
"@babel/core": "7.0.0-beta.44", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.44", | ||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.44" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12911
176
0
+ Added@babel/code-frame@7.0.0-beta.44(transitive)
+ Added@babel/core@7.0.0-beta.44(transitive)
+ Added@babel/generator@7.0.0-beta.44(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.44(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.44(transitive)
+ Added@babel/helper-module-imports@7.0.0-beta.44(transitive)
+ Added@babel/helper-module-transforms@7.0.0-beta.44(transitive)
+ Added@babel/helper-plugin-utils@7.0.0-beta.44(transitive)
+ Added@babel/helper-simple-access@7.0.0-beta.44(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.44(transitive)
+ Added@babel/helpers@7.0.0-beta.44(transitive)
+ Added@babel/highlight@7.0.0-beta.44(transitive)
+ Added@babel/template@7.0.0-beta.44(transitive)
+ Added@babel/traverse@7.0.0-beta.44(transitive)
+ Added@babel/types@7.0.0-beta.44(transitive)
+ Addedbabylon@7.0.0-beta.44(transitive)
- Removed@babel/code-frame@7.0.0-beta.43(transitive)
- Removed@babel/core@7.0.0-beta.43(transitive)
- Removed@babel/generator@7.0.0-beta.43(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.43(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.43(transitive)
- Removed@babel/helper-module-imports@7.0.0-beta.43(transitive)
- Removed@babel/helper-module-transforms@7.0.0-beta.43(transitive)
- Removed@babel/helper-plugin-utils@7.0.0-beta.43(transitive)
- Removed@babel/helper-simple-access@7.0.0-beta.43(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.43(transitive)
- Removed@babel/helpers@7.0.0-beta.43(transitive)
- Removed@babel/highlight@7.0.0-beta.43(transitive)
- Removed@babel/template@7.0.0-beta.43(transitive)
- Removed@babel/traverse@7.0.0-beta.43(transitive)
- Removed@babel/types@7.0.0-beta.43(transitive)
- Removedbabylon@7.0.0-beta.43(transitive)