Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Object Rest Spread by default #1835

Merged
merged 5 commits into from Aug 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions 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 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem like the right place for this but I'm not sure where would be a better place to put this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine here, but than you should probably remove it from JSAsset.js as now it probably runs it twice...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On sidenote though, this would also run over node_modules, not sure if that's intended

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine here, but than you should probably remove it from JSAsset.js as now it probably runs it twice...

The one in JSAsset.js seems to only be used for parser options. Inspecting the plugins array we get from getEnvPlugins and it does not contain babel-plugin-transform-object-rest-spread

On sidenote though, this would also run over node_modules, not sure if that's intended

That is what I want since npm modules are now starting to use this feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but babylon runs before the other transforms to create the ast, so this would run twice, at different places, but it'll still run twice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks.

// add it.
plugins.push([
require('babel-plugin-transform-object-rest-spread'),
{useBuiltIns}
]);

envCache.set(key, plugins);
return plugins;
}
Expand Down
7 changes: 7 additions & 0 deletions test/integration/object-rest-spread/object-rest-spread.js
@@ -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 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