update
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
> Compile ES2015 spread to ES5
|
||||
|
||||
See our website [@babel/plugin-transform-spread](https://babeljs.io/docs/en/next/babel-plugin-transform-spread.html) for more information.
|
||||
See our website [@babel/plugin-transform-spread](https://babeljs.io/docs/en/babel-plugin-transform-spread) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
|
||||
+38
-22
@@ -7,25 +7,31 @@ exports.default = void 0;
|
||||
|
||||
var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
||||
|
||||
var _helperSkipTransparentExpressionWrappers = require("@babel/helper-skip-transparent-expression-wrappers");
|
||||
|
||||
var _core = require("@babel/core");
|
||||
|
||||
var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
var _api$assumption, _options$allowArrayLi;
|
||||
|
||||
api.assertVersion(7);
|
||||
const {
|
||||
loose,
|
||||
allowArrayLike
|
||||
} = options;
|
||||
const iterableIsArray = (_api$assumption = api.assumption("iterableIsArray")) != null ? _api$assumption : options.loose;
|
||||
const arrayLikeIsIterable = (_options$allowArrayLi = options.allowArrayLike) != null ? _options$allowArrayLi : api.assumption("arrayLikeIsIterable");
|
||||
|
||||
function getSpreadLiteral(spread, scope) {
|
||||
if (loose && !_core.types.isIdentifier(spread.argument, {
|
||||
if (iterableIsArray && !_core.types.isIdentifier(spread.argument, {
|
||||
name: "arguments"
|
||||
})) {
|
||||
return spread.argument;
|
||||
} else {
|
||||
return scope.toArray(spread.argument, true, allowArrayLike);
|
||||
return scope.toArray(spread.argument, true, arrayLikeIsIterable);
|
||||
}
|
||||
}
|
||||
|
||||
function hasHole(spread) {
|
||||
return spread.elements.some(el => el === null);
|
||||
}
|
||||
|
||||
function hasSpread(nodes) {
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
if (_core.types.isSpreadElement(nodes[i])) {
|
||||
@@ -42,14 +48,20 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
return [];
|
||||
}
|
||||
|
||||
function build(props, scope) {
|
||||
function build(props, scope, file) {
|
||||
const nodes = [];
|
||||
let _props = [];
|
||||
|
||||
for (const prop of props) {
|
||||
if (_core.types.isSpreadElement(prop)) {
|
||||
_props = push(_props, nodes);
|
||||
nodes.push(getSpreadLiteral(prop, scope));
|
||||
let spreadLiteral = getSpreadLiteral(prop, scope);
|
||||
|
||||
if (_core.types.isArrayExpression(spreadLiteral) && hasHole(spreadLiteral)) {
|
||||
spreadLiteral = _core.types.callExpression(file.addHelper("arrayWithoutHoles"), [spreadLiteral]);
|
||||
}
|
||||
|
||||
nodes.push(spreadLiteral);
|
||||
} else {
|
||||
_props.push(prop);
|
||||
}
|
||||
@@ -69,7 +81,7 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
} = path;
|
||||
const elements = node.elements;
|
||||
if (!hasSpread(elements)) return;
|
||||
const nodes = build(elements, scope);
|
||||
const nodes = build(elements, scope, this.file);
|
||||
let first = nodes[0];
|
||||
|
||||
if (nodes.length === 1 && first !== elements[0].argument) {
|
||||
@@ -93,16 +105,22 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
} = path;
|
||||
const args = node.arguments;
|
||||
if (!hasSpread(args)) return;
|
||||
const calleePath = path.get("callee");
|
||||
if (calleePath.isSuper()) return;
|
||||
const calleePath = (0, _helperSkipTransparentExpressionWrappers.skipTransparentExprWrappers)(path.get("callee"));
|
||||
|
||||
if (calleePath.isSuper()) {
|
||||
throw path.buildCodeFrameError("It's not possible to compile spread arguments in `super()` without compiling classes.\n" + "Please add '@babel/plugin-transform-classes' to your Babel configuration.");
|
||||
}
|
||||
|
||||
let contextLiteral = scope.buildUndefinedNode();
|
||||
node.arguments = [];
|
||||
let nodes;
|
||||
|
||||
if (args.length === 1 && args[0].argument.name === "arguments") {
|
||||
if (args.length === 1 && _core.types.isIdentifier(args[0].argument, {
|
||||
name: "arguments"
|
||||
})) {
|
||||
nodes = [args[0].argument];
|
||||
} else {
|
||||
nodes = build(args, scope);
|
||||
nodes = build(args, scope, this.file);
|
||||
}
|
||||
|
||||
const first = nodes.shift();
|
||||
@@ -113,9 +131,9 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
node.arguments.push(first);
|
||||
}
|
||||
|
||||
const callee = node.callee;
|
||||
const callee = calleePath.node;
|
||||
|
||||
if (calleePath.isMemberExpression()) {
|
||||
if (_core.types.isMemberExpression(callee)) {
|
||||
const temp = scope.maybeGenerateMemoised(callee.object);
|
||||
|
||||
if (temp) {
|
||||
@@ -124,12 +142,10 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
} else {
|
||||
contextLiteral = _core.types.cloneNode(callee.object);
|
||||
}
|
||||
|
||||
_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();
|
||||
}
|
||||
@@ -142,10 +158,10 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
node,
|
||||
scope
|
||||
} = path;
|
||||
let args = node.arguments;
|
||||
if (!hasSpread(args)) return;
|
||||
const nodes = build(args, scope);
|
||||
if (!hasSpread(node.arguments)) return;
|
||||
const nodes = build(node.arguments, scope, this.file);
|
||||
const first = nodes.shift();
|
||||
let args;
|
||||
|
||||
if (nodes.length) {
|
||||
args = _core.types.callExpression(_core.types.memberExpression(first, _core.types.identifier("concat")), nodes);
|
||||
|
||||
+26
-18
@@ -1,51 +1,58 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"@babel/plugin-transform-spread@7.10.4",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"@babel/plugin-transform-spread@7.18.6",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "@babel/plugin-transform-spread@7.10.4",
|
||||
"_id": "@babel/plugin-transform-spread@7.10.4",
|
||||
"_from": "@babel/plugin-transform-spread@7.18.6",
|
||||
"_id": "@babel/plugin-transform-spread@7.18.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-1e/51G/Ni+7uH5gktbWv+eCED9pP8ZpRhZB3jOaI3mmzfvJTWHkuyYTv0Z5PYtyM+Tr2Ccr9kUdQxn60fI5WuQ==",
|
||||
"_integrity": "sha512-ayT53rT/ENF8WWexIRg9AiV9h0aIteyWn5ptfZTZQrjk/+f3WdrJGCY4c9wcgl2+MKkKPhzbYp97FTsquZpDCw==",
|
||||
"_location": "/@babel/plugin-transform-spread",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@babel/plugin-transform-spread@7.10.4",
|
||||
"raw": "@babel/plugin-transform-spread@7.18.6",
|
||||
"name": "@babel/plugin-transform-spread",
|
||||
"escapedName": "@babel%2fplugin-transform-spread",
|
||||
"scope": "@babel",
|
||||
"rawSpec": "7.10.4",
|
||||
"rawSpec": "7.18.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "7.10.4"
|
||||
"fetchSpec": "7.18.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@babel/preset-env"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@babel/plugin-transform-spread/-/plugin-transform-spread-7.10.4.tgz",
|
||||
"_spec": "7.10.4",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/@babel/plugin-transform-spread/-/plugin-transform-spread-7.18.6.tgz",
|
||||
"_spec": "7.18.6",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "The Babel Team",
|
||||
"url": "https://babel.dev/team"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/babel/babel/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "^7.10.4"
|
||||
"@babel/helper-plugin-utils": "^7.18.6",
|
||||
"@babel/helper-skip-transparent-expression-wrappers": "^7.18.6"
|
||||
},
|
||||
"description": "Compile ES2015 spread to ES5",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.10.4",
|
||||
"@babel/helper-plugin-test-runner": "^7.10.4"
|
||||
"@babel/core": "^7.18.6",
|
||||
"@babel/helper-plugin-test-runner": "^7.18.6"
|
||||
},
|
||||
"gitHead": "7fd40d86a0d03ff0e9c3ea16b29689945433d4df",
|
||||
"homepage": "https://github.com/babel/babel#readme",
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-spread",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"main": "./lib/index.js",
|
||||
"name": "@babel/plugin-transform-spread",
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
@@ -58,5 +65,6 @@
|
||||
"url": "git+https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-plugin-transform-spread"
|
||||
},
|
||||
"version": "7.10.4"
|
||||
"type": "commonjs",
|
||||
"version": "7.18.6"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user