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

Support async/await #327

Merged
merged 2 commits into from
Aug 2, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions config/babel.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ module.exports = {
babelrc: false,
cacheDirectory: true,
presets: [
'babel-preset-es2015',
'babel-preset-es2016',
'babel-preset-react'
].map(require.resolve),
require.resolve('babel-preset-es2015'),
require.resolve('babel-preset-es2016'),
require.resolve('babel-preset-react')
],
plugins: [
'babel-plugin-syntax-trailing-function-commas',
'babel-plugin-transform-class-properties',
'babel-plugin-transform-object-rest-spread'
].map(require.resolve).concat([
require.resolve('babel-plugin-syntax-trailing-function-commas'),
require.resolve('babel-plugin-transform-async-to-generator'),
require.resolve('babel-plugin-transform-class-properties'),
require.resolve('babel-plugin-transform-object-rest-spread'),
[require.resolve('babel-plugin-transform-runtime'), {
helpers: false,
polyfill: false,
regenerator: true
}]
])
]
};
20 changes: 10 additions & 10 deletions config/babel.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
module.exports = {
babelrc: false,
presets: [
'babel-preset-es2015',
'babel-preset-es2016',
'babel-preset-react'
].map(require.resolve),
require.resolve('babel-preset-es2015'),
require.resolve('babel-preset-es2016'),
require.resolve('babel-preset-react')
],
plugins: [
'babel-plugin-syntax-trailing-function-commas',
'babel-plugin-transform-class-properties',
'babel-plugin-transform-object-rest-spread',
'babel-plugin-transform-react-constant-elements',
].map(require.resolve).concat([
require.resolve('babel-plugin-syntax-trailing-function-commas'),
require.resolve('babel-plugin-transform-async-to-generator'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, is there a reason we use transform-async-to-generator to first transform async functions to generators and then regenerator to transform them to ES5? (Regenerator can also transform async functions directly, in which case the async-to-generator won't be needed.)

I've tested the Regenerator-only solution with following config:

    require.resolve('babel-plugin-syntax-async-functions'),
    [require.resolve('babel-plugin-transform-regenerator'), {
      asyncGenerators: false,
      generators: true,
      async: true
    }],

and it compiled to more or less the same code except it uses only the regenerator runtime and not the _asyncToGenerator helper from Babel. I don't know, if there are some minor differences in the runtime behaviour of these alternatives.

If you want to switch, I can send a pull request with this config I have.

P.S. It's very cool to have async/await supported by create-react-app! This was the reason I had to eject my config and I've been planning to make a PR to add them, but you beat me to it 😎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, PR would be welcome. I had no idea what’s the right way to integrate this. 😄

require.resolve('babel-plugin-transform-class-properties'),
require.resolve('babel-plugin-transform-object-rest-spread'),
require.resolve('babel-plugin-transform-react-constant-elements'),
[require.resolve('babel-plugin-transform-runtime'), {
helpers: false,
polyfill: false,
regenerator: true
}]
])
]
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"babel-jest": "14.1.0",
"babel-loader": "6.2.4",
"babel-plugin-syntax-trailing-function-commas": "6.8.0",
"babel-plugin-transform-async-to-generator": "6.8.0",
"babel-plugin-transform-class-properties": "6.11.5",
"babel-plugin-transform-object-rest-spread": "6.8.0",
"babel-plugin-transform-react-constant-elements": "6.9.1",
Expand Down