Skip to content

Commit

Permalink
Babel Preset Default: Avoid disabling regenerator option (#14130)
Browse files Browse the repository at this point in the history
* Babel Preset Default: Remove redundant (defaulted) corejs option

* Scripts: Assign Babel runtime regenerator as externals in Webpack config

* Babel Preset Default: Avoid disabling regenerator option
  • Loading branch information
aduth authored and youknowriad committed Mar 20, 2019
1 parent 96abd75 commit a1b1f55
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
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 (2019-03-06)

## 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',
},
wordpressExternals,
];
Expand Down

0 comments on commit a1b1f55

Please sign in to comment.