New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-es2015-modules-commonjs

Package Overview
Dependencies
Maintainers
6
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-es2015-modules-commonjs - npm Package Compare versions

Comparing version 7.0.0-beta.2 to 7.0.0-beta.3

93

lib/index.js
"use strict";
exports.__esModule = true;
exports.default = _default;
exports.default = function (_ref) {
var t = _ref.types;
var _babelHelperModuleTransforms = require("babel-helper-module-transforms");
var _babelHelperSimpleAccess = _interopRequireDefault(require("babel-helper-simple-access"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _default(_ref, options) {
var t = _ref.types,
template = _ref.template;
var loose = options.loose,
allowTopLevelThis = options.allowTopLevelThis,
strict = options.strict,
strictMode = options.strictMode,
noInterop = options.noInterop,
_options$allowCommonJ = options.allowCommonJSExports,
allowCommonJSExports = _options$allowCommonJ === void 0 ? true : _options$allowCommonJ;
var moduleAssertion = template("\n (function(){\n throw new Error(\"The CommonJS 'module' variable is not available in ES6 modules.\");\n })();\n ");
var exportsAssertion = template("\n (function(){\n throw new Error(\"The CommonJS 'exports' variable is not available in ES6 modules.\");\n })();\n ");
var getAssertion = function getAssertion(localName) {
return (localName === "module" ? moduleAssertion() : exportsAssertion()).expression;
};
var moduleExportsVisitor = {
ReferencedIdentifier: function ReferencedIdentifier(path) {
var localName = path.node.name;
if (localName !== "module" && localName !== "exports") return;
var localBinding = path.scope.getBinding(localName);
var rootBinding = this.scope.getBinding(localName);
if (rootBinding !== localBinding || path.parentPath.isObjectProperty({
value: path.node
}) && path.parentPath.parentPath.isObjectPattern() || path.parentPath.isAssignmentExpression({
left: path.node
}) || path.isAssignmentExpression({
left: path.node
})) {
return;
}
path.replaceWith(getAssertion(localName));
},
AssignmentExpression: function AssignmentExpression(path) {
var _this = this;
var left = path.get("left");
if (left.isIdentifier()) {
var localName = path.node.name;
if (localName !== "module" && localName !== "exports") return;
var localBinding = path.scope.getBinding(localName);
var rootBinding = this.scope.getBinding(localName);
if (rootBinding !== localBinding) return;
var right = path.get("right");
right.replaceWith(t.sequenceExpression([right.node, getAssertion(localName)]));
} else if (left.isPattern()) {
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);
})[0];
if (_localName) {
var _right = path.get("right");
_right.replaceWith(t.sequenceExpression([_right.node, getAssertion(_localName)]));
}
}
}
};
return {
visitor: {
Program: {
exit: function exit(path, state) {
exit: function exit(path) {
if (!(0, _babelHelperModuleTransforms.isModule)(path, true)) return;
var _state$opts = state.opts,
loose = _state$opts.loose,
allowTopLevelThis = _state$opts.allowTopLevelThis,
strict = _state$opts.strict,
strictMode = _state$opts.strictMode,
noInterop = _state$opts.noInterop;
path.scope.rename("exports");

@@ -23,2 +86,10 @@ path.scope.rename("module");

path.scope.rename("__dirname");
if (!allowCommonJSExports) {
(0, _babelHelperSimpleAccess.default)(path, new Set(["module", "exports"]));
path.traverse(moduleExportsVisitor, {
scope: path.scope
});
}
var moduleName = this.getModuleName();

@@ -73,4 +144,2 @@ if (moduleName) moduleName = t.stringLiteral(moduleName);

};
};
var _babelHelperModuleTransforms = require("babel-helper-module-transforms");
}

12

package.json
{
"name": "babel-plugin-transform-es2015-modules-commonjs",
"version": "7.0.0-beta.2",
"version": "7.0.0-beta.3",
"description": "This plugin transforms ES2015 modules to CommonJS",

@@ -9,4 +9,5 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-modules-commonjs",

"dependencies": {
"babel-helper-module-transforms": "7.0.0-beta.2",
"babel-types": "7.0.0-beta.2"
"babel-helper-module-transforms": "7.0.0-beta.3",
"babel-helper-simple-access": "7.0.0-beta.3",
"babel-types": "7.0.0-beta.3"
},

@@ -17,5 +18,6 @@ "keywords": [

"devDependencies": {
"babel-helper-plugin-test-runner": "7.0.0-beta.2",
"babel-plugin-syntax-object-rest-spread": "7.0.0-beta.2"
"babel-core": "7.0.0-beta.3",
"babel-helper-plugin-test-runner": "7.0.0-beta.3",
"babel-plugin-syntax-object-rest-spread": "7.0.0-beta.3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc