Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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
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
- All iterables are assumed to be arrays.FAQs
Compile ES2015 spread to ES5
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.