Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
babel-plugin-transform-es2015-spread
Advanced tools
The babel-plugin-transform-es2015-spread npm package is used to compile ES2015 spread syntax to a version of JavaScript that can run in environments that do not support this syntax natively. Spread syntax allows an iterable such as an array to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.
Function Calls
This feature allows an array of arguments to be spread out and passed as individual arguments to a function call. The code sample demonstrates spreading an array into a function call.
function sum(x, y, z) { return x + y + z; } const numbers = [1, 2, 3]; console.log(sum(...numbers));
Array Literals
Spread syntax can be used to concatenate arrays or insert multiple elements into an array at once. The code sample shows how to use spread syntax to merge arrays.
const parts = ['shoulders', 'knees']; const body = ['head', ...parts, 'toes'];
Object Literals
This feature allows for the properties of one or more source objects to be copied into a new object. The code sample demonstrates both cloning and merging objects using spread syntax.
const obj1 = { foo: 'bar', x: 42 }; const obj2 = { foo: 'baz', y: 13 }; const clonedObj = { ...obj1 }; const mergedObj = { ...obj1, ...obj2 };
This package provides functionality similar to babel-plugin-transform-es2015-spread but focuses on the object rest and spread properties proposal, which was later included in ES2018. It allows for spreading properties of objects in a similar manner but is more up-to-date with the latest JavaScript specifications.
While not a direct replacement, @babel/preset-env includes the functionality of babel-plugin-transform-es2015-spread as part of a comprehensive preset that compiles ES2015+ syntax down to ES5. It automatically determines the Babel plugins and polyfills needed based on the target environment's support for modern JavaScript features.
Compile ES2015 spread to ES5
In
var a = ['a', 'b', 'c'];
var b = [...a, 'foo'];
Out
var a = [ 'a', 'b', 'c' ];
var b = [].concat(a, [ 'foo' ]);
npm install --save-dev babel-plugin-transform-es2015-spread
.babelrc
(Recommended).babelrc
Without options:
{
"plugins": ["transform-es2015-spread"]
}
With options:
{
"plugins": [
["transform-es2015-spread", {
"loose": true
}]
]
}
babel --plugins transform-es2015-spread script.js
require("babel-core").transform("code", {
plugins: ["transform-es2015-spread"]
});
loose
boolean
, defaults to false
.
In loose mode, all iterables are assumed to be arrays.
FAQs
Compile ES2015 spread to ES5
The npm package babel-plugin-transform-es2015-spread receives a total of 597,326 weekly downloads. As such, babel-plugin-transform-es2015-spread popularity was classified as popular.
We found that babel-plugin-transform-es2015-spread demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.