Registry /
devops / babel-plugin-object-rest-spread
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
plugin
✓ plugins: ['babel-plugin-object-rest-spread']
✗ plugins: ['object-rest-spread']
Babel 6 expects the full package name; avoid abbreviating.
options
✓ plugins: [['babel-plugin-object-rest-spread', { loose: true }]]
✗ plugins: ['babel-plugin-object-rest-spread', { loose: true }]
Options must be in an array with the plugin name; this syntax changed from Babel 5.
require
✓ require('babel-plugin-object-rest-spread')
✗ require('babel-plugin-object-rest-spread').default
The plugin is CommonJS-compatible; no .default needed.
Demonstrates transforming object rest/spread with .babelrc config and sample output.
// Install: npm install --save-dev babel-plugin-object-rest-spread
// .babelrc
{
"plugins": ["babel-plugin-object-rest-spread"]
}
// Input: uses object rest/spread
const { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
const n = { x, y, ...z };
// Output (with loose:false by default)
var _objectWithoutProperties = function (obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}
return target;
};
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
var ref = { x: 1, y: 2, a: 3, b: 4 };
var x = ref.x;
var y = ref.y;
var z = _objectWithoutProperties(ref, ['x', 'y']);
var n = _extends({ x: x, y: y }, z);
Debug
Known issues
deprecatedThis plugin is for Babel 6 only. For Babel 7+, use @babel/plugin-proposal-object-rest-spread or include in @babel/preset-env.fixUpgrade to @babel/plugin-proposal-object-rest-spread (v7) or use @babel/preset-env.
affects: >=0.0.0
breakingOptions 'useBuiltIns' was removed in favor of 'loose' and 'extends' options.fixUse { loose: true, extends: true } instead of useBuiltIns. affects: <1.0.0 (if applicable)
gotchaPlugin does not include destructuring transform; if you need full destructuring support, you must add transform-es2015-destructuring separately.fixAdd 'transform-es2015-destructuring' to your Babel plugins list.
affects: >=0.0.0
gotchaThe 'extends' option uses Object.assign if available; ensure your target environment supports it or use a polyfill.fixAdd babel-plugin-transform-object-assign or include a Object.assign polyfill.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Requires Babel "^6.0.0-0", but was loaded with "7.x.x".
Using Babel 7 with a Babel 6 plugin.
fixUse @babel/plugin-proposal-object-rest-spread or @babel/preset-env.
SyntaxError: Unexpected token '...'
Object rest/spread not transformed because plugin missing or not configured.
fixEnsure babel-plugin-object-rest-spread is in your .babelrc plugins array.
ReferenceError: _objectWithoutProperties is not defined
Generated code uses helper that wasn't provided.
fixAdd 'babel-plugin-transform-runtime' or include 'babel-runtime' if using loose mode with extends:false.
Audit
Dependencies
babel-runtimeoptionalruntime helpers for extended object spread