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

Babel Preset Default: Avoid disabling regenerator option #14130

Merged
merged 3 commits into from
Mar 4, 2019
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
8 changes: 6 additions & 2 deletions packages/babel-preset-default/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
## 4.0.0 (Unreleased)

## Breaking Change
### Breaking Change

- Removed `babel-core` dependency acting as Babel 7 bridge ([#13922](https://github.com/WordPress/gutenberg/pull/13922). Ensure all references to `babel-core` are replaced with `@babel/core` .
- Preset updated to include `@wordpress/babel-plugin-import-jsx-pragma` plugin integration ([#13540](https://github.com/WordPress/gutenberg/pull/13540)).

### Bug Fix

- The runtime transform no longer disables [the `regenerator` option](https://babeljs.io/docs/en/babel-plugin-transform-runtime#regenerator). This should resolve issues where a file generated using the preset would assume the presence of a `regeneratorRuntime` object in the global scope. While this is not considered a breaking change, you may be mindful to consider that with transformed output now explicitly importing the runtime regenerator, bundle sizes may increase if you do not otherwise mitigate the additional import by either (a) overriding the option in your own Babel configuration extensions or (b) redefining the resolved value of `@babel/runtime/regenerator` using a feature like [Webpack's `externals` option](https://webpack.js.org/configuration/externals/).

## 3.0.0 (2018-09-30)

## Breaking Change
### Breaking Change

- The configured `@babel/preset-env` preset will no longer pass `useBuiltIns: 'usage'` as an option. It is therefore expected that a polyfill serve in its place, if necessary.

Expand Down
2 changes: 0 additions & 2 deletions packages/babel-preset-default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ module.exports = function( api ) {
} ],
'@babel/plugin-proposal-async-generator-functions',
! isTestEnv && [ '@babel/plugin-transform-runtime', {
corejs: false, // We polyfill so we don't need core-js.
helpers: true,
regenerator: false, // We polyfill so we don't need regenerator.
useESModules: false,
} ],
].filter( Boolean ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`Babel preset default transpilation works properly 1`] = `
"import _asyncToGenerator from \\"@babel/runtime/helpers/asyncToGenerator\\";
import _regeneratorRuntime from \\"@babel/runtime/regenerator\\";
import _awaitAsyncGenerator from \\"@babel/runtime/helpers/awaitAsyncGenerator\\";
import _wrapAsyncGenerator from \\"@babel/runtime/helpers/wrapAsyncGenerator\\";
describe('Babel preset default', function () {
Expand All @@ -12,8 +13,8 @@ describe('Babel preset default', function () {
function _foo() {
_foo = _wrapAsyncGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
Expand All @@ -38,9 +39,9 @@ describe('Babel preset default', function () {
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee2() {
_regeneratorRuntime.mark(function _callee2() {
var generator;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
Expand Down
8 changes: 8 additions & 0 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ const externals = [
jquery: 'jQuery',
lodash: 'lodash',
'lodash-es': 'lodash',

// Distributed NPM packages may depend on Babel's runtime regenerator.
// In a WordPress context, the regenerator is assigned to the global
// scope via the `wp-polyfill` script. It is reassigned here as an
// externals to reduce the size of generated bundles.
//
// See: https://github.com/WordPress/gutenberg/issues/13890
'@babel/runtime/regenerator': 'regeneratorRuntime',
Copy link
Member

Choose a reason for hiding this comment

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

Given that all packages depend on @babel/runtime this seems like a very safe change 👍

},
wordpressExternals,
];
Expand Down