Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-runtime

Package Overview
Dependencies
Maintainers
5
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-runtime - npm Package Compare versions

Comparing version 7.3.4 to 7.4.0

lib/helpers.js

159

lib/index.js

@@ -58,4 +58,6 @@ "use strict";

var _definitions = _interopRequireDefault(require("./definitions"));
var _runtimeCorejs2Definitions = _interopRequireDefault(require("./runtime-corejs2-definitions"));
var _runtimeCorejs3Definitions = _interopRequireDefault(require("./runtime-corejs3-definitions"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -85,3 +87,3 @@

const {
corejs: corejsVersion = false,
corejs,
helpers: useRuntimeHelpers = true,

@@ -93,4 +95,22 @@ regenerator: useRuntimeRegenerator = true,

} = options;
const definitions = (0, _definitions.default)(runtimeVersion);
let proposals = false;
let rawVersion;
if (typeof corejs === "object" && corejs !== null) {
rawVersion = corejs.version;
proposals = Boolean(corejs.proposals);
} else {
rawVersion = corejs;
}
const corejsVersion = rawVersion ? Number(rawVersion) : false;
if (![false, 2, 3].includes(corejsVersion)) {
throw new Error(`The \`core-js\` version must be false, 2 or 3, but got ${JSON.stringify(rawVersion)}.`);
}
if (proposals && (!corejsVersion || corejsVersion < 3)) {
throw new Error("The 'proposals' option is only supported when using 'corejs: 3'");
}
if (typeof useRuntimeRegenerator !== "boolean") {

@@ -112,6 +132,2 @@ throw new Error("The 'regenerator' option must be undefined, or a boolean.");

if (corejsVersion !== false && (typeof corejsVersion !== "number" || corejsVersion !== 2) && (typeof corejsVersion !== "string" || corejsVersion !== "2")) {
throw new Error(`The 'corejs' option must be undefined, false, 2 or '2', ` + `but got ${JSON.stringify(corejsVersion)}.`);
}
if (typeof runtimeVersion !== "string") {

@@ -125,2 +141,10 @@ throw new Error(`The 'version' option must be a version string.`);

function hasMapping(methods, name) {
return has(methods, name) && (proposals || methods[name].stable);
}
function hasStaticMapping(object, method) {
return has(StaticProperties, object) && hasMapping(StaticProperties[object], method);
}
if (has(options, "useBuiltIns")) {

@@ -130,3 +154,3 @@ if (options.useBuiltIns) {

} else {
throw new Error("The 'useBuiltIns' option has been removed. Use the 'corejs'" + "option with value '2' to polyfill with CoreJS 2.x via @babel/runtime.");
throw new Error("The 'useBuiltIns' option has been removed. Use the 'corejs'" + "option to polyfill with `core-js` via @babel/runtime.");
}

@@ -139,3 +163,3 @@ }

} else {
throw new Error("The 'polyfill' option has been removed. Use the 'corejs'" + "option with value '2' to polyfill with CoreJS 2.x via @babel/runtime.");
throw new Error("The 'polyfill' option has been removed. Use the 'corejs'" + "option to polyfill with `core-js` via @babel/runtime.");
}

@@ -149,4 +173,12 @@ }

const esModules = useESModules === "auto" ? api.caller(supportsStaticESM) : useESModules;
const injectCoreJS2 = `${corejsVersion}` === "2";
const moduleName = injectCoreJS2 ? "@babel/runtime-corejs2" : "@babel/runtime";
const injectCoreJS2 = corejsVersion === 2;
const injectCoreJS3 = corejsVersion === 3;
const injectCoreJS = corejsVersion !== false;
const moduleName = injectCoreJS3 ? "@babel/runtime-corejs3" : injectCoreJS2 ? "@babel/runtime-corejs2" : "@babel/runtime";
const corejsRoot = injectCoreJS3 && !proposals ? "core-js-stable" : "core-js";
const {
BuiltIns,
StaticProperties,
InstanceProperties
} = (injectCoreJS2 ? _runtimeCorejs2Definitions.default : _runtimeCorejs3Definitions.default)(runtimeVersion);
const HEADER_HELPERS = ["interopRequireWildcard", "interopRequireDefault"];

@@ -205,4 +237,7 @@ let modulePath = moduleName;

} = path;
const {
name
} = node;
if (node.name === "regeneratorRuntime" && useRuntimeRegenerator) {
if (name === "regeneratorRuntime" && useRuntimeRegenerator) {
path.replaceWith(this.addDefaultImport(`${modulePath}/regenerator`, "regeneratorRuntime"));

@@ -212,14 +247,43 @@ return;

if (!injectCoreJS2) return;
if (!injectCoreJS) return;
if (_core().types.isMemberExpression(parent)) return;
if (!has(definitions.builtins, node.name)) return;
if (scope.getBindingIdentifier(node.name)) return;
path.replaceWith(this.addDefaultImport(`${modulePath}/core-js/${definitions.builtins[node.name]}`, node.name));
if (!hasMapping(BuiltIns, name)) return;
if (scope.getBindingIdentifier(name)) return;
path.replaceWith(this.addDefaultImport(`${modulePath}/${corejsRoot}/${BuiltIns[name].path}`, name));
},
CallExpression(path) {
if (!injectCoreJS2) return;
if (path.node.arguments.length) return;
const callee = path.node.callee;
if (!injectCoreJS) return;
const {
node
} = path;
const {
callee
} = node;
if (!_core().types.isMemberExpression(callee)) return;
const {
object,
property
} = callee;
const propertyName = property.name;
if (injectCoreJS3 && !hasStaticMapping(object.name, propertyName)) {
if (hasMapping(InstanceProperties, propertyName)) {
let context1, context2;
if (_core().types.isIdentifier(object)) {
context1 = object;
context2 = _core().types.cloneNode(object);
} else {
context1 = path.scope.generateDeclaredUidIdentifier("context");
context2 = _core().types.assignmentExpression("=", context1, object);
}
node.callee = _core().types.memberExpression(_core().types.callExpression(this.addDefaultImport(`${moduleName}/${corejsRoot}/instance/${InstanceProperties[propertyName].path}`, `${propertyName}InstanceProperty`), [context2]), _core().types.identifier("call"));
node.arguments.unshift(context1);
return;
}
}
if (node.arguments.length) return;
if (!callee.computed) return;

@@ -231,7 +295,7 @@

path.replaceWith(_core().types.callExpression(this.addDefaultImport(`${modulePath}/core-js/get-iterator`, "getIterator"), [callee.object]));
path.replaceWith(_core().types.callExpression(this.addDefaultImport(`${modulePath}/core-js/get-iterator`, "getIterator"), [object]));
},
BinaryExpression(path) {
if (!injectCoreJS2) return;
if (!injectCoreJS) return;
if (path.node.operator !== "in") return;

@@ -244,3 +308,3 @@ if (!path.get("left").matchesPattern("Symbol.iterator")) return;

enter(path) {
if (!injectCoreJS2) return;
if (!injectCoreJS) return;
if (!path.isReferenced()) return;

@@ -250,24 +314,34 @@ const {

} = path;
const obj = node.object;
const prop = node.property;
if (!_core().types.isReferenced(obj, node)) return;
if (node.computed) return;
if (!has(definitions.methods, obj.name)) return;
const methods = definitions.methods[obj.name];
if (!has(methods, prop.name)) return;
if (path.scope.getBindingIdentifier(obj.name)) return;
const {
object,
property
} = node;
if (!_core().types.isReferenced(object, node)) return;
if (obj.name === "Object" && prop.name === "defineProperty" && path.parentPath.isCallExpression()) {
const call = path.parentPath.node;
if (node.computed) {
if (injectCoreJS2) return;
if (call.arguments.length === 3 && _core().types.isLiteral(call.arguments[1])) {
return;
if (path.get("property").matchesPattern("Symbol.iterator")) {
path.replaceWith(_core().types.callExpression(this.addDefaultImport(`${moduleName}/core-js/get-iterator-method`, "getIteratorMethod"), [object]));
}
return;
}
path.replaceWith(this.addDefaultImport(`${modulePath}/core-js/${methods[prop.name]}`, `${obj.name}$${prop.name}`));
const objectName = object.name;
const propertyName = property.name;
if (path.scope.getBindingIdentifier(objectName) || !hasStaticMapping(objectName, propertyName)) {
if (injectCoreJS3 && hasMapping(InstanceProperties, propertyName)) {
path.replaceWith(_core().types.callExpression(this.addDefaultImport(`${moduleName}/${corejsRoot}/instance/${InstanceProperties[propertyName].path}`, `${propertyName}InstanceProperty`), [object]));
}
return;
}
path.replaceWith(this.addDefaultImport(`${modulePath}/${corejsRoot}/${StaticProperties[objectName][propertyName].path}`, `${objectName}$${propertyName}`));
},
exit(path) {
if (!injectCoreJS2) return;
if (!injectCoreJS) return;
if (!path.isReferenced()) return;

@@ -277,6 +351,11 @@ const {

} = path;
const obj = node.object;
if (!has(definitions.builtins, obj.name)) return;
if (path.scope.getBindingIdentifier(obj.name)) return;
path.replaceWith(_core().types.memberExpression(this.addDefaultImport(`${modulePath}/core-js/${definitions.builtins[obj.name]}`, obj.name), node.property, node.computed));
const {
object
} = node;
const {
name
} = object;
if (!hasMapping(BuiltIns, name)) return;
if (path.scope.getBindingIdentifier(name)) return;
path.replaceWith(_core().types.memberExpression(this.addDefaultImport(`${modulePath}/${corejsRoot}/${BuiltIns[name].path}`, name), node.property, node.computed));
}

@@ -283,0 +362,0 @@

{
"name": "@babel/plugin-transform-runtime",
"version": "7.3.4",
"version": "7.4.0",
"description": "Externalise references to helpers and builtins, automatically polyfilling your code without polluting globals",

@@ -24,12 +24,14 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime",

"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/core": "^7.4.0",
"@babel/helper-plugin-test-runner": "^7.0.0",
"@babel/helpers": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/runtime": "^7.3.4",
"@babel/template": "^7.0.0",
"@babel/helpers": "^7.4.0",
"@babel/plugin-transform-member-expression-literals": "^7.2.0",
"@babel/plugin-transform-property-literals": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.4.0",
"@babel/preset-env": "^7.4.0",
"@babel/runtime": "^7.4.0",
"@babel/template": "^7.4.0",
"@babel/types": "7.0.0-beta.53"
},
"gitHead": "1f6454cc90fe33e0a32260871212e2f719f35741"
"gitHead": "f1328fb913b5a93d54dfc6e3728b1f56c8f4a804"
}
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