Skip to content

Commit

Permalink
Enable Object Rest Spread by default (#1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
arv authored and DeMoorJasper committed Aug 11, 2018
1 parent ad5fcd6 commit edb9ba2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/parcel-bundler/package.json
Expand Up @@ -20,6 +20,7 @@
"babel-core": "^6.25.0",
"babel-generator": "^6.25.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-template": "^6.26.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/core/parcel-bundler/src/transforms/babel.js
Expand Up @@ -265,6 +265,14 @@ async function getEnvPlugins(targets, useBuiltIns = false) {
{},
{targets, modules: false, useBuiltIns: useBuiltIns ? 'entry' : false}
).plugins;

// babel-preset-env version 6.x does not cover object-rest-spread so always
// add it.
plugins.push([
require('babel-plugin-transform-object-rest-spread'),
{useBuiltIns}
]);

envCache.set(key, plugins);
return plugins;
}
Expand Down
@@ -0,0 +1,7 @@
var x = {a: 'a', b: 'b'};
var {a: y, ...ys} = x;
var z = {y, ...ys};

export default function () {
return {x, y, z, ys};
}
17 changes: 17 additions & 0 deletions packages/core/parcel-bundler/test/javascript.js
Expand Up @@ -28,6 +28,23 @@ describe('javascript', function() {
assert.equal(output.default(), 3);
});

it('should produce a basic JS bundle with object rest spread support', async function() {
let b = await bundle(
__dirname + '/integration/object-rest-spread/object-rest-spread.js'
);

assert.equal(b.assets.size, 1);

let output = await run(b);
assert.equal(typeof output, 'object');
assert.equal(typeof output.default, 'function');

let res = output.default();
assert.equal(res.y, 'a');
assert.deepEqual(res.z, {y: 'a', b: 'b'});
assert.deepEqual(res.ys, {b: 'b'});
});

it('should bundle node_modules on --target=browser', async function() {
let b = await bundle(__dirname + '/integration/node_require/main.js', {
target: 'browser'
Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Expand Up @@ -543,6 +543,10 @@ babel-plugin-syntax-jsx@^6.8.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"

babel-plugin-syntax-object-rest-spread@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5"

babel-plugin-syntax-trailing-function-commas@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3"
Expand Down Expand Up @@ -737,6 +741,13 @@ babel-plugin-transform-exponentiation-operator@^6.22.0:
babel-plugin-syntax-exponentiation-operator "^6.8.0"
babel-runtime "^6.22.0"

babel-plugin-transform-object-rest-spread@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz#0f36692d50fef6b7e2d4b3ac1478137a963b7b06"
dependencies:
babel-plugin-syntax-object-rest-spread "^6.8.0"
babel-runtime "^6.26.0"

babel-plugin-transform-react-jsx@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-jsx/-/babel-plugin-transform-react-jsx-6.24.1.tgz#840a028e7df460dfc3a2d29f0c0d91f6376e66a3"
Expand Down

0 comments on commit edb9ba2

Please sign in to comment.