What is babel-plugin-syntax-object-rest-spread?
The babel-plugin-syntax-object-rest-spread package allows Babel to parse the object rest/spread syntax. This syntax feature lets you copy enumerable properties from one object to another using the spread (...) operator and pick up remaining properties that are not explicitly picked up by the destructuring pattern using the rest (...) operator.
What are babel-plugin-syntax-object-rest-spread's main functionalities?
Object Spread
Allows an object's own enumerable properties to be copied into a new object. Useful for creating a shallow copy of an object or combining multiple objects into one.
{ ...source }
Object Rest
Allows the remaining own enumerable property keys that are not already picked off by the destructuring pattern to be collected into an object.
{ a, b, ...rest } = object
Other packages similar to babel-plugin-syntax-object-rest-spread
@babel/plugin-proposal-object-rest-spread
This package is a plugin that transforms object rest and spread syntax to ES5. It is the evolution of the babel-plugin-syntax-object-rest-spread and includes both the syntax parsing and the transformation, whereas babel-plugin-syntax-object-rest-spread only allows Babel to parse the syntax.
babel-plugin-transform-object-rest-spread
This is a legacy plugin that was used to transform object rest and spread properties for Babel 6. It has been superseded by @babel/plugin-proposal-object-rest-spread in Babel 7.
babel-plugin-syntax-object-rest-spread
Allow parsing of object rest/spread.
Installation
npm install --save-dev babel-plugin-syntax-object-rest-spread
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": ["syntax-object-rest-spread"]
}
Via CLI
babel --plugins syntax-object-rest-spread script.js
Via Node API
require("babel-core").transform("code", {
plugins: ["syntax-object-rest-spread"]
});