Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8fa68a7

Browse files
Split table between Babel 7 and 8
1 parent b2b3ae3 commit 8fa68a7

2 files changed

Lines changed: 68 additions & 61 deletions

File tree

docs/parser.md

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,34 @@ require("@babel/parser").parse("code", {
214214

215215
#### ECMAScript [proposals](https://github.com/babel/proposals)
216216

217+
:::babel8
218+
219+
| Name | Code Example |
220+
| -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
221+
| `asyncDoExpressions` ([proposal](https://github.com/tc39/proposal-async-do-expressions)) | `async do { await requestAPI().json() }` |
222+
| `decorators` ([proposal](https://github.com/tc39/proposal-decorators)) <br/> `decorators-legacy` | `@a class A {}` |
223+
| `decoratorAutoAccessors` ([proposal](https://github.com/tc39/proposal-decorators)) | `class Example { @reactive accessor myBool = false; }` |
224+
| `deferredImportEvaluation` ([proposal](https://github.com/tc39/proposal-defer-import-eval)) | `import defer * as ns from "dep";` |
225+
| `destructuringPrivate` ([proposal](https://github.com/tc39/proposal-destructuring-private)) | `class Example { #x = 1; method() { const { #x: x } = this; } }` |
226+
| `doExpressions` ([proposal](https://github.com/tc39/proposal-do-expressions)) | `var a = do { if (true) { 'hi'; } };` |
227+
| `explicitResourceManagement` ([proposal](https://github.com/tc39/proposal-explicit-resource-management)) | `using reader = getReader()` |
228+
| `exportDefaultFrom` ([proposal](https://github.com/tc39/ecmascript-export-default-from)) | `export v from "mod"` |
229+
| `functionBind` ([proposal](https://github.com/zenparsing/es-function-bind)) | `a::b`, `::console.log` |
230+
| `functionSent` ([proposal](https://github.com/tc39/proposal-function.sent)) | `function.sent` |
231+
| `importAttributes` ([proposal](https://github.com/tc39/proposal-import-attributes)) | `import json from "./foo.json" with { type: "json" };` |
232+
| `importReflection` ([proposal](https://github.com/tc39/proposal-import-reflection)) | `import module foo from "./foo.wasm";` |
233+
| `moduleBlocks` ([proposal](https://github.com/tc39/proposal-js-module-blocks)) | `let m = module { export let y = 1; };` |
234+
| `optionalChainingAssign` ([proposal](https://github.com/tc39/proposal-optional-chaining-assignment)) | `x?.prop = 2` |
235+
| `partialApplication` ([proposal](https://github.com/babel/proposals/issues/32)) | `f(?, a)` |
236+
| `pipelineOperator` ([proposal](https://github.com/babel/proposals/issues/29)) | <code>a &#124;> b</code> |
237+
| `recordAndTuple` ([proposal](https://github.com/tc39/proposal-record-tuple)) | `#{x: 1}`, `#[1, 2]` |
238+
| `sourcePhaseImports` ([proposal](https://github.com/tc39/proposal-source-phase-imports)) | `import source x from "./x"` |
239+
| `throwExpressions` ([proposal](https://github.com/babel/proposals/issues/23)) | `() => throw new Error("")` |
240+
241+
:::
242+
243+
:::babel7
244+
217245
<details>
218246
<summary>History</summary>
219247

@@ -236,28 +264,28 @@ require("@babel/parser").parse("code", {
236264

237265
</details>
238266

239-
| Name | Code Example |
240-
| ----------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
241-
| `asyncDoExpressions` ([proposal](https://github.com/tc39/proposal-async-do-expressions)) | `async do { await requestAPI().json() }` |
242-
| `decimal` ([proposal](https://github.com/tc39/proposal-decimal)) | `0.3m` |
243-
| `decorators` ([proposal](https://github.com/tc39/proposal-decorators)) <br/> `decorators-legacy` | `@a class A {}` |
244-
| `decoratorAutoAccessors` ([proposal](https://github.com/tc39/proposal-decorators)) | `class Example { @reactive accessor myBool = false; }` |
245-
| `deferredImportEvaluation` ([proposal](https://github.com/tc39/proposal-defer-import-eval)) | `import defer * as ns from "dep";` |
246-
| `destructuringPrivate` ([proposal](https://github.com/tc39/proposal-destructuring-private)) | `class Example { #x = 1; method() { const { #x: x } = this; } }` |
247-
| `doExpressions` ([proposal](https://github.com/tc39/proposal-do-expressions)) | `var a = do { if (true) { 'hi'; } };` |
248-
| `explicitResourceManagement` ([proposal](https://github.com/tc39/proposal-explicit-resource-management)) | `using reader = getReader()` |
249-
| `exportDefaultFrom` ([proposal](https://github.com/tc39/ecmascript-export-default-from)) | `export v from "mod"` |
250-
| `functionBind` ([proposal](https://github.com/zenparsing/es-function-bind)) | `a::b`, `::console.log` |
251-
| `functionSent` ([proposal](https://github.com/tc39/proposal-function.sent)) | `function.sent` |
252-
| `importAttributes` ([proposal](https://github.com/tc39/proposal-import-attributes)) [<br/> `importAssertions` (⚠️ deprecated)](:::babel7) | `import json from "./foo.json" with { type: "json" };` |
253-
| `importReflection` ([proposal](https://github.com/tc39/proposal-import-reflection)) | `import module foo from "./foo.wasm";` |
254-
| `moduleBlocks` ([proposal](https://github.com/tc39/proposal-js-module-blocks)) | `let m = module { export let y = 1; };` |
255-
| `optionalChainingAssign` ([proposal](https://github.com/tc39/proposal-optional-chaining-assignment)) | `x?.prop = 2` |
256-
| `partialApplication` ([proposal](https://github.com/babel/proposals/issues/32)) | `f(?, a)` |
257-
| `pipelineOperator` ([proposal](https://github.com/babel/proposals/issues/29)) | <code>a &#124;> b</code> |
258-
| `recordAndTuple` ([proposal](https://github.com/tc39/proposal-record-tuple)) | `#{x: 1}`, `#[1, 2]` |
259-
| `sourcePhaseImports` ([proposal](https://github.com/tc39/proposal-source-phase-imports)) | `import source x from "./x"` |
260-
| `throwExpressions` ([proposal](https://github.com/babel/proposals/issues/23)) | `() => throw new Error("")` |
267+
| Name | Code Example |
268+
| ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
269+
| `asyncDoExpressions` ([proposal](https://github.com/tc39/proposal-async-do-expressions)) | `async do { await requestAPI().json() }` |
270+
| `decimal` ([proposal](https://github.com/tc39/proposal-decimal)) | `0.3m` |
271+
| `decorators` ([proposal](https://github.com/tc39/proposal-decorators)) <br/> `decorators-legacy` | `@a class A {}` |
272+
| `decoratorAutoAccessors` ([proposal](https://github.com/tc39/proposal-decorators)) | `class Example { @reactive accessor myBool = false; }` |
273+
| `deferredImportEvaluation` ([proposal](https://github.com/tc39/proposal-defer-import-eval)) | `import defer * as ns from "dep";` |
274+
| `destructuringPrivate` ([proposal](https://github.com/tc39/proposal-destructuring-private)) | `class Example { #x = 1; method() { const { #x: x } = this; } }` |
275+
| `doExpressions` ([proposal](https://github.com/tc39/proposal-do-expressions)) | `var a = do { if (true) { 'hi'; } };` |
276+
| `explicitResourceManagement` ([proposal](https://github.com/tc39/proposal-explicit-resource-management)) | `using reader = getReader()` |
277+
| `exportDefaultFrom` ([proposal](https://github.com/tc39/ecmascript-export-default-from)) | `export v from "mod"` |
278+
| `functionBind` ([proposal](https://github.com/zenparsing/es-function-bind)) | `a::b`, `::console.log` |
279+
| `functionSent` ([proposal](https://github.com/tc39/proposal-function.sent)) | `function.sent` |
280+
| `importAttributes` ([proposal](https://github.com/tc39/proposal-import-attributes)) <br/> `importAssertions` (⚠️ deprecated) | `import json from "./foo.json" with { type: "json" };` |
281+
| `importReflection` ([proposal](https://github.com/tc39/proposal-import-reflection)) | `import module foo from "./foo.wasm";` |
282+
| `moduleBlocks` ([proposal](https://github.com/tc39/proposal-js-module-blocks)) | `let m = module { export let y = 1; };` |
283+
| `optionalChainingAssign` ([proposal](https://github.com/tc39/proposal-optional-chaining-assignment)) | `x?.prop = 2` |
284+
| `partialApplication` ([proposal](https://github.com/babel/proposals/issues/32)) | `f(?, a)` |
285+
| `pipelineOperator` ([proposal](https://github.com/babel/proposals/issues/29)) | <code>a &#124;> b</code> |
286+
| `recordAndTuple` ([proposal](https://github.com/tc39/proposal-record-tuple)) | `#{x: 1}`, `#[1, 2]` |
287+
| `sourcePhaseImports` ([proposal](https://github.com/tc39/proposal-source-phase-imports)) | `import source x from "./x"` |
288+
| `throwExpressions` ([proposal](https://github.com/babel/proposals/issues/23)) | `() => throw new Error("")` |
261289

262290
#### Latest ECMAScript features
263291

@@ -285,6 +313,8 @@ You should enable these features only if you are using an older version.
285313
| `regexpUnicodeSets` ([proposal](https://github.com/tc39/proposal-regexp-set-notation)) | `/[\p{Decimal_Number}--[0-9]]/v;` |
286314
| `topLevelAwait` ([proposal](https://github.com/tc39/proposal-top-level-await/)) | `await promise` in modules |
287315

316+
:::
317+
288318
#### Plugins options
289319

290320
<details>
@@ -310,7 +340,11 @@ When a plugin is specified multiple times, only the first options are considered
310340

311341
- `deprecatedAssertSyntax` (`boolean`, defaults to `false`)
312342

313-
When `true`, allow parsing an old version of the import attributes, which used the `assert` keyword instead of `with`. [This matches the syntax originally supported by the `importAssertions` parser plugin.](:::babel7)
343+
When `true`, allow parsing an old version of the import attributes, which used the `assert` keyword instead of `with`.
344+
345+
:::babel7
346+
This matches the syntax originally supported by the `importAssertions` parser plugin.
347+
:::
314348

315349
- `decorators`:
316350

website/docusaurus.config.js

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,23 @@ function loadYaml(fsPath) {
3333
return parseYaml(fs.readFileSync(path.join(__dirname, fsPath), "utf8"));
3434
}
3535

36-
const users = loadYaml("./data/users.yml").map((user) => ({
36+
const users = loadYaml("./data/users.yml").map(user => ({
3737
pinned: user.pinned,
3838
caption: user.name,
3939
infoLink: user.url,
4040
image: `/img/users/${user.logo}`,
4141
}));
4242

43-
const sponsorsManual = (loadYaml("./data/sponsors.yml") || []).map(
44-
(sponsor) => ({
45-
...sponsor,
46-
image: sponsor.image || path.join("/img/sponsors/", sponsor.logo),
47-
})
48-
);
43+
const sponsorsManual = (loadYaml("./data/sponsors.yml") || []).map(sponsor => ({
44+
...sponsor,
45+
image: sponsor.image || path.join("/img/sponsors/", sponsor.logo),
46+
}));
4947
const sponsorsDownloaded = require(path.join(__dirname, "/data/sponsors.json"));
5048

5149
const sponsors = [
5250
...sponsorsDownloaded
53-
.filter((sponsor) => sponsor.slug !== "github-sponsors")
54-
.map((sponsor) => {
51+
.filter(sponsor => sponsor.slug !== "github-sponsors")
52+
.map(sponsor => {
5553
let website = sponsor.website;
5654
if (typeof website == "string") {
5755
website = url.parse(website).protocol ? website : `http://${website}`;
@@ -81,7 +79,7 @@ const team = loadYaml("./data/team.yml");
8179
const tools = loadYaml("./data/tools.yml");
8280
const setupBabelrc = loadMD("./data/tools/setup.md");
8381

84-
toolsMD.forEach((tool) => {
82+
toolsMD.forEach(tool => {
8583
tool.install = loadMD(`${tool.path}/install.md`);
8684
tool.usage = loadMD(`${tool.path}/usage.md`);
8785
});
@@ -105,44 +103,19 @@ function remarkDirectiveBabel8Plugin({ renderBabel8 }) {
105103
if (node.type === "containerDirective") {
106104
const directiveLabel = node.name;
107105
if (directiveLabel === "babel8" || directiveLabel === "babel7") {
108-
if ((directiveLabel === "babel8") !== renderBabel8) {
106+
if ((directiveLabel === "babel8") ^ renderBabel8) {
109107
// remove anything between ":::babel[78]" and ":::"
110108
children.splice(index, 1);
111109
} else {
112110
// remove the :::babel[78] container only
113111
children.splice(index, 1, ...node.children);
114-
index += node.children.length;
115112
}
113+
} else {
114+
transformer(node); // for support inside ::tip, etc
116115
}
117116
}
118-
119-
flatMap(node, (child) => {
120-
if (child?.type === "link") {
121-
if (child.url === ":::babel7") {
122-
return renderBabel8 ? [] : child.children;
123-
}
124-
if (child.url === ":::babel8") {
125-
return renderBabel8 ? child.children : [];
126-
}
127-
}
128-
return [child];
129-
});
130117
}
131118
};
132-
133-
function flatMap(node, cb) {
134-
if (typeof node !== "object" || !node || typeof node.type !== "string") {
135-
return;
136-
}
137-
for (const key of Object.keys(node)) {
138-
if (Array.isArray(node[key])) {
139-
node[key] = node[key].flatMap(cb);
140-
node[key].forEach((child) => flatMap(child, cb));
141-
} else {
142-
flatMap(node[key], cb);
143-
}
144-
}
145-
}
146119
}
147120

148121
const siteConfig = {

0 commit comments

Comments
 (0)