Skip to main content

7.19.0 Released: Stage 3 decorators and more RegExp features!

ยท 3 min read

We just published Babel 7.19.0!

This release updates our implementation of the decorators proposal, which reached Stage 3 in March. It also includes support for the new duplicate named capturing groups proposal for regular expressions.

You can read the whole changelog on GitHub.

If you or your company want to support Babel and the evolution of JavaScript, but aren't sure how, you can donate to us on our Open Collective and, better yet, work with us on the implementation of new ECMAScript proposals directly! As a volunteer-driven project, we rely on the community's support to fund our efforts in supporting the wide range of JavaScript users. Reach out at team@babeljs.io if you'd like to discuss more!

Highlightsโ€‹

New default valuesโ€‹

Given the stabilization of the decorators and Record and Tuple proposal, we set some default values for their parser plugin options:

  • decorators/@babel/plugin-proposal-decorators's decoratorsBeforeExport now defaults to false;
  • recordAndTuple/@babel/plugin-proposal-record-and-tuple's syntaxType option now defaults to hash.

These options will be removed in Babel 8.

Stage 3 decorators (#14836)โ€‹

The decorators proposal was promoted to Stage 3 with some minor but observable changes. You can enable the new version using the "version": "2022-03" option of @babel/plugin-proposal-decorators:

babel.config.json
{
"plugins": [
["@babel/plugin-proposal-decorators", {
"version": "2022-03"
}]
]
}

If you are migrating from the 2021-12 version, the following breaking changes might affect you:

  • the initialize method of the object returned by accessor decorators has been renamed to init;
  • the isPrivate and isStatic properties of the context parameter received by the decorators (the second one) have been renamed to private and static;
  • the context parameter now always has an access property, regardless of the decorated element type;
  • support for metadata (getMetadata/setMetadata) has been removed and postponed to a future proposal;
  • @(expression)()-style decorators are disallowed, and you must use @(expression());
  • decorators are applied in the following order, instead of in a single pass:
    1. static method decorators
    2. proto method decorators
    3. static field decorators
    4. instance field decorators
    5. class decorators.

If you are migrating from an older version of the proposal, we suggest reading the full README. ๐Ÿ˜‰

๐Ÿ’ก TypeScript plans to implement this version of the proposal. After almost a decade, it will be possible to write decorators without worrying if they will be compiled by Babel or tsc!

RegExp duplicate named capturing groups (#14805)โ€‹

Babel now supports the RegExp duplicate named capturing groups proposal, which allows re-using the same group name in alternative RegExp branches:

JavaScript
const dateRE = /(?<year>\d\d\d\d)-(?<month>\d\d)|(?<month>\d\d)-(?<year>\d\d)/;

console.log("2022-12".match(dateRE).groups); // { year: "2022", month: "12" }
console.log("12-2022".match(dateRE).groups); // { year: "2022", month: "12" }

You can enable this proposal using the @babel/plugin-proposal-duplicate-named-capturing-groups-regex plugin:

babel.config.json
{
"plugins": ["@babel/proposal-duplicate-named-capturing-groups-regex"]
}

Babel relies on different third-party packages to transform regular expressions: this is possible thanks to the maintainers of regjsparser, regjsgen and regexpu-core who took time to review our pull requests!