@babel/plugin-transform-runtime
Advanced tools
Comparing version 7.0.0-beta.46 to 7.0.0-beta.47
110
lib/index.js
@@ -15,3 +15,3 @@ "use strict"; | ||
function _helperPluginUtils() { | ||
var data = require("@babel/helper-plugin-utils"); | ||
const data = require("@babel/helper-plugin-utils"); | ||
@@ -26,3 +26,3 @@ _helperPluginUtils = function _helperPluginUtils() { | ||
function _helperModuleImports() { | ||
var data = require("@babel/helper-module-imports"); | ||
const data = require("@babel/helper-module-imports"); | ||
@@ -37,3 +37,3 @@ _helperModuleImports = function _helperModuleImports() { | ||
function _core() { | ||
var data = require("@babel/core"); | ||
const data = require("@babel/core"); | ||
@@ -51,16 +51,16 @@ _core = function _core() { | ||
var _default = (0, _helperPluginUtils().declare)(function (api, options) { | ||
var _default = (0, _helperPluginUtils().declare)((api, options) => { | ||
api.assertVersion(7); | ||
var helpers = options.helpers, | ||
_options$moduleName = options.moduleName, | ||
moduleName = _options$moduleName === void 0 ? "@babel/runtime" : _options$moduleName, | ||
polyfill = options.polyfill, | ||
regenerator = options.regenerator, | ||
useBuiltIns = options.useBuiltIns, | ||
useESModules = options.useESModules; | ||
var regeneratorEnabled = regenerator !== false; | ||
var notPolyfillOrDoesUseBuiltIns = polyfill === false || useBuiltIns; | ||
var isPolyfillAndUseBuiltIns = polyfill && useBuiltIns; | ||
var baseHelpersDir = useBuiltIns ? "helpers/builtin" : "helpers"; | ||
var helpersDir = useESModules ? baseHelpersDir + "/es6" : baseHelpersDir; | ||
const helpers = options.helpers, | ||
_options$moduleName = options.moduleName, | ||
moduleName = _options$moduleName === void 0 ? "@babel/runtime" : _options$moduleName, | ||
polyfill = options.polyfill, | ||
regenerator = options.regenerator, | ||
useBuiltIns = options.useBuiltIns, | ||
useESModules = options.useESModules; | ||
const regeneratorEnabled = regenerator !== false; | ||
const notPolyfillOrDoesUseBuiltIns = polyfill === false || useBuiltIns; | ||
const isPolyfillAndUseBuiltIns = polyfill && useBuiltIns; | ||
const baseHelpersDir = useBuiltIns ? "helpers/builtin" : "helpers"; | ||
const helpersDir = useESModules ? `${baseHelpersDir}/es6` : baseHelpersDir; | ||
@@ -71,12 +71,10 @@ function has(obj, key) { | ||
var HEADER_HELPERS = ["interopRequireWildcard", "interopRequireDefault"]; | ||
const HEADER_HELPERS = ["interopRequireWildcard", "interopRequireDefault"]; | ||
return { | ||
pre: function pre(file) { | ||
var _this = this; | ||
pre(file) { | ||
if (helpers !== false) { | ||
file.set("helperGenerator", function (name) { | ||
var isInteropHelper = HEADER_HELPERS.indexOf(name) !== -1; | ||
var blockHoist = isInteropHelper && !(0, _helperModuleImports().isModule)(file.path) ? 4 : undefined; | ||
return _this.addDefaultImport(moduleName + "/" + helpersDir + "/" + name, name, blockHoist); | ||
file.set("helperGenerator", name => { | ||
const isInteropHelper = HEADER_HELPERS.indexOf(name) !== -1; | ||
const blockHoist = isInteropHelper && !(0, _helperModuleImports().isModule)(file.path) ? 4 : undefined; | ||
return this.addDefaultImport(`${moduleName}/${helpersDir}/${name}`, name, blockHoist); | ||
}); | ||
@@ -90,8 +88,8 @@ } | ||
this.moduleName = moduleName; | ||
var cache = new Map(); | ||
const cache = new Map(); | ||
this.addDefaultImport = function (source, nameHint, blockHoist) { | ||
var cacheKey = (0, _helperModuleImports().isModule)(file.path); | ||
var key = source + ":" + nameHint + ":" + (cacheKey || ""); | ||
var cached = cache.get(key); | ||
this.addDefaultImport = (source, nameHint, blockHoist) => { | ||
const cacheKey = (0, _helperModuleImports().isModule)(file.path); | ||
const key = `${source}:${nameHint}:${cacheKey || ""}`; | ||
let cached = cache.get(key); | ||
@@ -103,4 +101,4 @@ if (cached) { | ||
importedInterop: "uncompiled", | ||
nameHint: nameHint, | ||
blockHoist: blockHoist | ||
nameHint, | ||
blockHoist | ||
}); | ||
@@ -113,10 +111,11 @@ cache.set(key, cached); | ||
}, | ||
visitor: { | ||
ReferencedIdentifier: function ReferencedIdentifier(path) { | ||
var node = path.node, | ||
parent = path.parent, | ||
scope = path.scope; | ||
ReferencedIdentifier(path) { | ||
const node = path.node, | ||
parent = path.parent, | ||
scope = path.scope; | ||
if (node.name === "regeneratorRuntime" && regeneratorEnabled) { | ||
path.replaceWith(this.addDefaultImport(this.moduleName + "/regenerator", "regeneratorRuntime")); | ||
path.replaceWith(this.addDefaultImport(`${this.moduleName}/regenerator`, "regeneratorRuntime")); | ||
return; | ||
@@ -129,8 +128,9 @@ } | ||
if (scope.getBindingIdentifier(node.name)) return; | ||
path.replaceWith(this.addDefaultImport(moduleName + "/core-js/" + _definitions.default.builtins[node.name], node.name)); | ||
path.replaceWith(this.addDefaultImport(`${moduleName}/core-js/${_definitions.default.builtins[node.name]}`, node.name)); | ||
}, | ||
CallExpression: function CallExpression(path) { | ||
CallExpression(path) { | ||
if (notPolyfillOrDoesUseBuiltIns) return; | ||
if (path.node.arguments.length) return; | ||
var callee = path.node.callee; | ||
const callee = path.node.callee; | ||
if (!_core().types.isMemberExpression(callee)) return; | ||
@@ -143,21 +143,23 @@ if (!callee.computed) return; | ||
path.replaceWith(_core().types.callExpression(this.addDefaultImport(moduleName + "/core-js/get-iterator", "getIterator"), [callee.object])); | ||
path.replaceWith(_core().types.callExpression(this.addDefaultImport(`${moduleName}/core-js/get-iterator`, "getIterator"), [callee.object])); | ||
}, | ||
BinaryExpression: function BinaryExpression(path) { | ||
BinaryExpression(path) { | ||
if (notPolyfillOrDoesUseBuiltIns) return; | ||
if (path.node.operator !== "in") return; | ||
if (!path.get("left").matchesPattern("Symbol.iterator")) return; | ||
path.replaceWith(_core().types.callExpression(this.addDefaultImport(moduleName + "/core-js/is-iterable", "isIterable"), [path.node.right])); | ||
path.replaceWith(_core().types.callExpression(this.addDefaultImport(`${moduleName}/core-js/is-iterable`, "isIterable"), [path.node.right])); | ||
}, | ||
MemberExpression: { | ||
enter: function enter(path) { | ||
enter(path) { | ||
if (notPolyfillOrDoesUseBuiltIns) return; | ||
if (!path.isReferenced()) return; | ||
var node = path.node; | ||
var obj = node.object; | ||
var prop = node.property; | ||
const node = path.node; | ||
const obj = node.object; | ||
const prop = node.property; | ||
if (!_core().types.isReferenced(obj, node)) return; | ||
if (node.computed) return; | ||
if (!has(_definitions.default.methods, obj.name)) return; | ||
var methods = _definitions.default.methods[obj.name]; | ||
const methods = _definitions.default.methods[obj.name]; | ||
if (!has(methods, prop.name)) return; | ||
@@ -167,3 +169,3 @@ if (path.scope.getBindingIdentifier(obj.name)) return; | ||
if (obj.name === "Object" && prop.name === "defineProperty" && path.parentPath.isCallExpression()) { | ||
var call = path.parentPath.node; | ||
const call = path.parentPath.node; | ||
@@ -175,13 +177,15 @@ if (call.arguments.length === 3 && _core().types.isLiteral(call.arguments[1])) { | ||
path.replaceWith(this.addDefaultImport(moduleName + "/core-js/" + methods[prop.name], obj.name + "$" + prop.name)); | ||
path.replaceWith(this.addDefaultImport(`${moduleName}/core-js/${methods[prop.name]}`, `${obj.name}$${prop.name}`)); | ||
}, | ||
exit: function exit(path) { | ||
exit(path) { | ||
if (notPolyfillOrDoesUseBuiltIns) return; | ||
if (!path.isReferenced()) return; | ||
var node = path.node; | ||
var obj = node.object; | ||
const node = path.node; | ||
const obj = node.object; | ||
if (!has(_definitions.default.builtins, obj.name)) return; | ||
if (path.scope.getBindingIdentifier(obj.name)) return; | ||
path.replaceWith(_core().types.memberExpression(this.addDefaultImport(moduleName + "/core-js/" + _definitions.default.builtins[obj.name], obj.name), node.property, node.computed)); | ||
path.replaceWith(_core().types.memberExpression(this.addDefaultImport(`${moduleName}/core-js/${_definitions.default.builtins[obj.name]}`, obj.name), node.property, node.computed)); | ||
} | ||
} | ||
@@ -188,0 +192,0 @@ } |
{ | ||
"name": "@babel/plugin-transform-runtime", | ||
"version": "7.0.0-beta.46", | ||
"version": "7.0.0-beta.47", | ||
"description": "Externalise references to helpers and builtins, automatically polyfilling your code without polluting globals", | ||
@@ -12,12 +12,12 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime", | ||
"dependencies": { | ||
"@babel/helper-module-imports": "7.0.0-beta.46", | ||
"@babel/helper-plugin-utils": "7.0.0-beta.46" | ||
"@babel/helper-module-imports": "7.0.0-beta.47", | ||
"@babel/helper-plugin-utils": "7.0.0-beta.47" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "7.0.0-beta.46" | ||
"@babel/core": "7.0.0-beta.47" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.46", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.46" | ||
"@babel/core": "7.0.0-beta.47", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.47" | ||
} | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
22094
315
+ Added@babel/code-frame@7.0.0-beta.47(transitive)
+ Added@babel/core@7.0.0-beta.47(transitive)
+ Added@babel/generator@7.0.0-beta.47(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.47(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.47(transitive)
+ Added@babel/helper-module-imports@7.0.0-beta.47(transitive)
+ Added@babel/helper-plugin-utils@7.0.0-beta.47(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.47(transitive)
+ Added@babel/helpers@7.0.0-beta.47(transitive)
+ Added@babel/highlight@7.0.0-beta.47(transitive)
+ Added@babel/template@7.0.0-beta.47(transitive)
+ Added@babel/traverse@7.0.0-beta.47(transitive)
+ Added@babel/types@7.0.0-beta.47(transitive)
+ Addedbabylon@7.0.0-beta.47(transitive)
- Removed@babel/code-frame@7.0.0-beta.46(transitive)
- Removed@babel/core@7.0.0-beta.46(transitive)
- Removed@babel/generator@7.0.0-beta.46(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.46(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.46(transitive)
- Removed@babel/helper-module-imports@7.0.0-beta.46(transitive)
- Removed@babel/helper-plugin-utils@7.0.0-beta.46(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.46(transitive)
- Removed@babel/helpers@7.0.0-beta.46(transitive)
- Removed@babel/highlight@7.0.0-beta.46(transitive)
- Removed@babel/template@7.0.0-beta.46(transitive)
- Removed@babel/traverse@7.0.0-beta.46(transitive)
- Removed@babel/types@7.0.0-beta.46(transitive)
- Removedbabylon@7.0.0-beta.46(transitive)