Babel: Babel 8 Release Plan

Created on 21 Nov 2019  路  39Comments  路  Source: babel/babel

We plan to release a new major version in 2021 (milestone).

This release won't have all the migration pain which there was while migrating from Babel 5 to Babel 6 and then from Babel 6 to Babel 7. We plan to only make a _few_ breaking changes, and provide an easy migration strategy for each of them. Because of this, you won't see ~80 prereleases like we did in for Babel 7.0.0, but we plan to only release a few of them.

Babel 8.0.0 will _only_ contain breaking changes: we will release a minor version the same day, containing all the bug fixes and new features that would otherwise be released in 8.0.0.

This document is still a work in progress, but you can already start by applying the suggested migration strategies to your own codebase.

  • Compilation breaking changes

    • [x] [Don't remove uninitialized class fields when using Flow/TS](https://github.com/babel/babel/issues/10039) (pr for flow: #10120, pr for TS: #11114)
    • Area: Flow and TypeScript transforms
    • Impact: High (only for flow and TypeScript users)
    • Migration:
      You can use the new declare syntax, introduced in TypeScript 3.7 (Babel 7.7) and in Flow 0.120 (Babel 7.9), if you don't want fields to be initialized to undefined:

      class A {
      foo: string | void; // initialized to undefined
      declare bar: number; // type-only
      }
      

      Note that while this syntax is enabled by default in @babel/parser when using the typescript or flow plugins, if you are using Babel to remove type annotations you must enable the allowDeclareFields option:

      // TypeScript
      {
      presets: [
        ["@babel/typescript", { "allowDeclareFields": true }]
      ]
      }
      
      // Flow
      {
      presets: [
        ["@babel/flow", { "allowDeclareFields": true }]
      ]
      }
      
    • [x] [Disallow sequence expressions inside JSX attributes](https://github.com/babel/babel/issues/8604) (pr: #8787)

    • Area: JSX, @babel/parser
    • Impact: Low
    • Migration: If you are using them, you can already wrap them in parentheses:
      js <div key={foo, bar}></div> // Invalid <div key={(foo, bar)}></div> // Valid
    • [x] [Disallow } and > in JSX text](https://github.com/babel/babel/issues/11042) (pr: https://github.com/babel/babel/pull/11046)
    • Area: @babel/parser with JSX
    • Impact: Low
    • Migration: You can use {'}'} and {'>'} instead.
    • Notes: This is technically a bug fix becase the specification already forbids them. However, we have chosen to postpone it until Babel 8 because it could break someone's code.
    • [x] [Transforms JSX spread properties using object spread](https://github.com/babel/babel/issues/9652) (pr: #11141, docs: website#2289)
    • Area: JSX
    • Impact: Medium
    • Migration: You can already have this behavior by using the useSpread option in Babel 7.7.0. If your code needs to run in an environment which doesn't support object spread, you can either use @babel/preset-env (recommended) or @babel/plugin-proposal-object-rest-spread. If you want to transpile Object.assign down to Babel's _extends helper (which is the current default behavior) you also need to enable @babel/plugin-transform-object-assign.

    • [x] [Use the new JSX implementation by default](https://github.com/babel/babel/pull/11154#issuecomment-591188203) (pr: #11436, docs: website#2289)

    • Area: JSX
    • Impact: High
    • Migration: Starting from Babel 7.9.0, you can pass the runtime: "classic" option to @babel/preset-react or @babel/plugin-transform-react-jsx to be explicit about your usage of createElement (or the equivalent function in other libraries).
      If you are using a modern enough version of React or Preact, you can already use the new runtime: "automatic" implementation.

    • [x] Parse JSX elements when both the JSX and TS plugins are enabled, and throw an error when both Flow and TS are enabled (pr: #11316)

    • Area: JSX, TypeScript
    • Impact: Low
    • Migration: If you don't want <Foo> to be parsed as a JSX element, but as a TypeScript typecast, you can disable the JSX plugin.
    • Note: The current behavior is that JSX parsing is only handled by the isTSX option of the TypeScript plugin. We are also removing this option. We think that having the JSX plugin control JSX parsing is less confusing for our users.
  • Configuration breaking changes

    • [ ] [Require @babel/plugin-proposal-dynamic-import when transforming import() to SystemJS](https://github.com/babel/babel/blob/78cd63d9cfcd96e6a151c58fed392c3ee757d861/packages/babel-plugin-transform-modules-systemjs/src/index.js#L183-L185)
    • Area: @babel/plugin-transform-modules-systemjs
    • Impact: Medium
    • Migration: Add @babel/plugin-proposal-dynamic-import to your config: you can already do it in Babel 7. If you are using @babel/preset-env, you don't need to do anything.
    • Notes: All the other plugins which support dynamic import (transform-modules-commonjs and transform-modules-amd) require the separate plugin since it was introduced. We couldn't change it for transform-modules-systemjs because that package did already support dynamic import.
    • [ ] [Only change browserslist defaults if no config file exists](https://github.com/babel/babel/issues/9962) (pr: https://github.com/babel/babel/pull/10897 )
    • Area: @babel/preset-env
    • Impact: Low
    • Migration: If you are already using targets or have a .browserslist config file, this change won't affect you. Otherwise, you'll probably be fine with the new behavior (which supports these browsers). If you still need to enable every possible plugin, you can already enable the forceAllTransforms option.
    • [x] Remove uglify target (pr: #10895, docs: website#2290)
    • Area: @babel/preset-env
    • Impact: Low
    • Migration: The uglifyjs target had been deprecated since 7.0.0-beta.0, if you still need this, you can enable the forceAllTransforms option.
    • [ ] [Move root AMD/UMD/SystemJS options to be plugin/preset options](https://github.com/babel/babel/issues/5473) (pr: https://github.com/babel/babel/pull/11194)
    • Area: @babel/core, @babel/cli, @babel/plugin-transform-modules-amd, @babel/plugin-transform-modules-umd, @babel/plugin-transform-modules-systemjs
    • Impact: Medium
    • Migration: When upgrading to Babel 8, you'll move to modify your config and pass these options to the correct plugin or preset.
      If you are passing these options using the cli, you'll need to create a configuration file.
    • [x] [Drop support for core-js 2](https://github.com/babel/babel/issues/10746#issuecomment-573402372) (pr: #11751)
    • Area: @babel/preset-env, @babel/plugin-transform-runtime, @babel/compat-data
    • Impact: High
    • Migration: You can already change your config to use core-js@3. Don't forget to npm install it!
    • Notes:

      1. When useBuiltIns is enabled, the default core-js version is now 3.6 instead of 2

      2. If you still need core-js@2 support, you can use babel-plugin-polyfill-core-js2.

    • Add mandatory version option to the decorators plugins, and merge the two plugins in @babel/parser.
  • API breaking changes

    • [ ] [Bump Node Support to >=12.19](https://github.com/babel/babel/issues/9981) (pr for >= 10: #10747)
    • Area: Every package
    • Impact: Medium
    • Notes: The 10.x LTS is still a maintained, but its EOL is at the beginning of 2021.
    • [ ] Ship Babel as native ECMAScript modules
    • Area: Every package
    • Impact: Medium
    • Notes: Native modules are supported in Node.js 12!
    • [ ] Disallow using babel.transform, babel.transformFile, babel.transformFromAst, babel.parse, babel.loadOptions and babel.loadPartialConfig synchronously (pr: #11110)
    • Area: @babel/core
    • Impact: Medium
    • Migration: You can use babel.transformSync, babel.transformFromAstSync and babel.transformFileSync, supported since version 7.0.0. babel.parseSync, babel.loadOptionsSync and babel.loadPartialConfigSync will be introduced in v7.8.0.
    • [ ] [Don't generate TSParenthesizedType unless createParenthesizedExpression is enabled](https://github.com/babel/babel/issues/9546) (pr: #11200)
    • Area: @babel/parser
    • Impact: Low
    • Migration: If you need informations about parentheses, you can already enable the createParenthesizedExpression parser option (supported since Babel 7.4.0)
    • [x] [Remove t.jSX* and t.tS* builder aliases](https://github.com/babel/babel/issues/6989) (pr: #6993)
    • Area: @babel/types
    • Impact: Low
    • Migration: Use t.jsx* and t.ts* instead, which have been supported since Babel 7.0.0
    • [ ] [Reject invalid identifiers in t.identifier builder](https://github.com/babel/babel/pull/10621) (pr was reverted)
    • Area: @babel/types
    • Impact: Medium
    • Notes: Breaks metro bundler as of Nov 2019 (#10645)
    • [x] [Remove jsonCompatibleStrings generator option](https://github.com/babel/babel/issues/9943) (pr: #9958)
    • Area: @babel/generator
    • Impact: Medium
    • Migration: @babel/generator allows to specify options for jsesc, the library used to escape printed values.
      If you are using the jsonCompatibleStrings option, you can replace it with jsescOption: { json: true }.
    • [ ] [Disallow useBuiltIns: 0 when transforming JSX](https://github.com/babel/babel/pull/10572#discussion_r336564779) (pr: #10927)
    • Area: @babel/plugin-transform-react-jsx, @babel/preset-env
    • Impact: Low
    • Migration: Use useBuiltIns: false instead.
  • Misc breaking changes

    • [ ] Bump peer dependency on @babel/core to ^8.0.0
    • Area: Every package
    • Impact: None if you update every @babel/* package
    • [ ] [ESM runtime helper files should have the .mjs extension
      ](https://github.com/babel/babel/issues/8462)
    • Area: @babel/runtime, @babel/runtime-corejs2, @babel/runtime-corejs3
    • Impact: Medium
    • Notes: ES Modules are now unflagged (nodejs/node#29866), and .js modules don't work with native import unless our package.json specifies type: "module" (which will break cjs helpers).
    • [ ] [Change the format of CommonJS helpers in @babel/runtime](https://github.com/babel/babel/issues/10746#issuecomment-561510965)
    • Area: @babel/runtime, @babel/runtime-corejs2, @babel/runtime-corejs3
    • Impact: Low
    • Notes: This will only affect you if you are using @babel/runtime 7.x with @babel/plugin-transform-runtime 8.x (or the other way around), which woudln't be supported anyway.
    • [ ] Disallow importing internal files of the different packages (pr: #10850)
    • Area: Every package
    • Impact: High
    • Notes: This will break _at least_ vue-cli (cc @sodatea) and ember-cli-babel [2] (cc @rwjblue). We will provide targets-parser as a separate helper in v7.8.0.
      :warning: If anyone else is relying on internal Babel files, please let us know!
    • [x] Output non-ASCII characters as-is in string literal (pr: #11384)
    • Area: @babel/generator
    • Impact: High only if you are manually calling the babel.transform API and your server is not serving js files in the utf8 encoding.
    • Notes: If you are using any one of @babel/cli, WebPack, Rollup, create-react-app or other Node.js powered bundlers, the transformed code is always encoded with utf-8. That said, this issue probably won't affect your app.
    • Mitigation: Ensure your server is always serving js files in the utf8 encoding. If you can not control the server output, use <script charset="utf-8" src="your-app.js"></script> in the html files. You may also restore to the Babel 7 behaviour by
      js { generatorOpts: { jsescOption: { minimal: false } } }
  • Other _possibly_ breaking changes

    • [ ] [Remove ts type imports on Program:exit](https://github.com/babel/babel/issues/9991) (pr: #10009)
    • Area: @babel/plugin-transform-typescript
    • Impact: Low
    • [ ] [Allow skipped NodePaths to be requeued](https://github.com/babel/babel/blob/43b623c1f1e86e6fb86cae8d955a84fd924380a4/packages/babel-traverse/src/path/context.js#L241-L247)
    • Area: @babel/traverse
    • Impact: Low
    • Notes: This is actually a bugfix, but it causes an infinite loop in the tdz implementation of @babel/plugin-transform-block-scoping
    • [ ] Look for comments containing "Babel 8" in the source code
    • Area: Every package
    • Impact: Low
    • Notes: Most of those comments are just for internal dependencies between packages. Any significant change will have a dedicated point in this list of breaking changes.

Related: https://github.com/babel/babel/issues/10752


Note for contributors

We are currently developing Babel 8 in the next-8-dev branch. We will periodically merge master in next-8-dev.
We are also maintaining a separate branch, next-8-rebased to clearly show the commits specifically related to Babel 8.
PRs for Babel 8 should be opened to the next-8-dev branch.

umbrella 鈽傦笍

Most helpful comment

Can we also take the chance to rename now-standard features still listed a proposal-*?

  • babel-plugin-proposal-async-generator-functions
  • babel-plugin-proposal-dynamic-import
  • babel-plugin-proposal-export-namespace-from
  • babel-plugin-proposal-json-strings
  • babel-plugin-proposal-nullish-coalescing-operator
  • babel-plugin-proposal-object-rest-spread
  • babel-plugin-proposal-optional-catch-binding
  • babel-plugin-proposal-optional-chaining
  • babel-plugin-proposal-unicode-property-regex

All 39 comments

Remove ts type imports on Program:exit

will this allow to generate .d.ts files?

@TrejGun It is totally unrelated I think. I'd be happy to hear more about it on our Slack!

Will 8.x be faster than 7.x when building my own project?

No. Version 8.0 will only contain breaking changes, so if there are any performance improvements that we can make they will also be included in 7.x.

I would like to propose a breaking change.

I believe that @babel/runtime helpers should not get special treatment when transpiled to CJS - at least not for their export shape (used requires etc can still be optimized). I propose such output:

+"use strict";
+exports.__esModule = true;
+exports.default = _toPropertyKey;

-var _typeof = require("../helpers/typeof");
+var _typeof = require("../helpers/typeof").default;

-var toPrimitive = require("./toPrimitive");
+var toPrimitive = require("./toPrimitive").default;

function _toPropertyKey(arg) {
  var key = toPrimitive(arg, "string");
  return _typeof(key) === "symbol" ? key : String(key);
}

-module.exports = _toPropertyKey;

With such ESM-compatible output we could try to explore removing useESModules option from @babel/plugin-transform-runtime because it's possible to create a "proxy" package.json that would allow bundlers & node to pick up the correct version of a particular helper on their own using a single path (that would be inserted by transform runtime). The directory structure could look smth like this

helpers/toPropertyKey/package.json
helpers/toPropertyKey/toPropertyKey.js
helpers/toPropertyKey/toPropertyKey.mjs

with package.json being:

{
  "name": "@babel/runtime/helpers/toPropertyKey",
  "private": true,
  "type": "module",
  "main": "./toPropertyKey.cjs.js",
  "module": "./toPropertyKey.js",
  "exports": {
    ".": {
      "require": "./toPropertyKey.cjs.js",
      "default": "./toPropertyKey.js"
    }
  }
}

@babel/preset-env using core-js@2 by default. Can @bable/preset-env@8 using core-js@3 only?

Yeah, this is a good idea!
@zloirock WDYT about dropping support for core-js@2?

Yes, core-js@2 support should be dropped and the version of core-js should be required argument with useBuiltIns in preset-env. Maybe it could be good also to enforce specifying of minor core-js version.

Why it should be dropped - copy-paste from the draft of one post:

core-js@3 was published 10 months ago - I hoped that this is enough to update. However, core-js@2 still is used more often than core-js@3 - if some dependencies depend on core-js@2, users don't wanna have some copies of core-js in the bundle. However, we should kill core-js@2 ASAP. The main reason is even not some bugs, it's... V8 (de)optimizations - even if nothing is polyfilled. WTF? Now, if V8 saw the usage of some non-often used features (like @@species pattern), for example, in the features detection - V8 always will use the non-optimized version of a method that theoretically could use it. In core-js@2, that affects regexes, iterators, some array methods, typed arrays, promises, etc... Sometimes that causes ~100x performance degradation, let's say thanks to V8. At this moment, V8 is the most popular JS engine, so it's a complex of critical issues. Workarounds for a big part of those deoptimizations were added in [email protected], for remaining - at the latest patch releases. I don't see any reason to spent many days fixing those (and other) issues in the obsolete version.

Hey. I would love to contribute to Babel 8. What are some easy features I can work on? I think I can work on :-

Look for comments containing "Babel 8" in the source code
Area: Every package
Impact: Low
Notes: Most of those comments are just for internal dependencies between packages. Any significant change will have a dedicated point in this list of breaking changes.

Are there any other issues I can contribute to and help?

Another good one could be https://github.com/babel/babel/issues/9546, which would give you the chance to dig into @babel/parser's internals.
Or maybe Disallow using babel.transform, babel.transformFile, babel.transformFromAst, babel.parse, babel.loadOptions and babel.loadPartialConfig synchronously, which is probably a bit easier.
If you prefer, Transforms JSX spread properties using object spread involves removing the useSpread option and making it the default behavior.

If you want to work on the TODOs left in the comments containing "Babel 8", please don't resolve all of them in a single PR but keep separate changes in different PRs.

Disallow using babel.transform, babel.transformFile, babel.transformFromAst, babel.parse, babel.loadOptions and babel.loadPartialConfig synchronously
Area: @babel/core
Impact: Medium
Migration: You can use babel.transformSync, babel.transformFromAstSync and babel.transformFileSync, supported since version 7.0.0. babel.parseSync, babel.loadOptionsSync and babel.loadPartialConfigSync will be introduced in v7.8.0.

Shoud I just delete the given functions? Or am I misunderstanding the requirements?

Currently they behave asynchronously if you pass them a callback, otherwise they behave synchronously. Only the callback-based version should be allowed.

For whoever is watching this issue:
I just added the Use the new JSX implementation by default section.

Update: I added the Parse JSX elements when both the JSX and TypeScript plugins are enabled section.

Will the babel 8 release also include default handling of .ts and .tsx extensions? (see #8652). It's tagged with the milestone but this issue doesn't mention it.

Can we also take the chance to rename now-standard features still listed a proposal-*?

  • babel-plugin-proposal-async-generator-functions
  • babel-plugin-proposal-dynamic-import
  • babel-plugin-proposal-export-namespace-from
  • babel-plugin-proposal-json-strings
  • babel-plugin-proposal-nullish-coalescing-operator
  • babel-plugin-proposal-object-rest-spread
  • babel-plugin-proposal-optional-catch-binding
  • babel-plugin-proposal-optional-chaining
  • babel-plugin-proposal-unicode-property-regex

Currently they behave asynchronously if you pass them a callback, otherwise they behave synchronously. Only the callback-based version should be allowed.

How would such change be compatible with babel-register? Unless I'm missing something, require.extensions is synchronous.

EDIT: nevermind. just noticed the separate sync versions are kept.

Hello! Thanks everyone for your hard work on Babel (8). I wanted to ask about your upgrade strategy. To this day, Babel 6 is still found in many dependency trees of projects that use Babel 7 just because some tools haven't been (properly) upgraded. With many tools pulling in Babel 7, what is your recommendation on adopting Babel 8 to avoid mixing Babel 7 and 8 (and 6)?

It seems that due to semver there will be an awkward period of time when some tooling will be updated to use Babel 8 and some won't, likely forcing projects to use both in their projects or hold off on upgrading for a long time altogether.

In the original post it was said that there will be a Babel 7 release with all the non-breaking changes, which is awesome! Is there any consideration to keep the version gap to a minimum? One approach could be further updates to Babel 7 that enable the breaking changes as opt-in configuration options and I'm sure there are others.

It's not always possible, but in most cases we are making it so that something that works with Babel 8 can also work with Babel 7. Sometimes it works "out of the box" (for example for Disallow using babel.transform, babel.transformFile, babel.transformFromAst, babel.parse, babel.loadOptions and babel.loadPartialConfig synchronously), other times by enabling the corresponding option (for example, Transforms JSX spread properties using object spread).

Keep in mind the impact of duplicating Babel 6 and Babel 7 was lower because the package names changed from the babel- prefix to using the @babel org. When Babel 8 comes out, it is likely that through hoisting rules every tool will pull in its own copy of Babel 7 or 8 within its sub-node_modules folder.

Babel 6 had a "bridge" mode that allowed installing version 7 of some packages like babel-core bridging to @babel/core.

Please add ts and tsx as default extensions. I spent a few hours to figure out babel-node need specifying extensions for it to work when importing ts files. @peterjuras

I鈥檓 beginning to rethink our plan to release the @babel/eslint-* packages with Babel 8. I believe we鈥檙e ready to release those packages now - any further necessary changes will become apparent with the myriad of integrations in the community. If we were to release these packages in the next v7 line release, we could start getting immediate feedback. One other possible benefit is that if we need to make any breaking changes we can get them out in the v8 release.

Thoughts?

The next ESLint release has been in the prerelease state for too long. If it's already compatible with ESLint 7, I would be ok with releasing it in Babel 7.

Question: could the official upgrade guide suggest how library authors can make their code compatible with both Babel 7 and 8, and then recommend them to use a semver range that works with either 7 or 8 until 7 is dropped at a later time?

I believe that could significantly reduce the gap in time when some tools are upgraded but others aren't.

Yes!

  1. We will check which Babel 7 plugins in this repository work with @babel/core 8, and relax their semver ranges
  2. The @babel/core API (used by Babel integrations such as Jest, Parcel, the webpack and rollup plugins, etc) will work both with Babel 7 and Babel 8. There is a breaking change (https://github.com/babel/babel/pull/11110), but the alternative already works with Babel 7.
  3. If an open-source plugin author needs help to make their plugin work both with Babel 8 and Babel 7, I am happy to help on Slack (and probably also the rest of the team).

Thanks for the reply @nicolo-ribaudo, that's really exciting as that will ease the transition 馃憤

Was thinking through some ideas on how to make the migration easier (not for 1 project for the ecosystem) with @nicolo-ribaudo and @existentialism and I'll post an idea we had here: https://hackmd.io/lAEuzTXzQl6fAir01YgfkQ. (this is in addition to writing up a guide to migrate and codemods where possible)

Basically was thinking we could enable the breaking changes in a 7.x patch under an environmental flag, run like BABEL_8_BREAKING babel or with whatever integration so that any library/plugin can opt-into trying that locally and publish new versions ahead of us releasing anything. We would have to manage the if branches in the code and even tests + cleanup after but maybe that can help ease?

Other ideas welcome.

@hzoo I think that's a great idea, thank you for thinking about this.

How about drop support for core-js 3 (in preset-env). We have babel-plugin-polyfill-corejs3 now.

That was one of my goals when I started working on the polyfill packages, but we should first do https://github.com/babel/rfcs/pull/2

When will babel 8 release?

@TrySound It is: you can check JSXTextCharacter at https://facebook.github.io/jsx/.

Would be nice to know when we can expect Babel 8. The OP says that it'll come out in 2020, but the year is soon coming to a close and there's no news yet.

Who else is pumped for the chokidar dependency bump? :D

@fabis94 Sorry for the lack of communication about a precise schedule. My hope is to release Babel 8 alongside with 7.13 (so in about 2 months), since there isn't much left to do. However, please don't take this as an hard deadline since anything could happen :pray:

@WillBeebe Starting from Babel 7.12.0, it will use chokidar@3 if you are using a modern Node.js version :wink: https://github.com/babel/babel/pull/11560

Any updates regarding this?

Yes!
We wanted to work on this in a separate branch next-8-dev/next-8-rebased, but we found out that it was _really_ slowing us down. We are now starting to add these Babel 8 changes to main, so that it's easier for us to work on them and hopefully will help us finish this release in a reasonable time.

Was this page helpful?
0 / 5 - 0 ratings