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

docs(en): merge website/main into babeljs.cn/cn-v7 @ 1e6fbf4e #243

Open
wants to merge 87 commits into
base: cn-v7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
629a534
[FIX] broken link (#2883)
houtan-rocky Mar 27, 2024
90125ef
Update plugin-proposal-optional-chaining-assign.md (#2884)
SharakPL Mar 29, 2024
6678bf7
Add docs for bugfix-firefox-class-in-computed-class-key (#2885)
nicolo-ribaudo Apr 3, 2024
85c50cc
Fix typo in preset-typescript.md (#2886)
askoufis Apr 10, 2024
f151f34
Update Babel types docs (#2887)
babel-bot Apr 29, 2024
d75348f
Docs updates for `transform-runtime` cleanup (#2872)
nicolo-ribaudo Apr 29, 2024
014d07f
Bump Babel 8 node.js requirements (#2888)
JLHwung Apr 30, 2024
c375585
Update plugin-transform-typescript.md (#2889)
Dunqing May 11, 2024
b013f24
docs: update Babel/estree ast difference (#2892)
sxzz Jun 1, 2024
9018180
[Babel 8] Migration guide for `extra.shorthand` (#2891)
liuxingbaoyu Jun 3, 2024
13c9277
fix transform-dynamic-import 404 (#2894)
JLHwung Jun 4, 2024
873907a
fix dynamic-import proposal link (#2896)
JLHwung Jun 4, 2024
806e689
docs: typo in plugin-proposal-decorators (#2900)
fi3ework Jun 19, 2024
d8df2be
Document that regexp plugins only handle regexp literals (#2901)
nicolo-ribaudo Jun 20, 2024
449f038
fix(docsearch): better text contrast for active hit (#2905)
Den-dp Jul 6, 2024
4caa527
docs(options.md): clarify `--source-maps` CLI option (#2898)
jedwards1211 Jul 9, 2024
7242463
docs(assumptions): Remove references to `noObjectSuper` & `noUndeclar…
rschristian Jul 9, 2024
cf9d765
Update plugins-list.md (#2909)
JLHwung Jul 9, 2024
2852ab6
Bump ws from 7.5.9 to 7.5.10 (#2910)
dependabot[bot] Jul 9, 2024
f172a96
Bump webpack-dev-middleware from 5.3.3 to 5.3.4 (#2911)
dependabot[bot] Jul 9, 2024
ba5ca18
Bump braces from 3.0.2 to 3.0.3 (#2912)
dependabot[bot] Jul 9, 2024
22b7ea1
Bump ua-parser-js from 0.7.32 to 0.7.38 (#2913)
dependabot[bot] Jul 9, 2024
4f109ed
Bump follow-redirects from 1.15.3 to 1.15.6 (#2914)
dependabot[bot] Jul 9, 2024
3f0e414
Bump tar from 6.1.13 to 6.2.1 (#2917)
dependabot[bot] Jul 9, 2024
c5d1741
Bump semver from 5.7.1 to 5.7.2 (#2916)
dependabot[bot] Jul 9, 2024
8b91f98
Bump express from 4.18.2 to 4.19.2 (#2915)
dependabot[bot] Jul 9, 2024
97be67f
Add migration docs for removing methods starting with `_` (#2918)
liuxingbaoyu Jul 10, 2024
eab1cea
Fix REPL CORS error (#2920)
liuxingbaoyu Jul 15, 2024
90481ce
[Babel 8] Doc for removing some `NodePath` methods (#2924)
liuxingbaoyu Jul 26, 2024
6ea5704
Add duplicate-named-capturing-groups to ES2025 (#2893)
JLHwung Jul 26, 2024
3dd2641
Add docs for plugin-bugfix-safari-class-field-initializer-scope (#2921)
davidtaylorhq Jul 26, 2024
5c02185
Add docs for `uncheckedRequire` option (#2928)
nicolo-ribaudo Jul 26, 2024
05b6483
Add release post for 7.25.0 (#2927)
nicolo-ribaudo Jul 26, 2024
7d5e624
Remove tag from 7.25.0 blog post
nicolo-ribaudo Jul 26, 2024
7ff59f9
The Safari bug is _before_ 16
nicolo-ribaudo Jul 26, 2024
06d451b
add 7.25.0 to past versions (#2929)
JLHwung Jul 26, 2024
86dee74
Update 2024-07-26-7.25.0.md
nicolo-ribaudo Jul 27, 2024
3d3732c
fix(options): fix nested directives usage (#2908)
Armanio Jul 29, 2024
f9eeddd
fix(options): fix plugin / present entries anchors (#2930)
davidlj95 Jul 31, 2024
287e0ad
improve Babel generator docs (#2931)
JLHwung Aug 1, 2024
b3f6ea3
Updated Broken Link Broken Link #2934 (#2936)
Dwij1704 Aug 11, 2024
eccff2f
Add Route4Me sponsor logo (#2938)
nicolo-ribaudo Aug 19, 2024
4cfea29
Migration: min Node.js version for Babel 8 (#2947)
nicolo-ribaudo Sep 4, 2024
9423c66
Add Igalia as a base support sponsor (#2946)
nicolo-ribaudo Sep 4, 2024
4bad02b
[babel 8] Docs for babel/node args order (#2950)
nicolo-ribaudo Sep 6, 2024
b5d8f96
[Babel 8] doc: Remove `decimal` from parser (#2945)
liuxingbaoyu Sep 6, 2024
1c62dd8
[Babel 8] doc: Split `typeParameter` of `TSMappedType` (#2939)
liuxingbaoyu Sep 6, 2024
e159676
Fix codeblock titles (#2960)
JLHwung Sep 12, 2024
7369e6e
Bump webpack from 5.89.0 to 5.94.0 (#2962)
dependabot[bot] Sep 12, 2024
20e7a27
add diff to additionalLanguages (#2963)
JLHwung Sep 13, 2024
61d93d1
Docs for `importAssertions` and `importReflection` removal (#2948)
nicolo-ribaudo Sep 16, 2024
9291421
bump Babel 8 to 8.0.0-alpha.12 (#2961)
JLHwung Sep 17, 2024
ec30c0a
Bump Docusaurus to 3.5 (#2966)
JLHwung Sep 18, 2024
7ac5548
Update parser.md (#2968)
skyclouds2001 Sep 24, 2024
936f390
Fix `annexB` option name (#2972)
JLHwung Oct 2, 2024
c8052c2
Update Babel types docs (#2973)
babel-bot Oct 2, 2024
e9829a4
Add 7.25.0 to features timeline
nicolo-ribaudo Oct 2, 2024
3390b4f
update shipped proposals docs (#2958)
JLHwung Oct 8, 2024
ecb084b
update import assertions compat data (#2979)
JLHwung Oct 9, 2024
61218dc
fix: REPL with `preset-env` in Babel 8 (#2970)
liuxingbaoyu Oct 16, 2024
86a4395
Update Babel types docs (#2992)
babel-bot Oct 22, 2024
acb33cd
Add docs for generator's `experimental_preserveFormat` option (#2994)
nicolo-ribaudo Oct 25, 2024
c542714
docs: @babel/parser `startIndex` option (#2971)
DylanPiercey Oct 25, 2024
ded31aa
Rename proposal-modifiers (#2977)
JLHwung Oct 25, 2024
70cff98
docs: `import attributes` enabled by default (#2974)
nicolo-ribaudo Oct 25, 2024
c4e5e39
Add migration docs for flow `enums` option (#2965)
nicolo-ribaudo Oct 25, 2024
c5371ff
[babel 8] Add docs for minimal/smart pipeline modes removal (#2964)
nicolo-ribaudo Oct 25, 2024
9b8ed03
Rename `proposal-json-modules` to `transform` (#2998)
nicolo-ribaudo Oct 25, 2024
d9635e0
Docs for `@babel/highlight` and `code-frame` merge (#2995)
nicolo-ribaudo Oct 25, 2024
861cf9f
Update Babel types docs (#2999)
babel-bot Oct 25, 2024
c46a852
Add 7.26.0 blog post (#2993)
nicolo-ribaudo Oct 25, 2024
c6373d4
Bump http-proxy-middleware from 2.0.6 to 2.0.7 (#3001)
dependabot[bot] Oct 29, 2024
9f6bf35
update past versions (#3002)
JLHwung Oct 29, 2024
1fa7393
Update plugins link (#3004)
JLHwung Nov 1, 2024
bd8ae6f
Update typo in parser.md (#3007)
orta Nov 6, 2024
0e31de8
chore: upgrade Docusaurus, enable Faster Rspack/SWC/LightningCSS (#2997)
slorber Nov 8, 2024
2e87c3a
update landing page examples (#2750)
JLHwung Nov 8, 2024
8fabeac
Fix unused markdown directives warning (#3013)
JLHwung Nov 12, 2024
febfa5b
Migrate `react-instantsearch-dom` v6 to `react-instantsearch` v7 (#3017)
JLHwung Nov 21, 2024
b570d64
add compat-data docs (#3015)
JLHwung Nov 22, 2024
eb08a49
Using unpkg instead of googleapis (#3019)
liuxingbaoyu Nov 29, 2024
ff32d27
Use CodeMirror 6 in REPL (#3014)
JLHwung Nov 29, 2024
f1e8d8d
[babel 8] Docs for the new preset-react' `development` default (#3020)
nicolo-ribaudo Dec 6, 2024
2205b95
add TSTypeReference migration note (#3023)
JLHwung Dec 6, 2024
b8406d7
Add docs for `superTypeParameters` -> `superTypeArguments` rename (#3…
nicolo-ribaudo Dec 7, 2024
1e6fbf4
docs: add implied babel-types breaking changes (#3024)
JLHwung Dec 7, 2024
f7f5692
docs(en): merging all conflicts
docschina-bot Dec 7, 2024
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
44 changes: 28 additions & 16 deletions _redirects
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,29 @@ 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

# Removed packages
/docs/babel-highlight /docs/babel-code-frame#migrating-from-babelhighlight

# 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-unicode-sets-regex /docs/babel-plugin-transform-unicode-sets-regex
/docs/babel-plugin-proposal-export-namespace-from /docs/babel-plugin-transform-export-namespace-from
/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-dynamic-import /docs/babel-plugin-transform-dynamic-import
/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-unicode-sets-regex /docs/babel-plugin-transform-unicode-sets-regex
/docs/babel-plugin-proposal-export-namespace-from /docs/babel-plugin-transform-export-namespace-from
/docs/babel-plugin-proposal-duplicate-named-capturing-groups-regex /docs/babel-plugin-transform-duplicate-named-capturing-groups-regex
/docs/babel-plugin-proposal-regexp-modifiers /docs/babel-plugin-transform-regexp-modifiers
/docs/babel-plugin-proposal-json-modules /docs/babel-plugin-transform-json-modules

# Legacy redirects
/docs/en/babel-plugin-transform-decorators /docs/babel-plugin-proposal-decorators
Expand All @@ -92,8 +99,10 @@ https://babel.netlify.com/* https://babeljs.io/:splat 301!
/docs/en/next/tools/* /setup

# Blog rewrites
/7.26.0 /blog/2024/10/25/7.26.0
/7.25.0 /blog/2024/07/26/7.25.0
/7.24.0 /blog/2024/02/28/7.24.0
/7.23.0 /blog/2023/09/25/7.22.0
/7.23.0 /blog/2023/09/25/7.23.0
/7.22.0 /blog/2023/05/26/7.22.0
/7.21.0 /blog/2023/02/20/7.21.0
/7.20.0 /blog/2022/10/27/7.20.0
Expand Down Expand Up @@ -139,3 +148,6 @@ https://babel.netlify.com/* https://babeljs.io/:splat 301!
# Docusaurus v1 compat

/docs/en/* /docs/:splat

# CircleCI CORS
/circleci/api/* https://circleci.com/api/v1.1/project/github/babel/babel/:splat 200
2 changes: 0 additions & 2 deletions docs/assumptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@ class Child extends Parent {
"mutableTemplateObject": true,
"noClassCalls": true,
"noDocumentAll": true,
"noObjectSuper": true,
"noUndeclaredVariablesCheck": true,
"objectRestNoSymbols": true,
"privateFieldsAsProperties": true,
"pureGetters": true,
Expand Down
90 changes: 84 additions & 6 deletions docs/code-frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ npm install --save-dev @babel/code-frame

## Usage

### `codeFrameColumns`

The `codeFrameColumns` function allows you to decorate a code snipped with line numbers and with a marker pointing to a specific location.

It will also optionally highlight your code, defaulting to what is supported by the output terminal.

```js title="JavaScript"
import { codeFrameColumns } from "@babel/code-frame";

Expand Down Expand Up @@ -68,33 +74,33 @@ console.log(result);
5 | };
```

## Options
#### Options

### `highlightCode`
##### `highlightCode`

`boolean`, defaults to `false`.

Toggles syntax highlighting the code as JavaScript for terminals.

### `linesAbove`
##### `linesAbove`

`number`, defaults to `2`.

Adjust the number of lines to show above the error.

### `linesBelow`
##### `linesBelow`

`number`, defaults to `3`.

Adjust the number of lines to show below the error.

### `forceColor`
##### `forceColor`

`boolean`, defaults to `false`.

Enable this to forcibly syntax highlight the code as JavaScript (for non-terminals); overrides `highlightCode`.

### `message`
##### `message`

`string`, otherwise nothing

Expand All @@ -109,6 +115,76 @@ the code frame.
3 | };
```

### `highlight`

The `highlight` function adds syntax highlighting to a code snipped, to be displayed in a terminal.

```js title="JavaScript"
import { highlight } from "@babel/code-frame";

const code = `class Foo {
constructor()
}`;

const result = highlight(code);

console.log(result);
```

```js title="JavaScript"
class Foo {
constructor()
}
```

## Migrating from `@babel/highlight`

The `highlight` functionality was originally split in its own package, `@babel/highlight`.

You can migrate as follows:
<table>
<thead>
<tr>
<th>Using <code>@babel/highlight</code></th>
<th>Using <code>@babel/code-frame</code></th>
</tr>
</thead>
<tbody><tr><td>

```js title="JavaScript"
import highlight from "@babel/highlight";

highlight(text, { forceColor: true });
```

</td><td>

```js title="JavaScript"
import { highlight } from "@babel/code-frame";

highlight(text);
```

</td></tr><tr><td>

```js title="JavaScript"
import highlight from "@babel/highlight";

highlight(text);
```

</td><td>

```js title="JavaScript"
import { highlight } from "@babel/code-frame";

process.stdout.hasColors() ? highlight(text) : text;
```

</td></tr></tbody></table>

:::babel7

## Upgrading from prior versions

Prior to version 7, the only API exposed by this module was for a single line and optional column pointer. The old API will now log a deprecation warning.
Expand Down Expand Up @@ -151,3 +227,5 @@ const result = codeFrameColumns(rawLines, location, {

console.log(result);
```

:::
55 changes: 55 additions & 0 deletions docs/compat-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
id: babel-compat-data
title: "@babel/compat-data"
---

This package provides compatibility data for various JavaScript features across different browser and runtime environments. It is used by [`@babel/preset-env`](./preset-env.md) internally to determine the required Babel plugins for a given set of [compilation targets](./options.md#targets). The compat data is extracted from the [compat-table project](https://github.com/compat-table/compat-table).

## Install

```shell npm2yarn
npm install --save-dev @babel/compat-data
```

## Usage

### plugins
```javascript title="my-babel-plugin.js"
import _plugins from "@babel/compat-data/plugins";
const pluginsCompatData = _plugins.default;
```

The `pluginsCompatData` is an object with the Babel plugin short name as the key and a compat data entry as its value. Each entry is an object with a browser name as the key and the minimum supported version as its value.

For example, `pluginsCompatData["transform-object-rest-spread"]` will return an object:

```javascript title="my-babel-plugin.js"
{
"chrome": "60",
"opera": "47",
"edge": "79",
"firefox": "55",
"safari": "11.1",
"node": "8.3",
"deno": "1",
"ios": "11.3",
"samsung": "8",
"opera_mobile": "44",
"electron": "2.0"
}
```
Here, the minimum Chrome version with object-rest-spread support is `60`. Therefore, `@babel/preset-env` will enable the object-rest-spread transform only if users are compiling to Chrome versions older than `60`, and likewise for other browsers. Check the [source](https://github.com/babel/babel/blob/main/packages/babel-compat-data/data/plugins.json) for supported Babel plugin short names.

If you would like to know whether object-rest-spread is supported for any given `targets`, you don't have to manually compare it against the compat-data entry. Instead, you can use the [`isRequired`](./helper-compilation-targets.md#isrequired) utility from `@babel/helper-compilation-targets`:

```javascript title="my-babel-plugin.js"
import { isRequired } from "@babel/helper-compilation-targets";

module.exports = api => {
// Check if the targets have native object-rest-spread support
const objectRestSpreadSupported = !isRequired(
"transform-object-rest-spread",
api.targets()
);
};
```
19 changes: 19 additions & 0 deletions docs/features-timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ Which major new features did we introduce in each Babel version? This page inclu
Additionally, use this timeline to track some other important efforts, such as the [babel-polyfills](https://github.com/babel/babel-polyfills) project.

<ol class="timeline-container">
<li data-date="Oct 2024">

## Babel 7.26.0

[blog post](https://babeljs.io/blog/2024/10/25/7.26.0)

- Enable the [regular expression modifiers](https://github.com/tc39/proposal-regexp-modifiers/) Stage 4 proposal by default
- Enable parsing of the [import attributes](https://github.com/tc39/import-attributes/) Stage 4 proposal by default

</li>
<li data-date="Jul 2024">

## Babel 7.25.0

[blog post](https://babeljs.io/blog/2024/07/26/7.25.0)

- Enable the Stage 4 [duplicated named capturing groups](https://github.com/tc39/proposal-duplicate-named-capturing-groups/) proposal by default

</li>
<li data-date="Feb 2024">

## Babel 7.24.0
Expand Down
33 changes: 32 additions & 1 deletion docs/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: babel-generator
title: "@babel/generator"
---

> Turns an AST into code.
> Turns Babel AST into code.

## Install

Expand Down Expand Up @@ -33,13 +33,33 @@ const output = generate(
The symbols like white spaces or new line characters are not preserved in the AST. When Babel generator prints code from the AST, the output format is not guaranteed.
:::

### Parser plugins support
Babel generator supports all the listed [Babel parser plugins](./parser.md#plugins) except `estree`. Note that parser plugins do not transform the code. For example,
if you pass JSX `<div></div>` to babel generator, the result will still contain the `div` JSX element.

```js title="JavaScript"
import { parse } from "@babel/parser";
import generate from "@babel/generator";

const code = "const Example = () => <div>example</div>";
const ast = parse(code, { plugins: ["jsx" ] });

const output = generate(
ast,
);

// true
output.includes("<div>");
```

## Options

<details>
<summary>History</summary>

| Version | Changes |
| --- | --- |
| v7.26.0 | Added `experimental_preserveFormat` |
| v7.22.0 | Added `importAttributesKeyword` |
| v7.21.0 | Added `inputSourceMap` |
</details>
Expand Down Expand Up @@ -74,6 +94,17 @@ Options for source maps:
| sourceRoot | string | | A root for all relative URLs in the source map |
| sourceFileName | string | | The filename for the source code (i.e. the code in the `code` argument). This will only be used if `code` is a string. |

Experimental options:

:::warning
The behavior of experimental options could have breaking changes in _minor_ versions.
:::

| name | type | default | description | experimental reason |
| --------------------------- | ------- | ------- | ----------- | ------------------- |
| experimental_preserveFormat | boolean | `false` | When set to `true`, the generator will try to preserve location of all the nodes and tokens that are present both in the input and output code. To use this option, you currently need to enable the `retainLines: true` generator option, and the `tokens: true` and `createParenthesizedExpressions: true` parser options. | This option will graduate to stable once it supports a mode that does not require preserving line numbers, but just relative positions of tokens. |


## AST from Multiple Sources

In most cases, Babel does a 1:1 transformation of input-file to output-file. However,
Expand Down
2 changes: 1 addition & 1 deletion docs/helper-environment-visitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ if (path.isMethod()) {

Suppose we are migrating from vanilla JavaScript to ES Modules. Now that the `this` keyword is equivalent to `undefined` at the top level of an ESModule ([spec](https://tc39.es/ecma262/#sec-module-environment-records-getthisbinding)), we want to replace all top-level `this` to [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis):

```js title=input.js
```js title="input.js"
// replace this expression to `globalThis.foo = "top"`
this.foo = "top";

Expand Down
Loading
Loading