@babel/plugin-transform-spread
Advanced tools
Comparing version 7.0.0-beta.42 to 7.0.0-beta.43
138
lib/index.js
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _helperPluginUtils = require("@babel/helper-plugin-utils"); | ||
function _helperPluginUtils() { | ||
const data = require("@babel/helper-plugin-utils"); | ||
var _core = require("@babel/core"); | ||
_helperPluginUtils = function () { | ||
return data; | ||
}; | ||
var _default = (0, _helperPluginUtils.declare)(function (api, options) { | ||
return data; | ||
} | ||
function _core() { | ||
const data = require("@babel/core"); | ||
_core = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _default = (0, _helperPluginUtils().declare)((api, options) => { | ||
api.assertVersion(7); | ||
var loose = options.loose; | ||
const { | ||
loose | ||
} = options; | ||
function getSpreadLiteral(spread, scope) { | ||
if (loose && !_core.types.isIdentifier(spread.argument, { | ||
if (loose && !_core().types.isIdentifier(spread.argument, { | ||
name: "arguments" | ||
@@ -25,4 +45,4 @@ })) { | ||
function hasSpread(nodes) { | ||
for (var i = 0; i < nodes.length; i++) { | ||
if (_core.types.isSpreadElement(nodes[i])) { | ||
for (let i = 0; i < nodes.length; i++) { | ||
if (_core().types.isSpreadElement(nodes[i])) { | ||
return true; | ||
@@ -37,3 +57,3 @@ } | ||
if (!_props.length) return _props; | ||
nodes.push(_core.types.arrayExpression(_props)); | ||
nodes.push(_core().types.arrayExpression(_props)); | ||
return []; | ||
@@ -43,24 +63,11 @@ } | ||
function build(props, scope) { | ||
var nodes = []; | ||
var _props = []; | ||
const nodes = []; | ||
let _props = []; | ||
for (var _iterator = props, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var _prop = _ref; | ||
if (_core.types.isSpreadElement(_prop)) { | ||
for (const prop of props) { | ||
if (_core().types.isSpreadElement(prop)) { | ||
_props = push(_props, nodes); | ||
nodes.push(getSpreadLiteral(_prop, scope)); | ||
nodes.push(getSpreadLiteral(prop, scope)); | ||
} else { | ||
_props.push(_prop); | ||
_props.push(prop); | ||
} | ||
@@ -75,9 +82,11 @@ } | ||
visitor: { | ||
ArrayExpression: function ArrayExpression(path, state) { | ||
var node = path.node, | ||
scope = path.scope; | ||
var elements = node.elements; | ||
ArrayExpression(path, state) { | ||
const { | ||
node, | ||
scope | ||
} = path; | ||
const elements = node.elements; | ||
if (!hasSpread(elements)) return; | ||
var nodes = build(elements, scope, state); | ||
var first = nodes.shift(); | ||
const nodes = build(elements, scope, state); | ||
const first = nodes.shift(); | ||
@@ -89,14 +98,17 @@ if (nodes.length === 0 && first !== elements[0].argument) { | ||
path.replaceWith(_core.types.callExpression(_core.types.memberExpression(first, _core.types.identifier("concat")), nodes)); | ||
path.replaceWith(_core().types.callExpression(_core().types.memberExpression(first, _core().types.identifier("concat")), nodes)); | ||
}, | ||
CallExpression: function CallExpression(path, state) { | ||
var node = path.node, | ||
scope = path.scope; | ||
var args = node.arguments; | ||
CallExpression(path, state) { | ||
const { | ||
node, | ||
scope | ||
} = path; | ||
const args = node.arguments; | ||
if (!hasSpread(args)) return; | ||
var calleePath = path.get("callee"); | ||
const calleePath = path.get("callee"); | ||
if (calleePath.isSuper()) return; | ||
var contextLiteral = scope.buildUndefinedNode(); | ||
let contextLiteral = scope.buildUndefinedNode(); | ||
node.arguments = []; | ||
var nodes; | ||
let nodes; | ||
@@ -109,6 +121,6 @@ if (args.length === 1 && args[0].argument.name === "arguments") { | ||
var first = nodes.shift(); | ||
const first = nodes.shift(); | ||
if (nodes.length) { | ||
node.arguments.push(_core.types.callExpression(_core.types.memberExpression(first, _core.types.identifier("concat")), nodes)); | ||
node.arguments.push(_core().types.callExpression(_core().types.memberExpression(first, _core().types.identifier("concat")), nodes)); | ||
} else { | ||
@@ -118,37 +130,41 @@ node.arguments.push(first); | ||
var callee = node.callee; | ||
const callee = node.callee; | ||
if (calleePath.isMemberExpression()) { | ||
var temp = scope.maybeGenerateMemoised(callee.object); | ||
const temp = scope.maybeGenerateMemoised(callee.object); | ||
if (temp) { | ||
callee.object = _core.types.assignmentExpression("=", temp, callee.object); | ||
callee.object = _core().types.assignmentExpression("=", temp, callee.object); | ||
contextLiteral = temp; | ||
} else { | ||
contextLiteral = _core.types.cloneNode(callee.object); | ||
contextLiteral = _core().types.cloneNode(callee.object); | ||
} | ||
_core.types.appendToMemberExpression(callee, _core.types.identifier("apply")); | ||
_core().types.appendToMemberExpression(callee, _core().types.identifier("apply")); | ||
} else { | ||
node.callee = _core.types.memberExpression(node.callee, _core.types.identifier("apply")); | ||
node.callee = _core().types.memberExpression(node.callee, _core().types.identifier("apply")); | ||
} | ||
if (_core.types.isSuper(contextLiteral)) { | ||
contextLiteral = _core.types.thisExpression(); | ||
if (_core().types.isSuper(contextLiteral)) { | ||
contextLiteral = _core().types.thisExpression(); | ||
} | ||
node.arguments.unshift(_core.types.cloneNode(contextLiteral)); | ||
node.arguments.unshift(_core().types.cloneNode(contextLiteral)); | ||
}, | ||
NewExpression: function NewExpression(path, state) { | ||
var node = path.node, | ||
scope = path.scope; | ||
var args = node.arguments; | ||
NewExpression(path, state) { | ||
const { | ||
node, | ||
scope | ||
} = path; | ||
let args = node.arguments; | ||
if (!hasSpread(args)) return; | ||
var nodes = build(args, scope, state); | ||
const nodes = build(args, scope, state); | ||
var context = _core.types.arrayExpression([_core.types.nullLiteral()]); | ||
const context = _core().types.arrayExpression([_core().types.nullLiteral()]); | ||
args = _core.types.callExpression(_core.types.memberExpression(context, _core.types.identifier("concat")), nodes); | ||
path.replaceWith(_core.types.newExpression(_core.types.callExpression(_core.types.memberExpression(_core.types.memberExpression(_core.types.memberExpression(_core.types.identifier("Function"), _core.types.identifier("prototype")), _core.types.identifier("bind")), _core.types.identifier("apply")), [node.callee, args]), [])); | ||
args = _core().types.callExpression(_core().types.memberExpression(context, _core().types.identifier("concat")), nodes); | ||
path.replaceWith(_core().types.newExpression(_core().types.callExpression(_core().types.memberExpression(_core().types.memberExpression(_core().types.memberExpression(_core().types.identifier("Function"), _core().types.identifier("prototype")), _core().types.identifier("bind")), _core().types.identifier("apply")), [node.callee, args]), [])); | ||
} | ||
} | ||
@@ -155,0 +171,0 @@ }; |
{ | ||
"name": "@babel/plugin-transform-spread", | ||
"version": "7.0.0-beta.42", | ||
"version": "7.0.0-beta.43", | ||
"description": "Compile ES2015 spread to ES5", | ||
@@ -12,11 +12,11 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-spread", | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "7.0.0-beta.42" | ||
"@babel/helper-plugin-utils": "7.0.0-beta.43" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "7.0.0-beta.42" | ||
"@babel/core": "7.0.0-beta.43" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.42", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.42" | ||
"@babel/core": "7.0.0-beta.43", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.43" | ||
} | ||
} |
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
134
6011
+ Added@babel/code-frame@7.0.0-beta.43(transitive)
+ Added@babel/core@7.0.0-beta.43(transitive)
+ Added@babel/generator@7.0.0-beta.43(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.43(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.43(transitive)
+ Added@babel/helper-plugin-utils@7.0.0-beta.43(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.43(transitive)
+ Added@babel/helpers@7.0.0-beta.43(transitive)
+ Added@babel/highlight@7.0.0-beta.43(transitive)
+ Added@babel/template@7.0.0-beta.43(transitive)
+ Added@babel/traverse@7.0.0-beta.43(transitive)
+ Added@babel/types@7.0.0-beta.43(transitive)
+ Addedbabylon@7.0.0-beta.43(transitive)
- Removed@babel/code-frame@7.0.0-beta.42(transitive)
- Removed@babel/core@7.0.0-beta.42(transitive)
- Removed@babel/generator@7.0.0-beta.42(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.42(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.42(transitive)
- Removed@babel/helper-plugin-utils@7.0.0-beta.42(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.42(transitive)
- Removed@babel/helpers@7.0.0-beta.42(transitive)
- Removed@babel/highlight@7.0.0-beta.42(transitive)
- Removed@babel/template@7.0.0-beta.42(transitive)
- Removed@babel/traverse@7.0.0-beta.42(transitive)
- Removed@babel/types@7.0.0-beta.42(transitive)
- Removedbabylon@7.0.0-beta.42(transitive)