Skip to content

Commit

Permalink
Merge branch 'main' into import-attr-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 26, 2023
2 parents 5ca13f9 + 8cb0546 commit 8561e1a
Show file tree
Hide file tree
Showing 51 changed files with 496 additions and 223 deletions.
21 changes: 17 additions & 4 deletions _redirects
Expand Up @@ -64,12 +64,25 @@ https://babel.netlify.com/* https://babeljs.io/:splat 301!
/docs/plugins/minify-* /docs/babel-plugin-minify-:splat
/docs/plugins/external-helpers/ /docs/babel-plugin-external-helpers

/docs/en/babel-plugin-transform-async-generator-functions /docs/babel-plugin-proposal-async-generator-functions
/docs/en/babel-plugin-transform-class-properties /docs/babel-plugin-proposal-class-properties
# Plugins renamed from -proposal- to -transform-
/docs/babel-plugin-proposal-class-static-block /docs/babel-plugin-transform-class-static-block
/docs/babel-plugin-proposal-private-property-in-object /docs/babel-plugin-transform-private-property-in-object
/docs/babel-plugin-proposal-class-properties /docs/babel-plugin-transform-class-properties
/docs/babel-plugin-proposal-private-methods /docs/babel-plugin-transform-private-methods
/docs/babel-plugin-proposal-numeric-separator /docs/babel-plugin-transform-numeric-separator
/docs/babel-plugin-proposal-logical-assignment-operators /docs/babel-plugin-transform-logical-assignment-operators
/docs/babel-plugin-proposal-nullish-coalescing-operator /docs/babel-plugin-transform-nullish-coalescing-operator
/docs/babel-plugin-proposal-optional-chaining /docs/babel-plugin-transform-optional-chaining
/docs/babel-plugin-proposal-json-strings /docs/babel-plugin-transform-json-strings
/docs/babel-plugin-proposal-optional-catch-binding /docs/babel-plugin-transform-optional-catch-binding
/docs/babel-plugin-proposal-async-generator-functions /docs/babel-plugin-transform-async-generator-functions
/docs/babel-plugin-proposal-object-rest-spread /docs/babel-plugin-transform-object-rest-spread
/docs/babel-plugin-proposal-unicode-property-regex /docs/babel-plugin-transform-unicode-property-regex
/docs/babel-plugin-proposal-export-namespace-from /docs/babel-plugin-transform-export-namespace-from

# Legacy redirects
/docs/en/babel-plugin-transform-decorators /docs/babel-plugin-proposal-decorators
/docs/en/babel-plugin-transform-do-expressions /docs/babel-plugin-proposal-do-expressions
/docs/en/babel-plugin-transform-export-extensions /docs/babel-plugin-proposal-export-namespace
/docs/en/babel-plugin-transform-object-rest-spread /docs/babel-plugin-proposal-object-rest-spread

/docs/plugins/check-es2015-constants/ /docs/babel-plugin-check-es2015-constants
/docs/plugins/transform-es2015-constants /docs/babel-plugin-check-es2015-constants
Expand Down
2 changes: 1 addition & 1 deletion docs/cli.md
Expand Up @@ -158,7 +158,7 @@ npx babel --out-file script-compiled.js < script.js
Use the `--plugins` option to specify plugins to use in compilation

```sh title="Shell"
npx babel script.js --out-file script-compiled.js --plugins=@babel/proposal-class-properties,@babel/transform-modules-amd
npx babel script.js --out-file script-compiled.js --plugins=@babel/transform-class-properties,@babel/transform-modules-amd
```

### Using Presets
Expand Down
16 changes: 8 additions & 8 deletions docs/features-timeline.md
Expand Up @@ -442,18 +442,18 @@ This has a lot more changes since it was 2 years of pre-releases.
- Support TypeScript via `@babel/preset-typescript`
- Support JSX Fragments `<></>`
- Support a ton of TC39 proposals:
- [Unicode Property Regex](plugin-proposal-unicode-property-regex.md)
- [JSON Superset](plugin-proposal-json-strings.md)
- [Unicode Property Regex](plugin-transform-unicode-property-regex.md)
- [JSON Superset](plugin-transform-json-strings.md)
- [`new.target`](plugin-transform-new-target.md)
- [Class Private Instance Fields](plugin-proposal-class-properties.md) (`class A { #b = 2 }`)
- [Optional Catch Binding](plugin-proposal-optional-catch-binding.md) `try { throw 0 } catch { do() }`
- [Class Private Instance Fields](plugin-transform-class-properties.md) (`class A { #b = 2 }`)
- [Optional Catch Binding](plugin-transform-optional-catch-binding.md) `try { throw 0 } catch { do() }`
- [BigInt](plugin-syntax-bigint.md) (syntax only)
- [`import.meta`](plugin-syntax-import-meta.md) (syntax only) (`import.meta.url`)
- [Numeric Separators](plugin-proposal-numeric-separator.md) (`1_000`)
- [Numeric Separators](plugin-transform-numeric-separator.md) (`1_000`)
- [`function.sent`](plugin-proposal-function-sent.md)
- [Optional Chaining](plugin-proposal-optional-chaining.md) (`a?.b`)
- [Logical Assignment Operators](plugin-proposal-logical-assignment-operators.md) (`a &&= b; a ||= b`)
- [Nullish Coalescing Operator](plugin-proposal-nullish-coalescing-operator.md) (`a ?? b`)
- [Optional Chaining](plugin-transform-optional-chaining.md) (`a?.b`)
- [Logical Assignment Operators](plugin-transform-logical-assignment-operators.md) (`a &&= b; a ||= b`)
- [Nullish Coalescing Operator](plugin-transform-nullish-coalescing-operator.md) (`a ?? b`)
- [Pipeline Operator](plugin-proposal-pipeline-operator.md) (`a |> b`)
- [Throw Expressions](plugin-proposal-throw-expressions.md) (`() => throw new Error("a")`)
Expand Down
10 changes: 5 additions & 5 deletions docs/helper-compilation-targets.md
Expand Up @@ -198,9 +198,9 @@ Given browser targets `targets`, query the `compatData` whether plugin `name` is
module.exports = api => {
const targets = api.targets();
// The targets have native optional chaining support
// if `proposal-optional-chaining` is _not_ required
// if `transform-optional-chaining` is _not_ required
const optionalChainingSupported = !isRequired(
"proposal-optional-chaining",
"transform-optional-chaining",
targets
);
};
Expand All @@ -213,9 +213,9 @@ Plugin authors can use `isRequired` to optimize plugin output given different `t
module.exports = api => {
const targets = api.targets();
// The targets have native optional chaining support
// if `proposal-optional-chaining` is _not_ required
// if `transform-optional-chaining` is _not_ required
const optionalChainingSupported = !isRequired(
"proposal-optional-chaining",
"transform-optional-chaining",
targets
);
const visited = new WeakSet();
Expand All @@ -239,4 +239,4 @@ module.exports = api => {
};
```

[`@babel/plugin-proposal-object-rest-spread`](https://github.com/babel/babel/blob/962d81483ef6a57a4a3eca8230ae40795b695147/packages/babel-plugin-proposal-object-rest-spread/src/index.js#L23) uses `isRequired` to determine whether targets already have native `Object.assign` support.
[`@babel/plugin-transform-object-rest-spread`](https://github.com/babel/babel/blob/d54bc3cd1c1c462760e01c0a8c4bd4b3013f236a/packages/babel-plugin-transform-object-rest-spread/src/index.ts#L33) uses `isRequired` to determine whether targets already have native `Object.assign` support.
6 changes: 3 additions & 3 deletions docs/parser.md
Expand Up @@ -211,7 +211,7 @@ require("@babel/parser").parse("code", {

| Version | Changes |
| --- | --- |
| `v7.22.0` | Added `importAttributes` |
| `v7.22.0` | Enabled `regexpUnicodeSets` by default, added `importAttributes` |
| `v7.20.0` | Added `explicitResourceManagement`, `importReflection` |
| `v7.17.0` | Added `regexpUnicodeSets`, `destructuringPrivate`, `decoratorAutoAccessors` |
| `v7.15.0` | Added `hack` to the `proposal` option of `pipelineOperator`. Moved `topLevelAwait`, `privateIn` to Latest ECMAScript features |
Expand Down Expand Up @@ -244,7 +244,6 @@ require("@babel/parser").parse("code", {
| `partialApplication` ([proposal](https://github.com/babel/proposals/issues/32)) | `f(?, a)` |
| `pipelineOperator` ([proposal](https://github.com/babel/proposals/issues/29)) | <code>a &#124;> b</code> |
| `recordAndTuple` ([proposal](https://github.com/tc39/proposal-record-tuple)) | `#{x: 1}`, `#[1, 2]` |
| `regexpUnicodeSets` ([proposal](https://github.com/tc39/proposal-regexp-set-notation)) | `/[\p{Decimal_Number}--[0-9]]/v;` |
| `throwExpressions` ([proposal](https://github.com/babel/proposals/issues/23)) | `() => throw new Error("")` |

#### Latest ECMAScript features
Expand All @@ -265,11 +264,12 @@ You should enable these features only if you are using an older version.
| `logicalAssignment` ([proposal](https://github.com/tc39/proposal-logical-assignment)) | `a &&= b` |
| `moduleStringNames` ([proposal](https://github.com/tc39/ecma262/pull/2154)) | `import { "😄" as smile } from "emoji";` |
| `nullishCoalescingOperator` ([proposal](https://github.com/babel/proposals/issues/14)) | `a ?? b` |
| `numericSeparator` ([proposal](https://github.com/samuelgoto/proposal-numeric-separator)) | `1_000_000` |
| `numericSeparator` ([proposal](https://github.com/tc39/proposal-numeric-separator)) | `1_000_000` |
| `objectRestSpread` ([proposal](https://github.com/tc39/proposal-object-rest-spread)) | `var a = { b, ...c };` |
| `optionalCatchBinding` ([proposal](https://github.com/babel/proposals/issues/7)) | `try {throw 0;} catch{do();}` |
| `optionalChaining` ([proposal](https://github.com/tc39/proposal-optional-chaining)) | `a?.b` |
| `privateIn` ([proposal](https://github.com/tc39/proposal-private-fields-in-in)) | `#p in obj` |
| `regexpUnicodeSets` ([proposal](https://github.com/tc39/proposal-regexp-set-notation)) | `/[\p{Decimal_Number}--[0-9]]/v;` |
| `topLevelAwait` ([proposal](https://github.com/tc39/proposal-top-level-await/)) | `await promise` in modules |

#### Plugins options
Expand Down
24 changes: 13 additions & 11 deletions docs/plugin-proposal-decorators.md
Expand Up @@ -62,7 +62,7 @@ npm install --save-dev @babel/plugin-proposal-decorators
```json title="babel.config.json"
{
"plugins": [
["@babel/plugin-proposal-decorators", { "version": "2023-01" }]
["@babel/plugin-proposal-decorators", { "version": "2023-05" }]
]
}
```
Expand All @@ -72,7 +72,7 @@ npm install --save-dev @babel/plugin-proposal-decorators
```js title="JavaScript"
require("@babel/core").transformSync("code", {
plugins: [
["@babel/plugin-proposal-decorators", { version: "2023-01" }],
["@babel/plugin-proposal-decorators", { version: "2023-05" }],
]
});
```
Expand All @@ -84,16 +84,18 @@ require("@babel/core").transformSync("code", {

| Version | Changes |
| --- | --- |
| `v7.22.0` | Added support for `version: "2023-05"` |
| `v7.21.0` | Added support for `version: "2023-01"` |
| `v7.19.0` | Added support for `version: "2022-03"` |
| `v7.17.0` | Added the `version` option with support for `"2021-12"`, `"2018-09"` and `"legacy"` |
</details>

### `version`

`"2023-01"`, `"2022-03"`, `"2021-12"`, `"2018-09"` or `"legacy"`.
`"2023-05"`, `"2023-01"`, `"2022-03"`, `"2021-12"`, `"2018-09"` or `"legacy"`.

Selects the decorators proposal to use:
- `"2023-05"` is the proposal version after the updates that reached consensus in the March and May 2023 TC39 meetings, integrating [these changes](https://github.com/pzuraq/ecma262/compare/e86128e13b63a3c2efc3728f76c8332756752b02...c4465e44d514c6c1dba810487ec2721ccd6b08f9).
- `"2023-01"` is the proposal version after the updates that reached consensus in the January 2023 TC39 meeting, integrating [`pzuraq/ecma262#4`](https://github.com/pzuraq/ecma262/pull/4).
- `"2022-03"` is the proposal version that reached consensus for Stage 3 in the March 2022 TC39 meeting. You can read more about it at [`tc39/proposal-decorators@8ca65c046d`](https://github.com/tc39/proposal-decorators/tree/8ca65c046dd5e9aa3846a1fe5df343a6f7efd9f8).
- `"2021-12"` is the proposal version as it was presented to TC39 in Dec 2021. You can read more about it at [`tc39/proposal-decorators@d6c056fa06`](https://github.com/tc39/proposal-decorators/tree/d6c056fa061646178c34f361bad33d583316dc85).
Expand All @@ -107,7 +109,7 @@ If you specify the `decoratorsBeforeExport` option, `version` defaults to `"2018
### `decoratorsBeforeExport`

This option:
- is disallowed when using `version: "legacy"`, `version: "2022-03"`, or `version: "2023-01"`;
- is disallowed when using `version: "legacy"`, `version: "2022-03"`, `version: "2023-01"`, or `version: "2023-05"`;
- is required when using `version: "2018-09"`;
- is optional and defaults to `false` when using `version: "2021-12"`.

Expand All @@ -134,28 +136,28 @@ Use `version: "legacy"` instead. This option is a legacy alias.

Use the legacy (stage 1) decorators syntax and behavior.

#### NOTE: Compatibility with `@babel/plugin-proposal-class-properties`
#### NOTE: Compatibility with `@babel/plugin-transform-class-properties`

If you are including your plugins manually and using `@babel/plugin-proposal-class-properties` or `@babel/plugin-private-methods` and legacy decorators, make sure that `@babel/plugin-proposal-decorators` comes _before_ `@babel/plugin-proposal-class-properties`.
If you are including your plugins manually and using `@babel/plugin-transform-class-properties` or `@babel/plugin-private-methods` and legacy decorators, make sure that `@babel/plugin-proposal-decorators` comes _before_ `@babel/plugin-transform-class-properties`.

```diff title="babel.config.json"
{
"plugins": [
- "@babel/plugin-proposal-class-properties",
- "@babel/plugin-transform-class-properties",
["@babel/plugin-proposal-decorators", { "version": "2023-01" }]
+ "@babel/plugin-proposal-class-properties"
+ "@babel/plugin-transform-class-properties"
]
}
```

If you are already using `@babel/preset-env`, you can safely remove `@babel/plugin-proposal-class-properties` and `@babel/plugin-private-methods`:
If you are already using `@babel/preset-env`, you can safely remove `@babel/plugin-transform-class-properties` and `@babel/plugin-private-methods`:

```diff title="babel.config.json"
{
"presets": ["@babel/preset-env"],
"plugins": [
- "@babel/plugin-proposal-class-properties",
["@babel/plugin-proposal-decorators", { "version": "2023-01" }]
- "@babel/plugin-transform-class-properties",
["@babel/plugin-proposal-decorators", { "version": "2023-05" }]
]
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/plugin-proposal-destructuring-private.md
Expand Up @@ -50,13 +50,13 @@ npm install --save-dev @babel/plugin-proposal-destructuring-private
}
```

Because the output code includes private fields, if you are already using other class feature plugins (e.g. [`@babel/plugin-proposal-class-properties](plugin-proposal-class-properties.md)), be sure to place it _before_ the others.
Because the output code includes private fields, if you are already using other class feature plugins (e.g. [`@babel/plugin-transform-class-properties](plugin-transform-class-properties.md)), be sure to place it _before_ the others.

```json title="babel.config.json"
{
"plugins": [
"@babel/plugin-proposal-destructuring-private",
"@babel/plugin-proposal-class-properties"
"@babel/plugin-transform-class-properties"
]
}
```
Expand Down
65 changes: 65 additions & 0 deletions docs/plugin-proposal-explicit-resource-management.md
@@ -0,0 +1,65 @@
---
id: babel-plugin-proposal-explicit-resource-management
title: "@babel/plugin-proposal-explicit-resource-management"
sidebar_label: explicit-resource-management
---

This plugin enables Babel to transform using declarations `using handler = await read();`.

## Example

```js title="input.js"
using handlerSync = openSync();
await using handlerAsync = await openAsync();
```

will be transformed to

```js title="output.js"
try {
var _stack = [];
var handlerSync = babelHelpers.using(_stack, openSync());
var handlerAsync = babelHelpers.using(_stack, await openAsync(), true);
} catch (_) {
var _error = _;
var _hasError = true;
} finally {
await babelHelpers.dispose(_stack, _error, _hasError);
}
```

[Try it on the REPL](https://babeljs.io/repl#?build=&builtIns=false&corejs=3.28&spec=false&loose=false&code_lz=K4Zwlgdg5gBAFgQwgEwDYFMBOBlAnhAYxgF4YB7AB3Qj0IAoBKAbgCgEB3BMAFxlEliIUGTAEEQ-IqQ5delauMmMmQA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=react&prettier=false&targets=&externalPlugins=%40babel%2Fplugin-proposal-explicit-resource-management%407.22.0%2C%40babel%2Fplugin-external-helpers%407.18.6&assumptions=%7B%7D).

## Installation

```shell npm2yarn
npm install --save-dev @babel/plugin-proposal-explicit-resource-management
```

## Usage

### With a configuration file (Recommended)

```json title="babel.config.json"
{
"plugins": ["@babel/plugin-proposal-explicit-resource-management"]
}
```

### Via CLI

```sh title="Shell"
babel --plugins @babel/plugin-proposal-explicit-resource-management script.js
```

### Via Node API

```js title="JavaScript"
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-explicit-resource-management"]
});
```

## References

- [Proposal: ECMAScript Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)
41 changes: 41 additions & 0 deletions docs/plugin-proposal-import-attributes-to-assertions.md
@@ -0,0 +1,41 @@
---
id: babel-plugin-proposal-import-attributes-to-assertions
title: "@babel/plugin-proposal-import-attributes-to-assertions"
sidebar_label: import-attributes-to-assertions
---

:::caution

This plugin will generate code that is not compatible with the current ECMAScript specification or with any currently proposed addition to it. Only use it when you are shipping native ES modules and you need compatibility exclusively with tools that don't support the Import Attributes syntax (`import pkg from "./package.json" with { type: "json" }`) but support the old Import Assertions syntax (`import pkg from "./package.json" assert { type: "json" }`), such as Chrome 91+ and Node.js 17.2+.

:::

## Installation

```shell npm2yarn
npm install --save-dev @babel/plugin-proposal-import-attributes-to-assertions
```

## Usage

### With a configuration file (Recommended)

```json title="babel.config.json"
{
"plugins": ["@babel/plugin-proposal-import-attributes-to-assertions"]
}
```

### Via CLI

```sh title="Shell"
babel --plugins @babel/plugin-proposal-import-attributes-to-assertions script.js
```

### Via Node API

```js title="JavaScript"
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-import-attributes-to-assertions"],
});
```
2 changes: 2 additions & 0 deletions docs/plugin-proposal-unicode-sets-regex.md
Expand Up @@ -4,6 +4,8 @@ title: "@babel/plugin-proposal-unicode-sets-regex"
sidebar_label: unicode-sets-regex
---

> **NOTE**: This plugin is included in `@babel/preset-env`, in [ES2024](https://github.com/tc39/proposals/blob/master/finished-proposals.md)
This plugin transforms regular expressions using the `v` flag, introduced by the [RegExp set notation + properties of strings](https://github.com/tc39/proposal-regexp-set-notation) proposal, to regular expressions that use the `u` flag.

## Example
Expand Down
2 changes: 1 addition & 1 deletion docs/plugin-syntax-async-generators.md
Expand Up @@ -6,7 +6,7 @@ sidebar_label: syntax-async-generators

> #### Syntax only
>
> It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use [plugin-proposal-async-generators](plugin-proposal-async-generator-functions.md) to _both_ parse and transform this syntax.
> It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use [plugin-proposal-async-generators](plugin-transform-async-generator-functions.md) to _both_ parse and transform this syntax.
## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/plugin-syntax-class-properties.md
Expand Up @@ -6,7 +6,7 @@ sidebar_label: syntax-class-properties

> #### Syntax only
>
> It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use [plugin-proposal-class-properties](plugin-proposal-class-properties.md) to _both_ parse and transform this syntax.
> It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use [plugin-transform-class-properties](plugin-transform-class-properties.md) to _both_ parse and transform this syntax.
## Installation

Expand Down

0 comments on commit 8561e1a

Please sign in to comment.