From 431f5d3498f646ec91510b602dac726cf6f6baf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 24 Mar 2023 10:06:26 -0400 Subject: [PATCH 01/15] simplify isAsyncFunction --- packages/babel-parser/src/parser/statement.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/babel-parser/src/parser/statement.ts b/packages/babel-parser/src/parser/statement.ts index bd023239ef5b..bb4384631002 100644 --- a/packages/babel-parser/src/parser/statement.ts +++ b/packages/babel-parser/src/parser/statement.ts @@ -10,7 +10,6 @@ import { import ExpressionParser from "./expression"; import { Errors } from "../parse-error"; import { isIdentifierChar, isIdentifierStart } from "../util/identifier"; -import { lineBreak } from "../util/whitespace"; import * as charCodes from "charcodes"; import { BIND_CLASS, @@ -2458,11 +2457,8 @@ export default abstract class StatementParser extends ExpressionParser { isAsyncFunction(): boolean { if (!this.isContextual(tt._async)) return false; - const next = this.nextTokenStart(); - return ( - !lineBreak.test(this.input.slice(this.state.pos, next)) && - this.isUnparsedContextual(next, "function") - ); + const next = this.nextTokenInLineStart(); + return this.isUnparsedContextual(next, "function"); } parseExportDefaultExpression(this: Parser): N.Expression | N.Declaration { From fef32c7ccd20fb812abb18bef044ebf200080e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 12:21:32 -0400 Subject: [PATCH 02/15] add more test cases for explicit-resource-management --- .../valid-for-using-declaration/input.js | 3 + .../valid-for-using-declaration/output.json | 56 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/experimental/explicit-resource-management/valid-for-using-declaration/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/explicit-resource-management/valid-for-using-declaration/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/explicit-resource-management/valid-for-using-declaration/input.js b/packages/babel-parser/test/fixtures/experimental/explicit-resource-management/valid-for-using-declaration/input.js new file mode 100644 index 000000000000..06d1db008dc1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/explicit-resource-management/valid-for-using-declaration/input.js @@ -0,0 +1,3 @@ +{ + for (using basic = reader();;); +} diff --git a/packages/babel-parser/test/fixtures/experimental/explicit-resource-management/valid-for-using-declaration/output.json b/packages/babel-parser/test/fixtures/experimental/explicit-resource-management/valid-for-using-declaration/output.json new file mode 100644 index 000000000000..75ae3eaf7640 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/explicit-resource-management/valid-for-using-declaration/output.json @@ -0,0 +1,56 @@ +{ + "type": "File", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":37}}, + "program": { + "type": "Program", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":37}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "BlockStatement", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":37}}, + "body": [ + { + "type": "ForStatement", + "start":4,"end":35,"loc":{"start":{"line":2,"column":2,"index":4},"end":{"line":2,"column":33,"index":35}}, + "init": { + "type": "VariableDeclaration", + "start":9,"end":31,"loc":{"start":{"line":2,"column":7,"index":9},"end":{"line":2,"column":29,"index":31}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":15,"end":31,"loc":{"start":{"line":2,"column":13,"index":15},"end":{"line":2,"column":29,"index":31}}, + "id": { + "type": "Identifier", + "start":15,"end":20,"loc":{"start":{"line":2,"column":13,"index":15},"end":{"line":2,"column":18,"index":20},"identifierName":"basic"}, + "name": "basic" + }, + "init": { + "type": "CallExpression", + "start":23,"end":31,"loc":{"start":{"line":2,"column":21,"index":23},"end":{"line":2,"column":29,"index":31}}, + "callee": { + "type": "Identifier", + "start":23,"end":29,"loc":{"start":{"line":2,"column":21,"index":23},"end":{"line":2,"column":27,"index":29},"identifierName":"reader"}, + "name": "reader" + }, + "arguments": [] + } + } + ], + "kind": "using" + }, + "test": null, + "update": null, + "body": { + "type": "EmptyStatement", + "start":34,"end":35,"loc":{"start":{"line":2,"column":32,"index":34},"end":{"line":2,"column":33,"index":35}} + } + } + ], + "directives": [] + } + ], + "directives": [] + } +} From 892de2e506ca669d87138eefb097034305304228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 12:33:01 -0400 Subject: [PATCH 03/15] add await using AST definition --- packages/babel-types/src/ast-types/generated/index.ts | 2 +- packages/babel-types/src/builders/generated/index.ts | 2 +- packages/babel-types/src/definitions/core.ts | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index ba045b24d0d0..fc30e0ee912f 100644 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -688,7 +688,7 @@ export interface UpdateExpression extends BaseNode { export interface VariableDeclaration extends BaseNode { type: "VariableDeclaration"; - kind: "var" | "let" | "const" | "using"; + kind: "var" | "let" | "const" | "using" | "await using"; declarations: Array; declare?: boolean | null; } diff --git a/packages/babel-types/src/builders/generated/index.ts b/packages/babel-types/src/builders/generated/index.ts index 06c8521b05ea..b29b4d9cb530 100644 --- a/packages/babel-types/src/builders/generated/index.ts +++ b/packages/babel-types/src/builders/generated/index.ts @@ -509,7 +509,7 @@ export function updateExpression( }); } export function variableDeclaration( - kind: "var" | "let" | "const" | "using", + kind: "var" | "let" | "const" | "using" | "await using", declarations: Array, ): t.VariableDeclaration { return validateNode({ diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index fcf2c130ef05..79fb3e1c435f 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -1155,6 +1155,8 @@ defineType("VariableDeclaration", { "const", // https://github.com/tc39/proposal-explicit-resource-management "using", + // https://github.com/tc39/proposal-async-explicit-resource-management + "await using", ), }, declarations: { From b396838b76d303a1b699a4f7ed4c97c380c4553d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 11:58:50 -0400 Subject: [PATCH 04/15] parse await using declaration --- packages/babel-parser/data/schema.json | 2 + .../src/parse-error/standard-errors.ts | 2 + packages/babel-parser/src/parser/statement.ts | 100 ++- packages/babel-parser/src/types.d.ts | 2 +- packages/babel-parser/src/typings.d.ts | 1 + .../input.js | 3 + .../options.json | 3 + .../invalid-duplicate-using-bindings/input.js | 9 + .../output.json | 138 ++++ .../invalid-export-await-using/input.js | 1 + .../invalid-export-await-using/options.json | 4 + .../input.js | 4 + .../options.json | 3 + .../input.js | 4 + .../options.json | 3 + .../input.js | 8 + .../output.json | 211 ++++++ .../input.js | 1 + .../options.json | 3 + .../output.json | 51 ++ .../input.js | 1 + .../options.json | 3 + .../output.json | 42 ++ .../input.js | 12 + .../options.json | 3 + .../output.json | 214 ++++++ .../input.js | 12 + .../options.json | 3 + .../output.json | 214 ++++++ .../invalid-using-binding-let/input.js | 3 + .../invalid-using-binding-let/output.json | 61 ++ .../invalid-using-decl-as-expr/input.js | 3 + .../invalid-using-decl-as-expr/output.json | 87 +++ .../options.json | 3 + .../input.js | 5 + .../options.json | 3 + .../output.json | 62 ++ .../valid-await-asi-using-binding/input.js | 4 + .../options.json | 3 + .../valid-await-asi-using-binding/output.json | 55 ++ .../valid-await-expr-using/input.js | 4 + .../valid-await-expr-using/output.json | 156 +++++ .../valid-await-using-asi-assignment/input.js | 4 + .../options.json | 3 + .../output.json | 69 ++ .../valid-await-using-comments/input.js | 14 + .../valid-await-using-comments/output.json | 607 ++++++++++++++++++ .../input.js | 3 + .../output.json | 45 ++ .../valid-for-using-binding-of-of/input.js | 4 + .../valid-for-using-binding-of-of/output.json | 94 +++ .../valid-for-using-declaration/input.js | 3 + .../valid-for-using-declaration/output.json | 68 ++ .../input.js | 3 + .../options.json | 4 + .../output.json | 68 ++ .../valid-using-binding-basic/input.js | 3 + .../valid-using-binding-basic/output.json | 58 ++ .../valid-using-binding-escaped/input.js | 3 + .../valid-using-binding-escaped/output.json | 53 ++ .../valid-using-binding-non-bmp/input.js | 3 + .../valid-using-binding-non-bmp/output.json | 58 ++ .../valid-using-binding-using/input.js | 4 + .../valid-using-binding-using/output.json | 84 +++ 64 files changed, 2734 insertions(+), 27 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-duplicate-using-bindings/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-duplicate-using-bindings/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-export-await-using/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-export-await-using/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-linebreak-using/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-linebreak-using/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-using-linebreak/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-using-linebreak/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-in-single-statement-context/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-in-single-statement-context/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-let/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-let/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-decl-as-expr/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-decl-as-expr/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-comments/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-comments/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-lhs-await-as-identifier/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-lhs-await-as-identifier/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-binding-of-of/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-binding-of-of/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-declaration/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-declaration/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-basic/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-basic/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-escaped/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-escaped/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-non-bmp/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-non-bmp/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-using/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-using/output.json diff --git a/packages/babel-parser/data/schema.json b/packages/babel-parser/data/schema.json index ec354824d433..659af3272f02 100644 --- a/packages/babel-parser/data/schema.json +++ b/packages/babel-parser/data/schema.json @@ -126,6 +126,8 @@ }, { "enum": [ + "asyncDoExpressions", + "asyncExplicitResourceManagement", "asyncGenerators", "bigInt", "classPrivateMethods", diff --git a/packages/babel-parser/src/parse-error/standard-errors.ts b/packages/babel-parser/src/parse-error/standard-errors.ts index 64df29c7efb5..7eebae6e5b4d 100644 --- a/packages/babel-parser/src/parse-error/standard-errors.ts +++ b/packages/babel-parser/src/parse-error/standard-errors.ts @@ -33,6 +33,8 @@ export default { "Can not use 'await' as identifier inside a static block.", AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.", + AwaitUsingNotInAsyncContext: + "'await using' is only allowed within async functions and at the top levels of modules.", AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.", AwaitNotInAsyncFunction: "'await' is only allowed within async functions.", diff --git a/packages/babel-parser/src/parser/statement.ts b/packages/babel-parser/src/parser/statement.ts index bb4384631002..6c6fdb941ca6 100644 --- a/packages/babel-parser/src/parser/statement.ts +++ b/packages/babel-parser/src/parser/statement.ts @@ -348,6 +348,19 @@ export default abstract class StatementParser extends ExpressionParser { } } + startsAwaitUsing(): boolean { + let next = this.nextTokenInLineStart(); + if (this.isUnparsedContextual(next, "using")) { + next = this.nextTokenInLineStartSince(next + 5); + const nextCh = this.codePointAtPos(next); + if (this.chStartsBindingIdentifier(nextCh, next)) { + this.expectPlugin("asyncExplicitResourceManagement"); + return true; + } + } + return false; + } + // https://tc39.es/ecma262/#prod-ModuleItem parseModuleItem(this: Parser) { return this.parseStatementLike( @@ -482,6 +495,23 @@ export default abstract class StatementParser extends ExpressionParser { case tt._try: return this.parseTryStatement(node as Undone); + case tt._await: + // [+Await] await [no LineTerminator here] using [no LineTerminator here] BindingList[+Using] + if (!this.state.containsEsc && this.startsAwaitUsing()) { + if (!this.isAwaitAllowed()) { + this.raise(Errors.AwaitUsingNotInAsyncContext, { at: node }); + } else if (!allowDeclaration) { + this.raise(Errors.UnexpectedLexicalDeclaration, { + at: node, + }); + } + this.next(); // eat 'await' + return this.parseVarStatement( + node as Undone, + "await using", + ); + } + break; case tt._using: // using [no LineTerminator here] BindingList[+Using] if ( @@ -912,31 +942,49 @@ export default abstract class StatementParser extends ExpressionParser { } const startsWithLet = this.isContextual(tt._let); - const startsWithUsing = this.isContextual(tt._using); - const isLetOrUsing = - (startsWithLet && this.hasFollowingBindingAtom()) || - (startsWithUsing && this.startsUsingForOf()); - if (this.match(tt._var) || this.match(tt._const) || isLetOrUsing) { - const initNode = this.startNode(); - const kind = this.state.value; - this.next(); - this.parseVar(initNode, true, kind); - const init = this.finishNode(initNode, "VariableDeclaration"); + { + const startsWithAwaitUsing = + this.isContextual(tt._await) && this.startsAwaitUsing(); + const starsWithUsingDeclaration = + startsWithAwaitUsing || + (this.isContextual(tt._using) && this.startsUsingForOf()); + const isLetOrUsing = + (startsWithLet && this.hasFollowingBindingAtom()) || + starsWithUsingDeclaration; + + if (this.match(tt._var) || this.match(tt._const) || isLetOrUsing) { + const initNode = this.startNode(); + let kind; + if (startsWithAwaitUsing) { + kind = "await using"; + if (!this.isAwaitAllowed()) { + this.raise(Errors.AwaitUsingNotInAsyncContext, { + at: this.state.startLoc, + }); + } + this.next(); // eat 'await' + } else { + kind = this.state.value; + } + this.next(); + this.parseVar(initNode, true, kind); + const init = this.finishNode(initNode, "VariableDeclaration"); - const isForIn = this.match(tt._in); - if (isForIn && startsWithUsing) { - this.raise(Errors.ForInUsing, { at: init }); - } - if ( - (isForIn || this.isContextual(tt._of)) && - init.declarations.length === 1 - ) { - return this.parseForIn(node as Undone, init, awaitAt); - } - if (awaitAt !== null) { - this.unexpected(awaitAt); + const isForIn = this.match(tt._in); + if (isForIn && starsWithUsingDeclaration) { + this.raise(Errors.ForInUsing, { at: init }); + } + if ( + (isForIn || this.isContextual(tt._of)) && + init.declarations.length === 1 + ) { + return this.parseForIn(node as Undone, init, awaitAt); + } + if (awaitAt !== null) { + this.unexpected(awaitAt); + } + return this.parseFor(node as Undone, init); } - return this.parseFor(node as Undone, init); } // Check whether the first token is possibly a contextual keyword, so that @@ -1158,7 +1206,7 @@ export default abstract class StatementParser extends ExpressionParser { parseVarStatement( this: Parser, node: Undone, - kind: "var" | "let" | "const" | "using", + kind: "var" | "let" | "const" | "using" | "await using", allowMissingInitializer: boolean = false, ): N.VariableDeclaration { this.next(); @@ -1491,7 +1539,7 @@ export default abstract class StatementParser extends ExpressionParser { this: Parser, node: Undone, isFor: boolean, - kind: "var" | "let" | "const" | "using", + kind: "var" | "let" | "const" | "using" | "await using", allowMissingInitializer: boolean = false, ): Undone { const declarations: N.VariableDeclarator[] = (node.declarations = []); @@ -1533,7 +1581,7 @@ export default abstract class StatementParser extends ExpressionParser { parseVarId( this: Parser, decl: Undone, - kind: "var" | "let" | "const" | "using", + kind: "var" | "let" | "const" | "using" | "await using", ): void { const id = this.parseBindingAtom(); this.checkLVal(id, { diff --git a/packages/babel-parser/src/types.d.ts b/packages/babel-parser/src/types.d.ts index 3c178224b0bd..15fb192cebdf 100644 --- a/packages/babel-parser/src/types.d.ts +++ b/packages/babel-parser/src/types.d.ts @@ -355,7 +355,7 @@ export interface FunctionDeclaration extends OptFunctionDeclaration { export interface VariableDeclaration extends DeclarationBase, HasDecorators { type: "VariableDeclaration"; declarations: VariableDeclarator[]; - kind: "var" | "let" | "const" | "using"; + kind: "var" | "let" | "const" | "using" | "await using"; } export interface VariableDeclarator extends NodeBase { diff --git a/packages/babel-parser/src/typings.d.ts b/packages/babel-parser/src/typings.d.ts index 3ed4a5c70b59..bfde3490be83 100644 --- a/packages/babel-parser/src/typings.d.ts +++ b/packages/babel-parser/src/typings.d.ts @@ -1,5 +1,6 @@ export type Plugin = | "asyncDoExpressions" + | "asyncExplicitResourceManagement" | "asyncGenerators" | "bigInt" | "classPrivateMethods" diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/input.js new file mode 100644 index 000000000000..0f2a5dfcc635 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/input.js @@ -0,0 +1,3 @@ +async function f() { + await using reader = getReader(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/options.json new file mode 100644 index 000000000000..63a3dde712b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/options.json @@ -0,0 +1,3 @@ +{ + "throws": "This experimental syntax requires enabling the parser plugin: \"asyncExplicitResourceManagement\". (2:2)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-duplicate-using-bindings/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-duplicate-using-bindings/input.js new file mode 100644 index 000000000000..82743cd3b697 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-duplicate-using-bindings/input.js @@ -0,0 +1,9 @@ +async function f() { + { + await using f, f = foo(); + } + { + await using g = foo(); + await using g = foo(); + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-duplicate-using-bindings/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-duplicate-using-bindings/output.json new file mode 100644 index 000000000000..dd7e07bd5c34 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-duplicate-using-bindings/output.json @@ -0,0 +1,138 @@ +{ + "type": "File", + "start":0,"end":122,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":9,"column":1,"index":122}}, + "errors": [ + "SyntaxError: Identifier 'f' has already been declared. (3:19)", + "SyntaxError: Identifier 'g' has already been declared. (7:16)" + ], + "program": { + "type": "Program", + "start":0,"end":122,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":9,"column":1,"index":122}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":122,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":9,"column":1,"index":122}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":122,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":9,"column":1,"index":122}}, + "body": [ + { + "type": "BlockStatement", + "start":23,"end":58,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":4,"column":3,"index":58}}, + "body": [ + { + "type": "VariableDeclaration", + "start":29,"end":54,"loc":{"start":{"line":3,"column":4,"index":29},"end":{"line":3,"column":29,"index":54}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":41,"end":42,"loc":{"start":{"line":3,"column":16,"index":41},"end":{"line":3,"column":17,"index":42}}, + "id": { + "type": "Identifier", + "start":41,"end":42,"loc":{"start":{"line":3,"column":16,"index":41},"end":{"line":3,"column":17,"index":42},"identifierName":"f"}, + "name": "f" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start":44,"end":53,"loc":{"start":{"line":3,"column":19,"index":44},"end":{"line":3,"column":28,"index":53}}, + "id": { + "type": "Identifier", + "start":44,"end":45,"loc":{"start":{"line":3,"column":19,"index":44},"end":{"line":3,"column":20,"index":45},"identifierName":"f"}, + "name": "f" + }, + "init": { + "type": "CallExpression", + "start":48,"end":53,"loc":{"start":{"line":3,"column":23,"index":48},"end":{"line":3,"column":28,"index":53}}, + "callee": { + "type": "Identifier", + "start":48,"end":51,"loc":{"start":{"line":3,"column":23,"index":48},"end":{"line":3,"column":26,"index":51},"identifierName":"foo"}, + "name": "foo" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + }, + { + "type": "BlockStatement", + "start":61,"end":120,"loc":{"start":{"line":5,"column":2,"index":61},"end":{"line":8,"column":3,"index":120}}, + "body": [ + { + "type": "VariableDeclaration", + "start":67,"end":89,"loc":{"start":{"line":6,"column":4,"index":67},"end":{"line":6,"column":26,"index":89}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":79,"end":88,"loc":{"start":{"line":6,"column":16,"index":79},"end":{"line":6,"column":25,"index":88}}, + "id": { + "type": "Identifier", + "start":79,"end":80,"loc":{"start":{"line":6,"column":16,"index":79},"end":{"line":6,"column":17,"index":80},"identifierName":"g"}, + "name": "g" + }, + "init": { + "type": "CallExpression", + "start":83,"end":88,"loc":{"start":{"line":6,"column":20,"index":83},"end":{"line":6,"column":25,"index":88}}, + "callee": { + "type": "Identifier", + "start":83,"end":86,"loc":{"start":{"line":6,"column":20,"index":83},"end":{"line":6,"column":23,"index":86},"identifierName":"foo"}, + "name": "foo" + }, + "arguments": [] + } + } + ], + "kind": "await using" + }, + { + "type": "VariableDeclaration", + "start":94,"end":116,"loc":{"start":{"line":7,"column":4,"index":94},"end":{"line":7,"column":26,"index":116}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":106,"end":115,"loc":{"start":{"line":7,"column":16,"index":106},"end":{"line":7,"column":25,"index":115}}, + "id": { + "type": "Identifier", + "start":106,"end":107,"loc":{"start":{"line":7,"column":16,"index":106},"end":{"line":7,"column":17,"index":107},"identifierName":"g"}, + "name": "g" + }, + "init": { + "type": "CallExpression", + "start":110,"end":115,"loc":{"start":{"line":7,"column":20,"index":110},"end":{"line":7,"column":25,"index":115}}, + "callee": { + "type": "Identifier", + "start":110,"end":113,"loc":{"start":{"line":7,"column":20,"index":110},"end":{"line":7,"column":23,"index":113},"identifierName":"foo"}, + "name": "foo" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-export-await-using/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-export-await-using/input.js new file mode 100644 index 000000000000..d9e7b79c9b5c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-export-await-using/input.js @@ -0,0 +1 @@ +export await using basic = reader(); diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-export-await-using/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-export-await-using/options.json new file mode 100644 index 000000000000..9b76c337e1c3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-export-await-using/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token, expected \"{\" (1:7)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-linebreak-using/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-linebreak-using/input.js new file mode 100644 index 000000000000..60ebc45937a4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-linebreak-using/input.js @@ -0,0 +1,4 @@ +async function f() { + for (await + using basic of []); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-linebreak-using/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-linebreak-using/options.json new file mode 100644 index 000000000000..28c00573d82c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-linebreak-using/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (3:20)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-using-linebreak/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-using-linebreak/input.js new file mode 100644 index 000000000000..5602d169cd23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-using-linebreak/input.js @@ -0,0 +1,4 @@ +async function f() { + for (await using + basic of []); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-using-linebreak/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-using-linebreak/options.json new file mode 100644 index 000000000000..42f104b62d0b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-for-of-await-using-linebreak/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (3:14)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-in-single-statement-context/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-in-single-statement-context/input.js new file mode 100644 index 000000000000..e27ea3014676 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-in-single-statement-context/input.js @@ -0,0 +1,8 @@ +async function f() { + while (1) await using a; + for (;;) await using b; + do await using c; while (1); + if (1) await using d; + with (1) await using e; + label: await using f; +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-in-single-statement-context/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-in-single-statement-context/output.json new file mode 100644 index 000000000000..8e74752facbc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-in-single-statement-context/output.json @@ -0,0 +1,211 @@ +{ + "type": "File", + "start":0,"end":180,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":8,"column":1,"index":180}}, + "errors": [ + "SyntaxError: Lexical declaration cannot appear in a single-statement context. (2:12)", + "SyntaxError: Lexical declaration cannot appear in a single-statement context. (3:11)", + "SyntaxError: Lexical declaration cannot appear in a single-statement context. (4:5)", + "SyntaxError: Lexical declaration cannot appear in a single-statement context. (5:9)", + "SyntaxError: Lexical declaration cannot appear in a single-statement context. (6:11)", + "SyntaxError: Lexical declaration cannot appear in a single-statement context. (7:9)" + ], + "program": { + "type": "Program", + "start":0,"end":180,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":8,"column":1,"index":180}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":180,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":8,"column":1,"index":180}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":180,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":8,"column":1,"index":180}}, + "body": [ + { + "type": "WhileStatement", + "start":23,"end":47,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":26,"index":47}}, + "test": { + "type": "NumericLiteral", + "start":30,"end":31,"loc":{"start":{"line":2,"column":9,"index":30},"end":{"line":2,"column":10,"index":31}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "body": { + "type": "VariableDeclaration", + "start":33,"end":47,"loc":{"start":{"line":2,"column":12,"index":33},"end":{"line":2,"column":26,"index":47}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":45,"end":46,"loc":{"start":{"line":2,"column":24,"index":45},"end":{"line":2,"column":25,"index":46}}, + "id": { + "type": "Identifier", + "start":45,"end":46,"loc":{"start":{"line":2,"column":24,"index":45},"end":{"line":2,"column":25,"index":46},"identifierName":"a"}, + "name": "a" + }, + "init": null + } + ], + "kind": "await using" + } + }, + { + "type": "ForStatement", + "start":50,"end":73,"loc":{"start":{"line":3,"column":2,"index":50},"end":{"line":3,"column":25,"index":73}}, + "init": null, + "test": null, + "update": null, + "body": { + "type": "VariableDeclaration", + "start":59,"end":73,"loc":{"start":{"line":3,"column":11,"index":59},"end":{"line":3,"column":25,"index":73}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":71,"end":72,"loc":{"start":{"line":3,"column":23,"index":71},"end":{"line":3,"column":24,"index":72}}, + "id": { + "type": "Identifier", + "start":71,"end":72,"loc":{"start":{"line":3,"column":23,"index":71},"end":{"line":3,"column":24,"index":72},"identifierName":"b"}, + "name": "b" + }, + "init": null + } + ], + "kind": "await using" + } + }, + { + "type": "DoWhileStatement", + "start":76,"end":104,"loc":{"start":{"line":4,"column":2,"index":76},"end":{"line":4,"column":30,"index":104}}, + "body": { + "type": "VariableDeclaration", + "start":79,"end":93,"loc":{"start":{"line":4,"column":5,"index":79},"end":{"line":4,"column":19,"index":93}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":91,"end":92,"loc":{"start":{"line":4,"column":17,"index":91},"end":{"line":4,"column":18,"index":92}}, + "id": { + "type": "Identifier", + "start":91,"end":92,"loc":{"start":{"line":4,"column":17,"index":91},"end":{"line":4,"column":18,"index":92},"identifierName":"c"}, + "name": "c" + }, + "init": null + } + ], + "kind": "await using" + }, + "test": { + "type": "NumericLiteral", + "start":101,"end":102,"loc":{"start":{"line":4,"column":27,"index":101},"end":{"line":4,"column":28,"index":102}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "IfStatement", + "start":107,"end":128,"loc":{"start":{"line":5,"column":2,"index":107},"end":{"line":5,"column":23,"index":128}}, + "test": { + "type": "NumericLiteral", + "start":111,"end":112,"loc":{"start":{"line":5,"column":6,"index":111},"end":{"line":5,"column":7,"index":112}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "consequent": { + "type": "VariableDeclaration", + "start":114,"end":128,"loc":{"start":{"line":5,"column":9,"index":114},"end":{"line":5,"column":23,"index":128}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":126,"end":127,"loc":{"start":{"line":5,"column":21,"index":126},"end":{"line":5,"column":22,"index":127}}, + "id": { + "type": "Identifier", + "start":126,"end":127,"loc":{"start":{"line":5,"column":21,"index":126},"end":{"line":5,"column":22,"index":127},"identifierName":"d"}, + "name": "d" + }, + "init": null + } + ], + "kind": "await using" + }, + "alternate": null + }, + { + "type": "WithStatement", + "start":131,"end":154,"loc":{"start":{"line":6,"column":2,"index":131},"end":{"line":6,"column":25,"index":154}}, + "object": { + "type": "NumericLiteral", + "start":137,"end":138,"loc":{"start":{"line":6,"column":8,"index":137},"end":{"line":6,"column":9,"index":138}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "body": { + "type": "VariableDeclaration", + "start":140,"end":154,"loc":{"start":{"line":6,"column":11,"index":140},"end":{"line":6,"column":25,"index":154}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":152,"end":153,"loc":{"start":{"line":6,"column":23,"index":152},"end":{"line":6,"column":24,"index":153}}, + "id": { + "type": "Identifier", + "start":152,"end":153,"loc":{"start":{"line":6,"column":23,"index":152},"end":{"line":6,"column":24,"index":153},"identifierName":"e"}, + "name": "e" + }, + "init": null + } + ], + "kind": "await using" + } + }, + { + "type": "LabeledStatement", + "start":157,"end":178,"loc":{"start":{"line":7,"column":2,"index":157},"end":{"line":7,"column":23,"index":178}}, + "body": { + "type": "VariableDeclaration", + "start":164,"end":178,"loc":{"start":{"line":7,"column":9,"index":164},"end":{"line":7,"column":23,"index":178}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":176,"end":177,"loc":{"start":{"line":7,"column":21,"index":176},"end":{"line":7,"column":22,"index":177}}, + "id": { + "type": "Identifier", + "start":176,"end":177,"loc":{"start":{"line":7,"column":21,"index":176},"end":{"line":7,"column":22,"index":177},"identifierName":"f"}, + "name": "f" + }, + "init": null + } + ], + "kind": "await using" + }, + "label": { + "type": "Identifier", + "start":157,"end":162,"loc":{"start":{"line":7,"column":2,"index":157},"end":{"line":7,"column":7,"index":162},"identifierName":"label"}, + "name": "label" + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/input.js new file mode 100644 index 000000000000..587d0b393803 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/input.js @@ -0,0 +1 @@ +label: await using x = bar(); diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/options.json new file mode 100644 index 000000000000..b412ffe6712f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "script" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/output.json new file mode 100644 index 000000000000..944dd71fb6d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-labeled-using-binding/output.json @@ -0,0 +1,51 @@ +{ + "type": "File", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":29,"index":29}}, + "errors": [ + "SyntaxError: 'await using' is only allowed within async functions and at the top levels of modules. (1:7)" + ], + "program": { + "type": "Program", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":29,"index":29}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "LabeledStatement", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":29,"index":29}}, + "body": { + "type": "VariableDeclaration", + "start":7,"end":29,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":29,"index":29}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":19,"end":28,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":28,"index":28}}, + "id": { + "type": "Identifier", + "start":19,"end":20,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":20,"index":20},"identifierName":"x"}, + "name": "x" + }, + "init": { + "type": "CallExpression", + "start":23,"end":28,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":28,"index":28}}, + "callee": { + "type": "Identifier", + "start":23,"end":26,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":26,"index":26},"identifierName":"bar"}, + "name": "bar" + }, + "arguments": [] + } + } + ], + "kind": "await using" + }, + "label": { + "type": "Identifier", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":5,"index":5},"identifierName":"label"}, + "name": "label" + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/input.js new file mode 100644 index 000000000000..c806400a3d76 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/input.js @@ -0,0 +1 @@ +await using x = bar(); diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/options.json new file mode 100644 index 000000000000..b412ffe6712f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "script" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/output.json new file mode 100644 index 000000000000..bb1c9a28d166 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-script-top-level-using-binding/output.json @@ -0,0 +1,42 @@ +{ + "type": "File", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, + "errors": [ + "SyntaxError: 'await using' is only allowed within async functions and at the top levels of modules. (1:0)" + ], + "program": { + "type": "Program", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":12,"end":21,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":21,"index":21}}, + "id": { + "type": "Identifier", + "start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13},"identifierName":"x"}, + "name": "x" + }, + "init": { + "type": "CallExpression", + "start":16,"end":21,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":21,"index":21}}, + "callee": { + "type": "Identifier", + "start":16,"end":19,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":19,"index":19},"identifierName":"bar"}, + "name": "bar" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/input.js new file mode 100644 index 000000000000..c8bfd7d35a2a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/input.js @@ -0,0 +1,12 @@ +async function f () { + await using await = h(); +} +async function g () { + await using \u0061wait = h(); +} +async function h () { + await using x, await = h(); +} +async function i () { + for (await using await of []); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/output.json new file mode 100644 index 000000000000..9c85f9b4860d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-module/output.json @@ -0,0 +1,214 @@ +{ + "type": "File", + "start":0,"end":217,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":12,"column":1,"index":217}}, + "errors": [ + "SyntaxError: Unexpected reserved word 'await'. (2:14)", + "SyntaxError: Unexpected reserved word 'await'. (5:14)", + "SyntaxError: Unexpected reserved word 'await'. (8:17)", + "SyntaxError: Unexpected reserved word 'await'. (11:19)" + ], + "program": { + "type": "Program", + "start":0,"end":217,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":12,"column":1,"index":217}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":50,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":50}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":20,"end":50,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":3,"column":1,"index":50}}, + "body": [ + { + "type": "VariableDeclaration", + "start":24,"end":48,"loc":{"start":{"line":2,"column":2,"index":24},"end":{"line":2,"column":26,"index":48}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":36,"end":47,"loc":{"start":{"line":2,"column":14,"index":36},"end":{"line":2,"column":25,"index":47}}, + "id": { + "type": "Identifier", + "start":36,"end":41,"loc":{"start":{"line":2,"column":14,"index":36},"end":{"line":2,"column":19,"index":41},"identifierName":"await"}, + "name": "await" + }, + "init": { + "type": "CallExpression", + "start":44,"end":47,"loc":{"start":{"line":2,"column":22,"index":44},"end":{"line":2,"column":25,"index":47}}, + "callee": { + "type": "Identifier", + "start":44,"end":45,"loc":{"start":{"line":2,"column":22,"index":44},"end":{"line":2,"column":23,"index":45},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":51,"end":106,"loc":{"start":{"line":4,"column":0,"index":51},"end":{"line":6,"column":1,"index":106}}, + "id": { + "type": "Identifier", + "start":66,"end":67,"loc":{"start":{"line":4,"column":15,"index":66},"end":{"line":4,"column":16,"index":67},"identifierName":"g"}, + "name": "g" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":71,"end":106,"loc":{"start":{"line":4,"column":20,"index":71},"end":{"line":6,"column":1,"index":106}}, + "body": [ + { + "type": "VariableDeclaration", + "start":75,"end":104,"loc":{"start":{"line":5,"column":2,"index":75},"end":{"line":5,"column":31,"index":104}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":87,"end":103,"loc":{"start":{"line":5,"column":14,"index":87},"end":{"line":5,"column":30,"index":103}}, + "id": { + "type": "Identifier", + "start":87,"end":97,"loc":{"start":{"line":5,"column":14,"index":87},"end":{"line":5,"column":24,"index":97},"identifierName":"await"}, + "name": "await" + }, + "init": { + "type": "CallExpression", + "start":100,"end":103,"loc":{"start":{"line":5,"column":27,"index":100},"end":{"line":5,"column":30,"index":103}}, + "callee": { + "type": "Identifier", + "start":100,"end":101,"loc":{"start":{"line":5,"column":27,"index":100},"end":{"line":5,"column":28,"index":101},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":107,"end":160,"loc":{"start":{"line":7,"column":0,"index":107},"end":{"line":9,"column":1,"index":160}}, + "id": { + "type": "Identifier", + "start":122,"end":123,"loc":{"start":{"line":7,"column":15,"index":122},"end":{"line":7,"column":16,"index":123},"identifierName":"h"}, + "name": "h" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":127,"end":160,"loc":{"start":{"line":7,"column":20,"index":127},"end":{"line":9,"column":1,"index":160}}, + "body": [ + { + "type": "VariableDeclaration", + "start":131,"end":158,"loc":{"start":{"line":8,"column":2,"index":131},"end":{"line":8,"column":29,"index":158}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":143,"end":144,"loc":{"start":{"line":8,"column":14,"index":143},"end":{"line":8,"column":15,"index":144}}, + "id": { + "type": "Identifier", + "start":143,"end":144,"loc":{"start":{"line":8,"column":14,"index":143},"end":{"line":8,"column":15,"index":144},"identifierName":"x"}, + "name": "x" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start":146,"end":157,"loc":{"start":{"line":8,"column":17,"index":146},"end":{"line":8,"column":28,"index":157}}, + "id": { + "type": "Identifier", + "start":146,"end":151,"loc":{"start":{"line":8,"column":17,"index":146},"end":{"line":8,"column":22,"index":151},"identifierName":"await"}, + "name": "await" + }, + "init": { + "type": "CallExpression", + "start":154,"end":157,"loc":{"start":{"line":8,"column":25,"index":154},"end":{"line":8,"column":28,"index":157}}, + "callee": { + "type": "Identifier", + "start":154,"end":155,"loc":{"start":{"line":8,"column":25,"index":154},"end":{"line":8,"column":26,"index":155},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":161,"end":217,"loc":{"start":{"line":10,"column":0,"index":161},"end":{"line":12,"column":1,"index":217}}, + "id": { + "type": "Identifier", + "start":176,"end":177,"loc":{"start":{"line":10,"column":15,"index":176},"end":{"line":10,"column":16,"index":177},"identifierName":"i"}, + "name": "i" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":181,"end":217,"loc":{"start":{"line":10,"column":20,"index":181},"end":{"line":12,"column":1,"index":217}}, + "body": [ + { + "type": "ForOfStatement", + "start":185,"end":215,"loc":{"start":{"line":11,"column":2,"index":185},"end":{"line":11,"column":32,"index":215}}, + "await": false, + "left": { + "type": "VariableDeclaration", + "start":190,"end":207,"loc":{"start":{"line":11,"column":7,"index":190},"end":{"line":11,"column":24,"index":207}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":202,"end":207,"loc":{"start":{"line":11,"column":19,"index":202},"end":{"line":11,"column":24,"index":207}}, + "id": { + "type": "Identifier", + "start":202,"end":207,"loc":{"start":{"line":11,"column":19,"index":202},"end":{"line":11,"column":24,"index":207},"identifierName":"await"}, + "name": "await" + }, + "init": null + } + ], + "kind": "await using" + }, + "right": { + "type": "ArrayExpression", + "start":211,"end":213,"loc":{"start":{"line":11,"column":28,"index":211},"end":{"line":11,"column":30,"index":213}}, + "elements": [] + }, + "body": { + "type": "EmptyStatement", + "start":214,"end":215,"loc":{"start":{"line":11,"column":31,"index":214},"end":{"line":11,"column":32,"index":215}} + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/input.js new file mode 100644 index 000000000000..ec9efef0a8e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/input.js @@ -0,0 +1,12 @@ +async function f() { + await using await = h(); +} +async function f() { + await using \u0061wait = h(); +} +async function f() { + await using x, await = h(); +} +async function f() { + for (await using await of []); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/options.json new file mode 100644 index 000000000000..b412ffe6712f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "script" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/output.json new file mode 100644 index 000000000000..e8bd0314fa0d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-await-script/output.json @@ -0,0 +1,214 @@ +{ + "type": "File", + "start":0,"end":213,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":12,"column":1,"index":213}}, + "errors": [ + "SyntaxError: Can not use 'await' as identifier inside an async function. (2:14)", + "SyntaxError: Can not use 'await' as identifier inside an async function. (5:14)", + "SyntaxError: Can not use 'await' as identifier inside an async function. (8:17)", + "SyntaxError: Can not use 'await' as identifier inside an async function. (11:19)" + ], + "program": { + "type": "Program", + "start":0,"end":213,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":12,"column":1,"index":213}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":49,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":49}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":49,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":49}}, + "body": [ + { + "type": "VariableDeclaration", + "start":23,"end":47,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":26,"index":47}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":35,"end":46,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":25,"index":46}}, + "id": { + "type": "Identifier", + "start":35,"end":40,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":19,"index":40},"identifierName":"await"}, + "name": "await" + }, + "init": { + "type": "CallExpression", + "start":43,"end":46,"loc":{"start":{"line":2,"column":22,"index":43},"end":{"line":2,"column":25,"index":46}}, + "callee": { + "type": "Identifier", + "start":43,"end":44,"loc":{"start":{"line":2,"column":22,"index":43},"end":{"line":2,"column":23,"index":44},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":50,"end":104,"loc":{"start":{"line":4,"column":0,"index":50},"end":{"line":6,"column":1,"index":104}}, + "id": { + "type": "Identifier", + "start":65,"end":66,"loc":{"start":{"line":4,"column":15,"index":65},"end":{"line":4,"column":16,"index":66},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":69,"end":104,"loc":{"start":{"line":4,"column":19,"index":69},"end":{"line":6,"column":1,"index":104}}, + "body": [ + { + "type": "VariableDeclaration", + "start":73,"end":102,"loc":{"start":{"line":5,"column":2,"index":73},"end":{"line":5,"column":31,"index":102}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":85,"end":101,"loc":{"start":{"line":5,"column":14,"index":85},"end":{"line":5,"column":30,"index":101}}, + "id": { + "type": "Identifier", + "start":85,"end":95,"loc":{"start":{"line":5,"column":14,"index":85},"end":{"line":5,"column":24,"index":95},"identifierName":"await"}, + "name": "await" + }, + "init": { + "type": "CallExpression", + "start":98,"end":101,"loc":{"start":{"line":5,"column":27,"index":98},"end":{"line":5,"column":30,"index":101}}, + "callee": { + "type": "Identifier", + "start":98,"end":99,"loc":{"start":{"line":5,"column":27,"index":98},"end":{"line":5,"column":28,"index":99},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":105,"end":157,"loc":{"start":{"line":7,"column":0,"index":105},"end":{"line":9,"column":1,"index":157}}, + "id": { + "type": "Identifier", + "start":120,"end":121,"loc":{"start":{"line":7,"column":15,"index":120},"end":{"line":7,"column":16,"index":121},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":124,"end":157,"loc":{"start":{"line":7,"column":19,"index":124},"end":{"line":9,"column":1,"index":157}}, + "body": [ + { + "type": "VariableDeclaration", + "start":128,"end":155,"loc":{"start":{"line":8,"column":2,"index":128},"end":{"line":8,"column":29,"index":155}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":140,"end":141,"loc":{"start":{"line":8,"column":14,"index":140},"end":{"line":8,"column":15,"index":141}}, + "id": { + "type": "Identifier", + "start":140,"end":141,"loc":{"start":{"line":8,"column":14,"index":140},"end":{"line":8,"column":15,"index":141},"identifierName":"x"}, + "name": "x" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start":143,"end":154,"loc":{"start":{"line":8,"column":17,"index":143},"end":{"line":8,"column":28,"index":154}}, + "id": { + "type": "Identifier", + "start":143,"end":148,"loc":{"start":{"line":8,"column":17,"index":143},"end":{"line":8,"column":22,"index":148},"identifierName":"await"}, + "name": "await" + }, + "init": { + "type": "CallExpression", + "start":151,"end":154,"loc":{"start":{"line":8,"column":25,"index":151},"end":{"line":8,"column":28,"index":154}}, + "callee": { + "type": "Identifier", + "start":151,"end":152,"loc":{"start":{"line":8,"column":25,"index":151},"end":{"line":8,"column":26,"index":152},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":158,"end":213,"loc":{"start":{"line":10,"column":0,"index":158},"end":{"line":12,"column":1,"index":213}}, + "id": { + "type": "Identifier", + "start":173,"end":174,"loc":{"start":{"line":10,"column":15,"index":173},"end":{"line":10,"column":16,"index":174},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":177,"end":213,"loc":{"start":{"line":10,"column":19,"index":177},"end":{"line":12,"column":1,"index":213}}, + "body": [ + { + "type": "ForOfStatement", + "start":181,"end":211,"loc":{"start":{"line":11,"column":2,"index":181},"end":{"line":11,"column":32,"index":211}}, + "await": false, + "left": { + "type": "VariableDeclaration", + "start":186,"end":203,"loc":{"start":{"line":11,"column":7,"index":186},"end":{"line":11,"column":24,"index":203}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":198,"end":203,"loc":{"start":{"line":11,"column":19,"index":198},"end":{"line":11,"column":24,"index":203}}, + "id": { + "type": "Identifier", + "start":198,"end":203,"loc":{"start":{"line":11,"column":19,"index":198},"end":{"line":11,"column":24,"index":203},"identifierName":"await"}, + "name": "await" + }, + "init": null + } + ], + "kind": "await using" + }, + "right": { + "type": "ArrayExpression", + "start":207,"end":209,"loc":{"start":{"line":11,"column":28,"index":207},"end":{"line":11,"column":30,"index":209}}, + "elements": [] + }, + "body": { + "type": "EmptyStatement", + "start":210,"end":211,"loc":{"start":{"line":11,"column":31,"index":210},"end":{"line":11,"column":32,"index":211}} + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-let/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-let/input.js new file mode 100644 index 000000000000..0c5b099a054a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-let/input.js @@ -0,0 +1,3 @@ +async function f() { + await using let = h(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-let/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-let/output.json new file mode 100644 index 000000000000..cfcf5c87b6d5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-binding-let/output.json @@ -0,0 +1,61 @@ +{ + "type": "File", + "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":47}}, + "errors": [ + "SyntaxError: 'let' is not allowed to be used as a name in 'let' or 'const' declarations. (2:14)" + ], + "program": { + "type": "Program", + "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":47}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":47}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":47,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":47}}, + "body": [ + { + "type": "VariableDeclaration", + "start":23,"end":45,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":24,"index":45}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":35,"end":44,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":23,"index":44}}, + "id": { + "type": "Identifier", + "start":35,"end":38,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":17,"index":38},"identifierName":"let"}, + "name": "let" + }, + "init": { + "type": "CallExpression", + "start":41,"end":44,"loc":{"start":{"line":2,"column":20,"index":41},"end":{"line":2,"column":23,"index":44}}, + "callee": { + "type": "Identifier", + "start":41,"end":42,"loc":{"start":{"line":2,"column":20,"index":41},"end":{"line":2,"column":21,"index":42},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-decl-as-expr/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-decl-as-expr/input.js new file mode 100644 index 000000000000..20339d0061d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-decl-as-expr/input.js @@ -0,0 +1,3 @@ +async function f() { + 0,await using basic = getReader(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-decl-as-expr/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-decl-as-expr/output.json new file mode 100644 index 000000000000..3049dad6556c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-decl-as-expr/output.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start":0,"end":59,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":59}}, + "errors": [ + "SyntaxError: Missing semicolon. (2:15)" + ], + "program": { + "type": "Program", + "start":0,"end":59,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":59}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":59,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":59}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":59,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":59}}, + "body": [ + { + "type": "ExpressionStatement", + "start":23,"end":36,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":15,"index":36}}, + "expression": { + "type": "SequenceExpression", + "start":23,"end":36,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":15,"index":36}}, + "expressions": [ + { + "type": "NumericLiteral", + "start":23,"end":24,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":3,"index":24}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + { + "type": "AwaitExpression", + "start":25,"end":36,"loc":{"start":{"line":2,"column":4,"index":25},"end":{"line":2,"column":15,"index":36}}, + "argument": { + "type": "Identifier", + "start":31,"end":36,"loc":{"start":{"line":2,"column":10,"index":31},"end":{"line":2,"column":15,"index":36},"identifierName":"using"}, + "name": "using" + } + } + ] + } + }, + { + "type": "ExpressionStatement", + "start":37,"end":57,"loc":{"start":{"line":2,"column":16,"index":37},"end":{"line":2,"column":36,"index":57}}, + "expression": { + "type": "AssignmentExpression", + "start":37,"end":56,"loc":{"start":{"line":2,"column":16,"index":37},"end":{"line":2,"column":35,"index":56}}, + "operator": "=", + "left": { + "type": "Identifier", + "start":37,"end":42,"loc":{"start":{"line":2,"column":16,"index":37},"end":{"line":2,"column":21,"index":42},"identifierName":"basic"}, + "name": "basic" + }, + "right": { + "type": "CallExpression", + "start":45,"end":56,"loc":{"start":{"line":2,"column":24,"index":45},"end":{"line":2,"column":35,"index":56}}, + "callee": { + "type": "Identifier", + "start":45,"end":54,"loc":{"start":{"line":2,"column":24,"index":45},"end":{"line":2,"column":33,"index":54},"identifierName":"getReader"}, + "name": "getReader" + }, + "arguments": [] + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/options.json new file mode 100644 index 000000000000..48bceee79c05 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["asyncExplicitResourceManagement"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/input.js new file mode 100644 index 000000000000..b998a037e1b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/input.js @@ -0,0 +1,5 @@ +{ + await + using + using = h(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/options.json new file mode 100644 index 000000000000..ff1d688a13e9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["asyncExplicitResourceManagement", "explicitResourceManagement"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/output.json new file mode 100644 index 000000000000..3b50e9416eed --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/output.json @@ -0,0 +1,62 @@ +{ + "type": "File", + "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":5,"column":1,"index":34}}, + "program": { + "type": "Program", + "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":5,"column":1,"index":34}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "BlockStatement", + "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":5,"column":1,"index":34}}, + "body": [ + { + "type": "ExpressionStatement", + "start":4,"end":9,"loc":{"start":{"line":2,"column":2,"index":4},"end":{"line":2,"column":7,"index":9}}, + "expression": { + "type": "Identifier", + "start":4,"end":9,"loc":{"start":{"line":2,"column":2,"index":4},"end":{"line":2,"column":7,"index":9},"identifierName":"await"}, + "name": "await" + } + }, + { + "type": "ExpressionStatement", + "start":12,"end":17,"loc":{"start":{"line":3,"column":2,"index":12},"end":{"line":3,"column":7,"index":17}}, + "expression": { + "type": "Identifier", + "start":12,"end":17,"loc":{"start":{"line":3,"column":2,"index":12},"end":{"line":3,"column":7,"index":17},"identifierName":"using"}, + "name": "using" + } + }, + { + "type": "ExpressionStatement", + "start":20,"end":32,"loc":{"start":{"line":4,"column":2,"index":20},"end":{"line":4,"column":14,"index":32}}, + "expression": { + "type": "AssignmentExpression", + "start":20,"end":31,"loc":{"start":{"line":4,"column":2,"index":20},"end":{"line":4,"column":13,"index":31}}, + "operator": "=", + "left": { + "type": "Identifier", + "start":20,"end":25,"loc":{"start":{"line":4,"column":2,"index":20},"end":{"line":4,"column":7,"index":25},"identifierName":"using"}, + "name": "using" + }, + "right": { + "type": "CallExpression", + "start":28,"end":31,"loc":{"start":{"line":4,"column":10,"index":28},"end":{"line":4,"column":13,"index":31}}, + "callee": { + "type": "Identifier", + "start":28,"end":29,"loc":{"start":{"line":4,"column":10,"index":28},"end":{"line":4,"column":11,"index":29},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + } + ], + "directives": [] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/input.js new file mode 100644 index 000000000000..45cd3bc387d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/input.js @@ -0,0 +1,4 @@ +{ + await + using using = h(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/options.json new file mode 100644 index 000000000000..ff1d688a13e9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["asyncExplicitResourceManagement", "explicitResourceManagement"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/output.json new file mode 100644 index 000000000000..f948cf34a652 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/output.json @@ -0,0 +1,55 @@ +{ + "type": "File", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":32}}, + "program": { + "type": "Program", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":32}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "BlockStatement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":32}}, + "body": [ + { + "type": "ExpressionStatement", + "start":4,"end":9,"loc":{"start":{"line":2,"column":2,"index":4},"end":{"line":2,"column":7,"index":9}}, + "expression": { + "type": "Identifier", + "start":4,"end":9,"loc":{"start":{"line":2,"column":2,"index":4},"end":{"line":2,"column":7,"index":9},"identifierName":"await"}, + "name": "await" + } + }, + { + "type": "VariableDeclaration", + "start":12,"end":30,"loc":{"start":{"line":3,"column":2,"index":12},"end":{"line":3,"column":20,"index":30}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":18,"end":29,"loc":{"start":{"line":3,"column":8,"index":18},"end":{"line":3,"column":19,"index":29}}, + "id": { + "type": "Identifier", + "start":18,"end":23,"loc":{"start":{"line":3,"column":8,"index":18},"end":{"line":3,"column":13,"index":23},"identifierName":"using"}, + "name": "using" + }, + "init": { + "type": "CallExpression", + "start":26,"end":29,"loc":{"start":{"line":3,"column":16,"index":26},"end":{"line":3,"column":19,"index":29}}, + "callee": { + "type": "Identifier", + "start":26,"end":27,"loc":{"start":{"line":3,"column":16,"index":26},"end":{"line":3,"column":17,"index":27},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + ], + "kind": "using" + } + ], + "directives": [] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using/input.js new file mode 100644 index 000000000000..f056de21db03 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using/input.js @@ -0,0 +1,4 @@ +async function f() { + await using[x]; + await using.x + await using(x) ? await using?.x : await using`x`; +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using/output.json new file mode 100644 index 000000000000..c67aa7c336b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using/output.json @@ -0,0 +1,156 @@ +{ + "type": "File", + "start":0,"end":108,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":108}}, + "program": { + "type": "Program", + "start":0,"end":108,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":108}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":108,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":108}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":108,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":4,"column":1,"index":108}}, + "body": [ + { + "type": "ExpressionStatement", + "start":23,"end":38,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":17,"index":38}}, + "expression": { + "type": "AwaitExpression", + "start":23,"end":37,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":16,"index":37}}, + "argument": { + "type": "MemberExpression", + "start":29,"end":37,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":16,"index":37}}, + "object": { + "type": "Identifier", + "start":29,"end":34,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":13,"index":34},"identifierName":"using"}, + "name": "using" + }, + "computed": true, + "property": { + "type": "Identifier", + "start":35,"end":36,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":15,"index":36},"identifierName":"x"}, + "name": "x" + } + } + } + }, + { + "type": "ExpressionStatement", + "start":41,"end":106,"loc":{"start":{"line":3,"column":2,"index":41},"end":{"line":3,"column":67,"index":106}}, + "expression": { + "type": "ConditionalExpression", + "start":41,"end":105,"loc":{"start":{"line":3,"column":2,"index":41},"end":{"line":3,"column":66,"index":105}}, + "test": { + "type": "BinaryExpression", + "start":41,"end":71,"loc":{"start":{"line":3,"column":2,"index":41},"end":{"line":3,"column":32,"index":71}}, + "left": { + "type": "AwaitExpression", + "start":41,"end":54,"loc":{"start":{"line":3,"column":2,"index":41},"end":{"line":3,"column":15,"index":54}}, + "argument": { + "type": "MemberExpression", + "start":47,"end":54,"loc":{"start":{"line":3,"column":8,"index":47},"end":{"line":3,"column":15,"index":54}}, + "object": { + "type": "Identifier", + "start":47,"end":52,"loc":{"start":{"line":3,"column":8,"index":47},"end":{"line":3,"column":13,"index":52},"identifierName":"using"}, + "name": "using" + }, + "computed": false, + "property": { + "type": "Identifier", + "start":53,"end":54,"loc":{"start":{"line":3,"column":14,"index":53},"end":{"line":3,"column":15,"index":54},"identifierName":"x"}, + "name": "x" + } + } + }, + "operator": "+", + "right": { + "type": "AwaitExpression", + "start":57,"end":71,"loc":{"start":{"line":3,"column":18,"index":57},"end":{"line":3,"column":32,"index":71}}, + "argument": { + "type": "CallExpression", + "start":63,"end":71,"loc":{"start":{"line":3,"column":24,"index":63},"end":{"line":3,"column":32,"index":71}}, + "callee": { + "type": "Identifier", + "start":63,"end":68,"loc":{"start":{"line":3,"column":24,"index":63},"end":{"line":3,"column":29,"index":68},"identifierName":"using"}, + "name": "using" + }, + "arguments": [ + { + "type": "Identifier", + "start":69,"end":70,"loc":{"start":{"line":3,"column":30,"index":69},"end":{"line":3,"column":31,"index":70},"identifierName":"x"}, + "name": "x" + } + ] + } + } + }, + "consequent": { + "type": "AwaitExpression", + "start":74,"end":88,"loc":{"start":{"line":3,"column":35,"index":74},"end":{"line":3,"column":49,"index":88}}, + "argument": { + "type": "OptionalMemberExpression", + "start":80,"end":88,"loc":{"start":{"line":3,"column":41,"index":80},"end":{"line":3,"column":49,"index":88}}, + "object": { + "type": "Identifier", + "start":80,"end":85,"loc":{"start":{"line":3,"column":41,"index":80},"end":{"line":3,"column":46,"index":85},"identifierName":"using"}, + "name": "using" + }, + "computed": false, + "property": { + "type": "Identifier", + "start":87,"end":88,"loc":{"start":{"line":3,"column":48,"index":87},"end":{"line":3,"column":49,"index":88},"identifierName":"x"}, + "name": "x" + }, + "optional": true + } + }, + "alternate": { + "type": "AwaitExpression", + "start":91,"end":105,"loc":{"start":{"line":3,"column":52,"index":91},"end":{"line":3,"column":66,"index":105}}, + "argument": { + "type": "TaggedTemplateExpression", + "start":97,"end":105,"loc":{"start":{"line":3,"column":58,"index":97},"end":{"line":3,"column":66,"index":105}}, + "tag": { + "type": "Identifier", + "start":97,"end":102,"loc":{"start":{"line":3,"column":58,"index":97},"end":{"line":3,"column":63,"index":102},"identifierName":"using"}, + "name": "using" + }, + "quasi": { + "type": "TemplateLiteral", + "start":102,"end":105,"loc":{"start":{"line":3,"column":63,"index":102},"end":{"line":3,"column":66,"index":105}}, + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start":103,"end":104,"loc":{"start":{"line":3,"column":64,"index":103},"end":{"line":3,"column":65,"index":104}}, + "value": { + "raw": "x", + "cooked": "x" + }, + "tail": true + } + ] + } + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/input.js new file mode 100644 index 000000000000..2dde3680d926 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/input.js @@ -0,0 +1,4 @@ +async function f() { + await using + using = h(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/options.json new file mode 100644 index 000000000000..ff1d688a13e9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["asyncExplicitResourceManagement", "explicitResourceManagement"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/output.json new file mode 100644 index 000000000000..988498e32e3d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/output.json @@ -0,0 +1,69 @@ +{ + "type": "File", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":51}}, + "program": { + "type": "Program", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":51}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":51}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":51,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":4,"column":1,"index":51}}, + "body": [ + { + "type": "ExpressionStatement", + "start":23,"end":34,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":13,"index":34}}, + "expression": { + "type": "AwaitExpression", + "start":23,"end":34,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":13,"index":34}}, + "argument": { + "type": "Identifier", + "start":29,"end":34,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":13,"index":34},"identifierName":"using"}, + "name": "using" + } + } + }, + { + "type": "ExpressionStatement", + "start":37,"end":49,"loc":{"start":{"line":3,"column":2,"index":37},"end":{"line":3,"column":14,"index":49}}, + "expression": { + "type": "AssignmentExpression", + "start":37,"end":48,"loc":{"start":{"line":3,"column":2,"index":37},"end":{"line":3,"column":13,"index":48}}, + "operator": "=", + "left": { + "type": "Identifier", + "start":37,"end":42,"loc":{"start":{"line":3,"column":2,"index":37},"end":{"line":3,"column":7,"index":42},"identifierName":"using"}, + "name": "using" + }, + "right": { + "type": "CallExpression", + "start":45,"end":48,"loc":{"start":{"line":3,"column":10,"index":45},"end":{"line":3,"column":13,"index":48}}, + "callee": { + "type": "Identifier", + "start":45,"end":46,"loc":{"start":{"line":3,"column":10,"index":45},"end":{"line":3,"column":11,"index":46},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-comments/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-comments/input.js new file mode 100644 index 000000000000..3ce48f45b7b2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-comments/input.js @@ -0,0 +1,14 @@ +async function f() { +{ + /*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/; +} +{ + /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; +} +{ + /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; +} +{ + /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; +} +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-comments/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-comments/output.json new file mode 100644 index 000000000000..be9e52179acb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-comments/output.json @@ -0,0 +1,607 @@ +{ + "type": "File", + "start":0,"end":313,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":14,"column":1,"index":313}}, + "program": { + "type": "Program", + "start":0,"end":313,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":14,"column":1,"index":313}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":313,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":14,"column":1,"index":313}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":313,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":14,"column":1,"index":313}}, + "body": [ + { + "type": "BlockStatement", + "start":21,"end":73,"loc":{"start":{"line":2,"column":0,"index":21},"end":{"line":4,"column":1,"index":73}}, + "body": [ + { + "type": "VariableDeclaration", + "start":30,"end":71,"loc":{"start":{"line":3,"column":7,"index":30},"end":{"line":3,"column":48,"index":71}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":50,"end":65,"loc":{"start":{"line":3,"column":27,"index":50},"end":{"line":3,"column":42,"index":65}}, + "id": { + "type": "Identifier", + "start":50,"end":51,"loc":{"start":{"line":3,"column":27,"index":50},"end":{"line":3,"column":28,"index":51},"identifierName":"b"}, + "name": "b", + "trailingComments": [ + { + "type": "CommentBlock", + "value": "3", + "start":51,"end":56,"loc":{"start":{"line":3,"column":28,"index":51},"end":{"line":3,"column":33,"index":56}} + } + ] + }, + "init": { + "type": "CallExpression", + "start":62,"end":65,"loc":{"start":{"line":3,"column":39,"index":62},"end":{"line":3,"column":42,"index":65}}, + "callee": { + "type": "Identifier", + "start":62,"end":63,"loc":{"start":{"line":3,"column":39,"index":62},"end":{"line":3,"column":40,"index":63},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "4", + "start":57,"end":62,"loc":{"start":{"line":3,"column":34,"index":57},"end":{"line":3,"column":39,"index":62}} + } + ] + }, + "trailingComments": [ + { + "type": "CommentBlock", + "value": "5", + "start":65,"end":70,"loc":{"start":{"line":3,"column":42,"index":65},"end":{"line":3,"column":47,"index":70}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "2", + "start":45,"end":50,"loc":{"start":{"line":3,"column":22,"index":45},"end":{"line":3,"column":27,"index":50}} + } + ] + } + ], + "kind": "await using", + "innerComments": [ + { + "type": "CommentBlock", + "value": "1", + "start":35,"end":40,"loc":{"start":{"line":3,"column":12,"index":35},"end":{"line":3,"column":17,"index":40}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "0", + "start":25,"end":30,"loc":{"start":{"line":3,"column":2,"index":25},"end":{"line":3,"column":7,"index":30}} + } + ] + } + ], + "directives": [] + }, + { + "type": "BlockStatement", + "start":74,"end":157,"loc":{"start":{"line":5,"column":0,"index":74},"end":{"line":7,"column":1,"index":157}}, + "body": [ + { + "type": "ForStatement", + "start":83,"end":155,"loc":{"start":{"line":6,"column":7,"index":83},"end":{"line":6,"column":79,"index":155}}, + "init": { + "type": "VariableDeclaration", + "start":97,"end":130,"loc":{"start":{"line":6,"column":21,"index":97},"end":{"line":6,"column":54,"index":130}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":117,"end":130,"loc":{"start":{"line":6,"column":41,"index":117},"end":{"line":6,"column":54,"index":130}}, + "id": { + "type": "Identifier", + "start":117,"end":118,"loc":{"start":{"line":6,"column":41,"index":117},"end":{"line":6,"column":42,"index":118},"identifierName":"b"}, + "name": "b", + "trailingComments": [ + { + "type": "CommentBlock", + "value": "5", + "start":118,"end":123,"loc":{"start":{"line":6,"column":42,"index":118},"end":{"line":6,"column":47,"index":123}} + } + ] + }, + "init": { + "type": "Identifier", + "start":129,"end":130,"loc":{"start":{"line":6,"column":53,"index":129},"end":{"line":6,"column":54,"index":130},"identifierName":"x"}, + "name": "x", + "leadingComments": [ + { + "type": "CommentBlock", + "value": "6", + "start":124,"end":129,"loc":{"start":{"line":6,"column":48,"index":124},"end":{"line":6,"column":53,"index":129}} + } + ] + }, + "leadingComments": [ + { + "type": "CommentBlock", + "value": "4", + "start":112,"end":117,"loc":{"start":{"line":6,"column":36,"index":112},"end":{"line":6,"column":41,"index":117}} + } + ] + } + ], + "kind": "await using", + "innerComments": [ + { + "type": "CommentBlock", + "value": "3", + "start":102,"end":107,"loc":{"start":{"line":6,"column":26,"index":102},"end":{"line":6,"column":31,"index":107}} + } + ], + "trailingComments": [ + { + "type": "CommentBlock", + "value": "7", + "start":130,"end":135,"loc":{"start":{"line":6,"column":54,"index":130},"end":{"line":6,"column":59,"index":135}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "2", + "start":92,"end":97,"loc":{"start":{"line":6,"column":16,"index":92},"end":{"line":6,"column":21,"index":97}} + } + ] + }, + "test": null, + "update": null, + "body": { + "type": "EmptyStatement", + "start":154,"end":155,"loc":{"start":{"line":6,"column":78,"index":154},"end":{"line":6,"column":79,"index":155}}, + "leadingComments": [ + { + "type": "CommentBlock", + "value": "10", + "start":148,"end":154,"loc":{"start":{"line":6,"column":72,"index":148},"end":{"line":6,"column":78,"index":154}} + } + ] + }, + "innerComments": [ + { + "type": "CommentBlock", + "value": "1", + "start":86,"end":91,"loc":{"start":{"line":6,"column":10,"index":86},"end":{"line":6,"column":15,"index":91}} + }, + { + "type": "CommentBlock", + "value": "8", + "start":136,"end":141,"loc":{"start":{"line":6,"column":60,"index":136},"end":{"line":6,"column":65,"index":141}} + }, + { + "type": "CommentBlock", + "value": "9", + "start":142,"end":147,"loc":{"start":{"line":6,"column":66,"index":142},"end":{"line":6,"column":71,"index":147}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "0", + "start":78,"end":83,"loc":{"start":{"line":6,"column":2,"index":78},"end":{"line":6,"column":7,"index":83}} + } + ] + } + ], + "directives": [] + }, + { + "type": "BlockStatement", + "start":158,"end":229,"loc":{"start":{"line":8,"column":0,"index":158},"end":{"line":10,"column":1,"index":229}}, + "body": [ + { + "type": "ForOfStatement", + "start":167,"end":227,"loc":{"start":{"line":9,"column":7,"index":167},"end":{"line":9,"column":67,"index":227}}, + "await": false, + "left": { + "type": "VariableDeclaration", + "start":181,"end":202,"loc":{"start":{"line":9,"column":21,"index":181},"end":{"line":9,"column":42,"index":202}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":201,"end":202,"loc":{"start":{"line":9,"column":41,"index":201},"end":{"line":9,"column":42,"index":202}}, + "id": { + "type": "Identifier", + "start":201,"end":202,"loc":{"start":{"line":9,"column":41,"index":201},"end":{"line":9,"column":42,"index":202},"identifierName":"b"}, + "name": "b" + }, + "init": null, + "leadingComments": [ + { + "type": "CommentBlock", + "value": "4", + "start":196,"end":201,"loc":{"start":{"line":9,"column":36,"index":196},"end":{"line":9,"column":41,"index":201}} + } + ] + } + ], + "kind": "await using", + "innerComments": [ + { + "type": "CommentBlock", + "value": "3", + "start":186,"end":191,"loc":{"start":{"line":9,"column":26,"index":186},"end":{"line":9,"column":31,"index":191}} + } + ], + "trailingComments": [ + { + "type": "CommentBlock", + "value": "5", + "start":202,"end":207,"loc":{"start":{"line":9,"column":42,"index":202},"end":{"line":9,"column":47,"index":207}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "2", + "start":176,"end":181,"loc":{"start":{"line":9,"column":16,"index":176},"end":{"line":9,"column":21,"index":181}} + } + ] + }, + "right": { + "type": "Identifier", + "start":214,"end":215,"loc":{"start":{"line":9,"column":54,"index":214},"end":{"line":9,"column":55,"index":215},"identifierName":"x"}, + "name": "x", + "trailingComments": [ + { + "type": "CommentBlock", + "value": "7", + "start":215,"end":220,"loc":{"start":{"line":9,"column":55,"index":215},"end":{"line":9,"column":60,"index":220}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "6", + "start":209,"end":214,"loc":{"start":{"line":9,"column":49,"index":209},"end":{"line":9,"column":54,"index":214}} + } + ] + }, + "body": { + "type": "EmptyStatement", + "start":226,"end":227,"loc":{"start":{"line":9,"column":66,"index":226},"end":{"line":9,"column":67,"index":227}}, + "leadingComments": [ + { + "type": "CommentBlock", + "value": "8", + "start":221,"end":226,"loc":{"start":{"line":9,"column":61,"index":221},"end":{"line":9,"column":66,"index":226}} + } + ] + }, + "innerComments": [ + { + "type": "CommentBlock", + "value": "1", + "start":170,"end":175,"loc":{"start":{"line":9,"column":10,"index":170},"end":{"line":9,"column":15,"index":175}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "0", + "start":162,"end":167,"loc":{"start":{"line":9,"column":2,"index":162},"end":{"line":9,"column":7,"index":167}} + } + ] + } + ], + "directives": [] + }, + { + "type": "BlockStatement", + "start":230,"end":311,"loc":{"start":{"line":11,"column":0,"index":230},"end":{"line":13,"column":1,"index":311}}, + "body": [ + { + "type": "ForOfStatement", + "start":239,"end":309,"loc":{"start":{"line":12,"column":7,"index":239},"end":{"line":12,"column":77,"index":309}}, + "await": true, + "left": { + "type": "VariableDeclaration", + "start":263,"end":284,"loc":{"start":{"line":12,"column":31,"index":263},"end":{"line":12,"column":52,"index":284}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":283,"end":284,"loc":{"start":{"line":12,"column":51,"index":283},"end":{"line":12,"column":52,"index":284}}, + "id": { + "type": "Identifier", + "start":283,"end":284,"loc":{"start":{"line":12,"column":51,"index":283},"end":{"line":12,"column":52,"index":284},"identifierName":"b"}, + "name": "b" + }, + "init": null, + "leadingComments": [ + { + "type": "CommentBlock", + "value": "5", + "start":278,"end":283,"loc":{"start":{"line":12,"column":46,"index":278},"end":{"line":12,"column":51,"index":283}} + } + ] + } + ], + "kind": "await using", + "innerComments": [ + { + "type": "CommentBlock", + "value": "4", + "start":268,"end":273,"loc":{"start":{"line":12,"column":36,"index":268},"end":{"line":12,"column":41,"index":273}} + } + ], + "trailingComments": [ + { + "type": "CommentBlock", + "value": "6", + "start":284,"end":289,"loc":{"start":{"line":12,"column":52,"index":284},"end":{"line":12,"column":57,"index":289}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "3", + "start":258,"end":263,"loc":{"start":{"line":12,"column":26,"index":258},"end":{"line":12,"column":31,"index":263}} + } + ] + }, + "right": { + "type": "Identifier", + "start":296,"end":297,"loc":{"start":{"line":12,"column":64,"index":296},"end":{"line":12,"column":65,"index":297},"identifierName":"x"}, + "name": "x", + "trailingComments": [ + { + "type": "CommentBlock", + "value": "8", + "start":297,"end":302,"loc":{"start":{"line":12,"column":65,"index":297},"end":{"line":12,"column":70,"index":302}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "7", + "start":291,"end":296,"loc":{"start":{"line":12,"column":59,"index":291},"end":{"line":12,"column":64,"index":296}} + } + ] + }, + "body": { + "type": "EmptyStatement", + "start":308,"end":309,"loc":{"start":{"line":12,"column":76,"index":308},"end":{"line":12,"column":77,"index":309}}, + "leadingComments": [ + { + "type": "CommentBlock", + "value": "9", + "start":303,"end":308,"loc":{"start":{"line":12,"column":71,"index":303},"end":{"line":12,"column":76,"index":308}} + } + ] + }, + "innerComments": [ + { + "type": "CommentBlock", + "value": "1", + "start":242,"end":247,"loc":{"start":{"line":12,"column":10,"index":242},"end":{"line":12,"column":15,"index":247}} + }, + { + "type": "CommentBlock", + "value": "2", + "start":252,"end":257,"loc":{"start":{"line":12,"column":20,"index":252},"end":{"line":12,"column":25,"index":257}} + } + ], + "leadingComments": [ + { + "type": "CommentBlock", + "value": "0", + "start":234,"end":239,"loc":{"start":{"line":12,"column":2,"index":234},"end":{"line":12,"column":7,"index":239}} + } + ] + } + ], + "directives": [] + } + ], + "directives": [] + } + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentBlock", + "value": "0", + "start":25,"end":30,"loc":{"start":{"line":3,"column":2,"index":25},"end":{"line":3,"column":7,"index":30}} + }, + { + "type": "CommentBlock", + "value": "1", + "start":35,"end":40,"loc":{"start":{"line":3,"column":12,"index":35},"end":{"line":3,"column":17,"index":40}} + }, + { + "type": "CommentBlock", + "value": "2", + "start":45,"end":50,"loc":{"start":{"line":3,"column":22,"index":45},"end":{"line":3,"column":27,"index":50}} + }, + { + "type": "CommentBlock", + "value": "3", + "start":51,"end":56,"loc":{"start":{"line":3,"column":28,"index":51},"end":{"line":3,"column":33,"index":56}} + }, + { + "type": "CommentBlock", + "value": "4", + "start":57,"end":62,"loc":{"start":{"line":3,"column":34,"index":57},"end":{"line":3,"column":39,"index":62}} + }, + { + "type": "CommentBlock", + "value": "5", + "start":65,"end":70,"loc":{"start":{"line":3,"column":42,"index":65},"end":{"line":3,"column":47,"index":70}} + }, + { + "type": "CommentBlock", + "value": "0", + "start":78,"end":83,"loc":{"start":{"line":6,"column":2,"index":78},"end":{"line":6,"column":7,"index":83}} + }, + { + "type": "CommentBlock", + "value": "1", + "start":86,"end":91,"loc":{"start":{"line":6,"column":10,"index":86},"end":{"line":6,"column":15,"index":91}} + }, + { + "type": "CommentBlock", + "value": "2", + "start":92,"end":97,"loc":{"start":{"line":6,"column":16,"index":92},"end":{"line":6,"column":21,"index":97}} + }, + { + "type": "CommentBlock", + "value": "3", + "start":102,"end":107,"loc":{"start":{"line":6,"column":26,"index":102},"end":{"line":6,"column":31,"index":107}} + }, + { + "type": "CommentBlock", + "value": "4", + "start":112,"end":117,"loc":{"start":{"line":6,"column":36,"index":112},"end":{"line":6,"column":41,"index":117}} + }, + { + "type": "CommentBlock", + "value": "5", + "start":118,"end":123,"loc":{"start":{"line":6,"column":42,"index":118},"end":{"line":6,"column":47,"index":123}} + }, + { + "type": "CommentBlock", + "value": "6", + "start":124,"end":129,"loc":{"start":{"line":6,"column":48,"index":124},"end":{"line":6,"column":53,"index":129}} + }, + { + "type": "CommentBlock", + "value": "7", + "start":130,"end":135,"loc":{"start":{"line":6,"column":54,"index":130},"end":{"line":6,"column":59,"index":135}} + }, + { + "type": "CommentBlock", + "value": "8", + "start":136,"end":141,"loc":{"start":{"line":6,"column":60,"index":136},"end":{"line":6,"column":65,"index":141}} + }, + { + "type": "CommentBlock", + "value": "9", + "start":142,"end":147,"loc":{"start":{"line":6,"column":66,"index":142},"end":{"line":6,"column":71,"index":147}} + }, + { + "type": "CommentBlock", + "value": "10", + "start":148,"end":154,"loc":{"start":{"line":6,"column":72,"index":148},"end":{"line":6,"column":78,"index":154}} + }, + { + "type": "CommentBlock", + "value": "0", + "start":162,"end":167,"loc":{"start":{"line":9,"column":2,"index":162},"end":{"line":9,"column":7,"index":167}} + }, + { + "type": "CommentBlock", + "value": "1", + "start":170,"end":175,"loc":{"start":{"line":9,"column":10,"index":170},"end":{"line":9,"column":15,"index":175}} + }, + { + "type": "CommentBlock", + "value": "2", + "start":176,"end":181,"loc":{"start":{"line":9,"column":16,"index":176},"end":{"line":9,"column":21,"index":181}} + }, + { + "type": "CommentBlock", + "value": "3", + "start":186,"end":191,"loc":{"start":{"line":9,"column":26,"index":186},"end":{"line":9,"column":31,"index":191}} + }, + { + "type": "CommentBlock", + "value": "4", + "start":196,"end":201,"loc":{"start":{"line":9,"column":36,"index":196},"end":{"line":9,"column":41,"index":201}} + }, + { + "type": "CommentBlock", + "value": "5", + "start":202,"end":207,"loc":{"start":{"line":9,"column":42,"index":202},"end":{"line":9,"column":47,"index":207}} + }, + { + "type": "CommentBlock", + "value": "6", + "start":209,"end":214,"loc":{"start":{"line":9,"column":49,"index":209},"end":{"line":9,"column":54,"index":214}} + }, + { + "type": "CommentBlock", + "value": "7", + "start":215,"end":220,"loc":{"start":{"line":9,"column":55,"index":215},"end":{"line":9,"column":60,"index":220}} + }, + { + "type": "CommentBlock", + "value": "8", + "start":221,"end":226,"loc":{"start":{"line":9,"column":61,"index":221},"end":{"line":9,"column":66,"index":226}} + }, + { + "type": "CommentBlock", + "value": "0", + "start":234,"end":239,"loc":{"start":{"line":12,"column":2,"index":234},"end":{"line":12,"column":7,"index":239}} + }, + { + "type": "CommentBlock", + "value": "1", + "start":242,"end":247,"loc":{"start":{"line":12,"column":10,"index":242},"end":{"line":12,"column":15,"index":247}} + }, + { + "type": "CommentBlock", + "value": "2", + "start":252,"end":257,"loc":{"start":{"line":12,"column":20,"index":252},"end":{"line":12,"column":25,"index":257}} + }, + { + "type": "CommentBlock", + "value": "3", + "start":258,"end":263,"loc":{"start":{"line":12,"column":26,"index":258},"end":{"line":12,"column":31,"index":263}} + }, + { + "type": "CommentBlock", + "value": "4", + "start":268,"end":273,"loc":{"start":{"line":12,"column":36,"index":268},"end":{"line":12,"column":41,"index":273}} + }, + { + "type": "CommentBlock", + "value": "5", + "start":278,"end":283,"loc":{"start":{"line":12,"column":46,"index":278},"end":{"line":12,"column":51,"index":283}} + }, + { + "type": "CommentBlock", + "value": "6", + "start":284,"end":289,"loc":{"start":{"line":12,"column":52,"index":284},"end":{"line":12,"column":57,"index":289}} + }, + { + "type": "CommentBlock", + "value": "7", + "start":291,"end":296,"loc":{"start":{"line":12,"column":59,"index":291},"end":{"line":12,"column":64,"index":296}} + }, + { + "type": "CommentBlock", + "value": "8", + "start":297,"end":302,"loc":{"start":{"line":12,"column":65,"index":297},"end":{"line":12,"column":70,"index":302}} + }, + { + "type": "CommentBlock", + "value": "9", + "start":303,"end":308,"loc":{"start":{"line":12,"column":71,"index":303},"end":{"line":12,"column":76,"index":308}} + } + ] +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-lhs-await-as-identifier/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-lhs-await-as-identifier/input.js new file mode 100644 index 000000000000..87d8cd132331 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-lhs-await-as-identifier/input.js @@ -0,0 +1,3 @@ +{ + for (await of [of]); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-lhs-await-as-identifier/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-lhs-await-as-identifier/output.json new file mode 100644 index 000000000000..7a2e8673faee --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-lhs-await-as-identifier/output.json @@ -0,0 +1,45 @@ +{ + "type": "File", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":26}}, + "program": { + "type": "Program", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":26}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "BlockStatement", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":26}}, + "body": [ + { + "type": "ForOfStatement", + "start":4,"end":24,"loc":{"start":{"line":2,"column":2,"index":4},"end":{"line":2,"column":22,"index":24}}, + "await": false, + "left": { + "type": "Identifier", + "start":9,"end":14,"loc":{"start":{"line":2,"column":7,"index":9},"end":{"line":2,"column":12,"index":14},"identifierName":"await"}, + "name": "await" + }, + "right": { + "type": "ArrayExpression", + "start":18,"end":22,"loc":{"start":{"line":2,"column":16,"index":18},"end":{"line":2,"column":20,"index":22}}, + "elements": [ + { + "type": "Identifier", + "start":19,"end":21,"loc":{"start":{"line":2,"column":17,"index":19},"end":{"line":2,"column":19,"index":21},"identifierName":"of"}, + "name": "of" + } + ] + }, + "body": { + "type": "EmptyStatement", + "start":23,"end":24,"loc":{"start":{"line":2,"column":21,"index":23},"end":{"line":2,"column":22,"index":24}} + } + } + ], + "directives": [] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-binding-of-of/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-binding-of-of/input.js new file mode 100644 index 000000000000..4efb8f85a6fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-binding-of-of/input.js @@ -0,0 +1,4 @@ +async function f() { + for (await using of of of); + for await (await using of of of); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-binding-of-of/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-binding-of-of/output.json new file mode 100644 index 000000000000..affdb28699e7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-binding-of-of/output.json @@ -0,0 +1,94 @@ +{ + "type": "File", + "start":0,"end":88,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":88}}, + "program": { + "type": "Program", + "start":0,"end":88,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":88}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":88,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":88}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":88,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":4,"column":1,"index":88}}, + "body": [ + { + "type": "ForOfStatement", + "start":23,"end":50,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":29,"index":50}}, + "await": false, + "left": { + "type": "VariableDeclaration", + "start":28,"end":42,"loc":{"start":{"line":2,"column":7,"index":28},"end":{"line":2,"column":21,"index":42}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":40,"end":42,"loc":{"start":{"line":2,"column":19,"index":40},"end":{"line":2,"column":21,"index":42}}, + "id": { + "type": "Identifier", + "start":40,"end":42,"loc":{"start":{"line":2,"column":19,"index":40},"end":{"line":2,"column":21,"index":42},"identifierName":"of"}, + "name": "of" + }, + "init": null + } + ], + "kind": "await using" + }, + "right": { + "type": "Identifier", + "start":46,"end":48,"loc":{"start":{"line":2,"column":25,"index":46},"end":{"line":2,"column":27,"index":48},"identifierName":"of"}, + "name": "of" + }, + "body": { + "type": "EmptyStatement", + "start":49,"end":50,"loc":{"start":{"line":2,"column":28,"index":49},"end":{"line":2,"column":29,"index":50}} + } + }, + { + "type": "ForOfStatement", + "start":53,"end":86,"loc":{"start":{"line":3,"column":2,"index":53},"end":{"line":3,"column":35,"index":86}}, + "await": true, + "left": { + "type": "VariableDeclaration", + "start":64,"end":78,"loc":{"start":{"line":3,"column":13,"index":64},"end":{"line":3,"column":27,"index":78}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":76,"end":78,"loc":{"start":{"line":3,"column":25,"index":76},"end":{"line":3,"column":27,"index":78}}, + "id": { + "type": "Identifier", + "start":76,"end":78,"loc":{"start":{"line":3,"column":25,"index":76},"end":{"line":3,"column":27,"index":78},"identifierName":"of"}, + "name": "of" + }, + "init": null + } + ], + "kind": "await using" + }, + "right": { + "type": "Identifier", + "start":82,"end":84,"loc":{"start":{"line":3,"column":31,"index":82},"end":{"line":3,"column":33,"index":84},"identifierName":"of"}, + "name": "of" + }, + "body": { + "type": "EmptyStatement", + "start":85,"end":86,"loc":{"start":{"line":3,"column":34,"index":85},"end":{"line":3,"column":35,"index":86}} + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-declaration/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-declaration/input.js new file mode 100644 index 000000000000..a13b51758dcd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-declaration/input.js @@ -0,0 +1,3 @@ +async function f() { + for (await using basic = reader();;); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-declaration/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-declaration/output.json new file mode 100644 index 000000000000..4eec3e4ff619 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-declaration/output.json @@ -0,0 +1,68 @@ +{ + "type": "File", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":62}}, + "program": { + "type": "Program", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":62}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":62}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":62,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":62}}, + "body": [ + { + "type": "ForStatement", + "start":23,"end":60,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":39,"index":60}}, + "init": { + "type": "VariableDeclaration", + "start":28,"end":56,"loc":{"start":{"line":2,"column":7,"index":28},"end":{"line":2,"column":35,"index":56}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":40,"end":56,"loc":{"start":{"line":2,"column":19,"index":40},"end":{"line":2,"column":35,"index":56}}, + "id": { + "type": "Identifier", + "start":40,"end":45,"loc":{"start":{"line":2,"column":19,"index":40},"end":{"line":2,"column":24,"index":45},"identifierName":"basic"}, + "name": "basic" + }, + "init": { + "type": "CallExpression", + "start":48,"end":56,"loc":{"start":{"line":2,"column":27,"index":48},"end":{"line":2,"column":35,"index":56}}, + "callee": { + "type": "Identifier", + "start":48,"end":54,"loc":{"start":{"line":2,"column":27,"index":48},"end":{"line":2,"column":33,"index":54},"identifierName":"reader"}, + "name": "reader" + }, + "arguments": [] + } + } + ], + "kind": "await using" + }, + "test": null, + "update": null, + "body": { + "type": "EmptyStatement", + "start":59,"end":60,"loc":{"start":{"line":2,"column":38,"index":59},"end":{"line":2,"column":39,"index":60}} + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/input.js new file mode 100644 index 000000000000..fffa04d7c7af --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/input.js @@ -0,0 +1,3 @@ +const m = module { + await using foo = bar(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/options.json new file mode 100644 index 000000000000..70e7070ed475 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "script", + "plugins": ["asyncExplicitResourceManagement", "moduleBlocks"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/output.json new file mode 100644 index 000000000000..2c7d51dafc9f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/output.json @@ -0,0 +1,68 @@ +{ + "type": "File", + "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":47}}, + "program": { + "type": "Program", + "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":47}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":47}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":47,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":3,"column":1,"index":47}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"m"}, + "name": "m" + }, + "init": { + "type": "ModuleExpression", + "start":10,"end":47,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":3,"column":1,"index":47}}, + "body": { + "type": "Program", + "start":18,"end":46,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":3,"column":0,"index":46}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":21,"end":45,"loc":{"start":{"line":2,"column":2,"index":21},"end":{"line":2,"column":26,"index":45}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":33,"end":44,"loc":{"start":{"line":2,"column":14,"index":33},"end":{"line":2,"column":25,"index":44}}, + "id": { + "type": "Identifier", + "start":33,"end":36,"loc":{"start":{"line":2,"column":14,"index":33},"end":{"line":2,"column":17,"index":36},"identifierName":"foo"}, + "name": "foo" + }, + "init": { + "type": "CallExpression", + "start":39,"end":44,"loc":{"start":{"line":2,"column":20,"index":39},"end":{"line":2,"column":25,"index":44}}, + "callee": { + "type": "Identifier", + "start":39,"end":42,"loc":{"start":{"line":2,"column":20,"index":39},"end":{"line":2,"column":23,"index":42},"identifierName":"bar"}, + "name": "bar" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-basic/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-basic/input.js new file mode 100644 index 000000000000..321993e916c9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-basic/input.js @@ -0,0 +1,3 @@ +async function f() { + await using basic = getReader(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-basic/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-basic/output.json new file mode 100644 index 000000000000..5b6536119726 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-basic/output.json @@ -0,0 +1,58 @@ +{ + "type": "File", + "start":0,"end":57,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":57}}, + "program": { + "type": "Program", + "start":0,"end":57,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":57}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":57,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":57}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":57,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":57}}, + "body": [ + { + "type": "VariableDeclaration", + "start":23,"end":55,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":34,"index":55}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":35,"end":54,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":33,"index":54}}, + "id": { + "type": "Identifier", + "start":35,"end":40,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":19,"index":40},"identifierName":"basic"}, + "name": "basic" + }, + "init": { + "type": "CallExpression", + "start":43,"end":54,"loc":{"start":{"line":2,"column":22,"index":43},"end":{"line":2,"column":33,"index":54}}, + "callee": { + "type": "Identifier", + "start":43,"end":52,"loc":{"start":{"line":2,"column":22,"index":43},"end":{"line":2,"column":31,"index":52},"identifierName":"getReader"}, + "name": "getReader" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-escaped/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-escaped/input.js new file mode 100644 index 000000000000..76af5903fa74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-escaped/input.js @@ -0,0 +1,3 @@ +async function f() { + await using \u0061b = c; +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-escaped/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-escaped/output.json new file mode 100644 index 000000000000..aa656929afc9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-escaped/output.json @@ -0,0 +1,53 @@ +{ + "type": "File", + "start":0,"end":49,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":49}}, + "program": { + "type": "Program", + "start":0,"end":49,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":49}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":49,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":49}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":49,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":49}}, + "body": [ + { + "type": "VariableDeclaration", + "start":23,"end":47,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":26,"index":47}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":35,"end":46,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":25,"index":46}}, + "id": { + "type": "Identifier", + "start":35,"end":42,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":21,"index":42},"identifierName":"ab"}, + "name": "ab" + }, + "init": { + "type": "Identifier", + "start":45,"end":46,"loc":{"start":{"line":2,"column":24,"index":45},"end":{"line":2,"column":25,"index":46},"identifierName":"c"}, + "name": "c" + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-non-bmp/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-non-bmp/input.js new file mode 100644 index 000000000000..cbf4ce251996 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-non-bmp/input.js @@ -0,0 +1,3 @@ +async function f() { + await using 𠮷 = foo(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-non-bmp/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-non-bmp/output.json new file mode 100644 index 000000000000..b2c1b8437902 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-non-bmp/output.json @@ -0,0 +1,58 @@ +{ + "type": "File", + "start":0,"end":48,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":48}}, + "program": { + "type": "Program", + "start":0,"end":48,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":48}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":48,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":48}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":48,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":48}}, + "body": [ + { + "type": "VariableDeclaration", + "start":23,"end":46,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":25,"index":46}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":35,"end":45,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":24,"index":45}}, + "id": { + "type": "Identifier", + "start":35,"end":37,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":16,"index":37},"identifierName":"𠮷"}, + "name": "𠮷" + }, + "init": { + "type": "CallExpression", + "start":40,"end":45,"loc":{"start":{"line":2,"column":19,"index":40},"end":{"line":2,"column":24,"index":45}}, + "callee": { + "type": "Identifier", + "start":40,"end":43,"loc":{"start":{"line":2,"column":19,"index":40},"end":{"line":2,"column":22,"index":43},"identifierName":"foo"}, + "name": "foo" + }, + "arguments": [] + } + } + ], + "kind": "await using" + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-using/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-using/input.js new file mode 100644 index 000000000000..fd4e32547db8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-using/input.js @@ -0,0 +1,4 @@ +async function f() { + await using using = of; + for (await using using of of); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-using/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-using/output.json new file mode 100644 index 000000000000..b25c61d9e0eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-using-binding-using/output.json @@ -0,0 +1,84 @@ +{ + "type": "File", + "start":0,"end":81,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":81}}, + "program": { + "type": "Program", + "start":0,"end":81,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":81}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":81,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":81}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":81,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":4,"column":1,"index":81}}, + "body": [ + { + "type": "VariableDeclaration", + "start":23,"end":46,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":25,"index":46}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":35,"end":45,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":24,"index":45}}, + "id": { + "type": "Identifier", + "start":35,"end":40,"loc":{"start":{"line":2,"column":14,"index":35},"end":{"line":2,"column":19,"index":40},"identifierName":"using"}, + "name": "using" + }, + "init": { + "type": "Identifier", + "start":43,"end":45,"loc":{"start":{"line":2,"column":22,"index":43},"end":{"line":2,"column":24,"index":45},"identifierName":"of"}, + "name": "of" + } + } + ], + "kind": "await using" + }, + { + "type": "ForOfStatement", + "start":49,"end":79,"loc":{"start":{"line":3,"column":2,"index":49},"end":{"line":3,"column":32,"index":79}}, + "await": false, + "left": { + "type": "VariableDeclaration", + "start":54,"end":71,"loc":{"start":{"line":3,"column":7,"index":54},"end":{"line":3,"column":24,"index":71}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":66,"end":71,"loc":{"start":{"line":3,"column":19,"index":66},"end":{"line":3,"column":24,"index":71}}, + "id": { + "type": "Identifier", + "start":66,"end":71,"loc":{"start":{"line":3,"column":19,"index":66},"end":{"line":3,"column":24,"index":71},"identifierName":"using"}, + "name": "using" + }, + "init": null + } + ], + "kind": "await using" + }, + "right": { + "type": "Identifier", + "start":75,"end":77,"loc":{"start":{"line":3,"column":28,"index":75},"end":{"line":3,"column":30,"index":77},"identifierName":"of"}, + "name": "of" + }, + "body": { + "type": "EmptyStatement", + "start":78,"end":79,"loc":{"start":{"line":3,"column":31,"index":78},"end":{"line":3,"column":32,"index":79}} + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} From d948c9aa67218f2a85deb23c1698172433a2de8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 12:31:10 -0400 Subject: [PATCH 05/15] generate await using declaration --- packages/babel-generator/src/generators/statements.ts | 2 +- .../test/fixtures/await-using-declarations/basic/input.js | 3 +++ .../fixtures/await-using-declarations/basic/output.js | 3 +++ .../await-using-declarations/for-using-init/input.js | 3 +++ .../await-using-declarations/for-using-init/output.js | 3 +++ .../await-using-declarations/for-using-of/input.js | 8 ++++++++ .../await-using-declarations/for-using-of/output.js | 8 ++++++++ .../test/fixtures/await-using-declarations/options.json | 3 +++ 8 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 packages/babel-generator/test/fixtures/await-using-declarations/basic/input.js create mode 100644 packages/babel-generator/test/fixtures/await-using-declarations/basic/output.js create mode 100644 packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/input.js create mode 100644 packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/output.js create mode 100644 packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/input.js create mode 100644 packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/output.js create mode 100644 packages/babel-generator/test/fixtures/await-using-declarations/options.json diff --git a/packages/babel-generator/src/generators/statements.ts b/packages/babel-generator/src/generators/statements.ts index 6a579923258f..e6b7a96a011a 100644 --- a/packages/babel-generator/src/generators/statements.ts +++ b/packages/babel-generator/src/generators/statements.ts @@ -261,7 +261,7 @@ export function VariableDeclaration( } const { kind } = node; - this.word(kind, kind === "using"); + this.word(kind, kind === "using" || kind === "await using"); this.space(); let hasInits = false; diff --git a/packages/babel-generator/test/fixtures/await-using-declarations/basic/input.js b/packages/babel-generator/test/fixtures/await-using-declarations/basic/input.js new file mode 100644 index 000000000000..962b5206590c --- /dev/null +++ b/packages/babel-generator/test/fixtures/await-using-declarations/basic/input.js @@ -0,0 +1,3 @@ +async function f() { + /*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/; +} diff --git a/packages/babel-generator/test/fixtures/await-using-declarations/basic/output.js b/packages/babel-generator/test/fixtures/await-using-declarations/basic/output.js new file mode 100644 index 000000000000..2786f6c26c34 --- /dev/null +++ b/packages/babel-generator/test/fixtures/await-using-declarations/basic/output.js @@ -0,0 +1,3 @@ +async function f() { + /*0*/await using /*2*/b /*3*/ = /*4*/f() /*5*/; /*1*/ +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/input.js b/packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/input.js new file mode 100644 index 000000000000..299468240f2f --- /dev/null +++ b/packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/input.js @@ -0,0 +1,3 @@ +async function f() { + /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; +} diff --git a/packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/output.js b/packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/output.js new file mode 100644 index 000000000000..726cc7545464 --- /dev/null +++ b/packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/output.js @@ -0,0 +1,3 @@ +async function f() { + /*0*/for /*1*/ /*8*/ /*9*/ ( /*2*/await using /*4*/b /*5*/ = /*6*/x /*3*/ /*7*/;;) /*10*/; +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/input.js b/packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/input.js new file mode 100644 index 000000000000..06759207603b --- /dev/null +++ b/packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/input.js @@ -0,0 +1,8 @@ +async function f() { + { + /*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; + } + { + /*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; + } +} diff --git a/packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/output.js b/packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/output.js new file mode 100644 index 000000000000..573a4a22ec23 --- /dev/null +++ b/packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/output.js @@ -0,0 +1,8 @@ +async function f() { + { + /*0*/for /*1*/ ( /*2*/await using /*4*/b /*3*/ /*5*/ of /*6*/x /*7*/) /*8*/; + } + { + /*0*/for /*1*/ /*2*/ await ( /*3*/await using /*5*/b /*4*/ /*6*/ of /*7*/x /*8*/) /*9*/; + } +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/await-using-declarations/options.json b/packages/babel-generator/test/fixtures/await-using-declarations/options.json new file mode 100644 index 000000000000..48bceee79c05 --- /dev/null +++ b/packages/babel-generator/test/fixtures/await-using-declarations/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["asyncExplicitResourceManagement"] +} From 377b63cca6b742a45db8504e3760cb52a30f3035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 12:40:00 -0400 Subject: [PATCH 06/15] register await using as const declaration --- packages/babel-traverse/src/scope/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/babel-traverse/src/scope/index.ts b/packages/babel-traverse/src/scope/index.ts index 885e86b754ad..2fe2bb83405f 100644 --- a/packages/babel-traverse/src/scope/index.ts +++ b/packages/babel-traverse/src/scope/index.ts @@ -746,7 +746,10 @@ export default class Scope { const declarations = path.get("declarations"); const { kind } = path.node; for (const declar of declarations) { - this.registerBinding(kind === "using" ? "const" : kind, declar); + this.registerBinding( + kind === "using" || kind === "await using" ? "const" : kind, + declar, + ); } } else if (path.isClassDeclaration()) { if (path.node.declare) return; From 678906245835085fd06533e96716b2dcae51d314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 12:40:20 -0400 Subject: [PATCH 07/15] add syntax plugin --- .../README.md | 19 +++++++ .../package.json | 50 +++++++++++++++++++ .../src/index.ts | 13 +++++ tsconfig.json | 4 ++ yarn.lock | 11 ++++ 5 files changed, 97 insertions(+) create mode 100644 packages/babel-plugin-syntax-async-explicit-resource-management/README.md create mode 100644 packages/babel-plugin-syntax-async-explicit-resource-management/package.json create mode 100644 packages/babel-plugin-syntax-async-explicit-resource-management/src/index.ts diff --git a/packages/babel-plugin-syntax-async-explicit-resource-management/README.md b/packages/babel-plugin-syntax-async-explicit-resource-management/README.md new file mode 100644 index 000000000000..db45b0044848 --- /dev/null +++ b/packages/babel-plugin-syntax-async-explicit-resource-management/README.md @@ -0,0 +1,19 @@ +# @babel/plugin-syntax-async-explicit-resource-management + +> Allow parsing of the using declarations + +See our website [@babel/plugin-syntax-async-explicit-resource-management](https://babeljs.io/docs/en/babel-plugin-syntax-async-explicit-resource-management) for more information. + +## Install + +Using npm: + +```sh +npm install --save-dev @babel/plugin-syntax-async-explicit-resource-management +``` + +or using yarn: + +```sh +yarn add @babel/plugin-syntax-async-explicit-resource-management --dev +``` diff --git a/packages/babel-plugin-syntax-async-explicit-resource-management/package.json b/packages/babel-plugin-syntax-async-explicit-resource-management/package.json new file mode 100644 index 000000000000..b18917c00342 --- /dev/null +++ b/packages/babel-plugin-syntax-async-explicit-resource-management/package.json @@ -0,0 +1,50 @@ +{ + "name": "@babel/plugin-syntax-async-explicit-resource-management", + "version": "7.20.0", + "description": "Allow parsing of the await using declarations", + "repository": { + "type": "git", + "url": "https://github.com/babel/babel.git", + "directory": "packages/babel-plugin-syntax-async-explicit-resource-management" + }, + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "main": "./lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "@babel/helper-plugin-utils": "workspace:^" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + }, + "devDependencies": { + "@babel/core": "workspace:^" + }, + "engines": { + "node": ">=6.9.0" + }, + "author": "The Babel Team (https://babel.dev/team)", + "conditions": { + "BABEL_8_BREAKING": [ + null, + { + "exports": null + } + ], + "USE_ESM": [ + { + "type": "module" + }, + null + ] + }, + "exports": { + ".": "./lib/index.js", + "./package.json": "./package.json" + }, + "type": "commonjs" +} diff --git a/packages/babel-plugin-syntax-async-explicit-resource-management/src/index.ts b/packages/babel-plugin-syntax-async-explicit-resource-management/src/index.ts new file mode 100644 index 000000000000..a3d8551311db --- /dev/null +++ b/packages/babel-plugin-syntax-async-explicit-resource-management/src/index.ts @@ -0,0 +1,13 @@ +import { declare } from "@babel/helper-plugin-utils"; + +export default declare(api => { + api.assertVersion(7); + + return { + name: "syntax-async-explicit-resource-management", + + manipulateOptions(opts, parserOpts) { + parserOpts.plugins.push("asyncExplicitResourceManagement"); + }, + }; +}); diff --git a/tsconfig.json b/tsconfig.json index a362623d5daf..64106417631e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -71,6 +71,7 @@ "./packages/babel-plugin-proposal-unicode-property-regex/src/**/*.ts", "./packages/babel-plugin-proposal-unicode-sets-regex/src/**/*.ts", "./packages/babel-plugin-syntax-async-do-expressions/src/**/*.ts", + "./packages/babel-plugin-syntax-async-explicit-resource-management/src/**/*.ts", "./packages/babel-plugin-syntax-decimal/src/**/*.ts", "./packages/babel-plugin-syntax-decorators/src/**/*.ts", "./packages/babel-plugin-syntax-destructuring-private/src/**/*.ts", @@ -379,6 +380,9 @@ "@babel/plugin-syntax-async-do-expressions": [ "./packages/babel-plugin-syntax-async-do-expressions/src" ], + "@babel/plugin-syntax-async-explicit-resource-management": [ + "./packages/babel-plugin-syntax-async-explicit-resource-management/src" + ], "@babel/plugin-syntax-decimal": [ "./packages/babel-plugin-syntax-decimal/src" ], diff --git a/yarn.lock b/yarn.lock index 8246ec05989b..34ddadbaa559 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1832,6 +1832,17 @@ __metadata: languageName: unknown linkType: soft +"@babel/plugin-syntax-async-explicit-resource-management@workspace:packages/babel-plugin-syntax-async-explicit-resource-management": + version: 0.0.0-use.local + resolution: "@babel/plugin-syntax-async-explicit-resource-management@workspace:packages/babel-plugin-syntax-async-explicit-resource-management" + dependencies: + "@babel/core": "workspace:^" + "@babel/helper-plugin-utils": "workspace:^" + peerDependencies: + "@babel/core": ^7.0.0-0 + languageName: unknown + linkType: soft + "@babel/plugin-syntax-async-generators@npm:^7.8.4": version: 7.8.4 resolution: "@babel/plugin-syntax-async-generators@npm:7.8.4" From 1890dc3d3ef584b7b2b033c0c9a8919a2271ebc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 12:42:58 -0400 Subject: [PATCH 08/15] add syntax plugin to standalone --- packages/babel-standalone/package.json | 1 + packages/babel-standalone/scripts/pluginConfig.json | 1 + packages/babel-standalone/src/generated/plugins.ts | 4 ++++ packages/babel-standalone/src/preset-stage-2.ts | 1 + yarn.lock | 3 ++- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/babel-standalone/package.json b/packages/babel-standalone/package.json index 2e9ae54db80a..ed37491fe6cc 100644 --- a/packages/babel-standalone/package.json +++ b/packages/babel-standalone/package.json @@ -39,6 +39,7 @@ "@babel/plugin-proposal-throw-expressions": "workspace:^", "@babel/plugin-proposal-unicode-property-regex": "workspace:^", "@babel/plugin-proposal-unicode-sets-regex": "workspace:^", + "@babel/plugin-syntax-async-explicit-resource-management": "workspace:^", "@babel/plugin-syntax-decimal": "workspace:^", "@babel/plugin-syntax-decorators": "workspace:^", "@babel/plugin-syntax-destructuring-private": "workspace:^", diff --git a/packages/babel-standalone/scripts/pluginConfig.json b/packages/babel-standalone/scripts/pluginConfig.json index 815d03edd31c..16c6e90b783c 100644 --- a/packages/babel-standalone/scripts/pluginConfig.json +++ b/packages/babel-standalone/scripts/pluginConfig.json @@ -20,6 +20,7 @@ ], "externalPlugins": [ "external-helpers", + "syntax-async-explicit-resource-management", "syntax-decimal", "syntax-decorators", "syntax-destructuring-private", diff --git a/packages/babel-standalone/src/generated/plugins.ts b/packages/babel-standalone/src/generated/plugins.ts index 285f8946c40c..7bda0a41d36d 100644 --- a/packages/babel-standalone/src/generated/plugins.ts +++ b/packages/babel-standalone/src/generated/plugins.ts @@ -4,6 +4,7 @@ */ import makeNoopPlugin from "../make-noop-plugin"; import externalHelpers from "@babel/plugin-external-helpers"; +import syntaxAsyncExplicitResourceManagement from "@babel/plugin-syntax-async-explicit-resource-management"; import syntaxDecimal from "@babel/plugin-syntax-decimal"; import syntaxDecorators from "@babel/plugin-syntax-decorators"; import syntaxDestructuringPrivate from "@babel/plugin-syntax-destructuring-private"; @@ -107,6 +108,7 @@ export const syntaxAsyncGenerators = makeNoopPlugin(), syntaxTopLevelAwait = makeNoopPlugin(); export { externalHelpers, + syntaxAsyncExplicitResourceManagement, syntaxDecimal, syntaxDecorators, syntaxDestructuringPrivate, @@ -211,6 +213,8 @@ export const all: { [k: string]: any } = { "syntax-optional-catch-binding": syntaxOptionalCatchBinding, "syntax-top-level-await": syntaxTopLevelAwait, "external-helpers": externalHelpers, + "syntax-async-explicit-resource-management": + syntaxAsyncExplicitResourceManagement, "syntax-decimal": syntaxDecimal, "syntax-decorators": syntaxDecorators, "syntax-destructuring-private": syntaxDestructuringPrivate, diff --git a/packages/babel-standalone/src/preset-stage-2.ts b/packages/babel-standalone/src/preset-stage-2.ts index d1bd3788d1a2..67402651631d 100644 --- a/packages/babel-standalone/src/preset-stage-2.ts +++ b/packages/babel-standalone/src/preset-stage-2.ts @@ -11,6 +11,7 @@ export default (_: any, opts: any = {}) => { return { presets: [[presetStage3, opts]], plugins: [ + babelPlugins.syntaxAsyncExplicitResourceManagement, babelPlugins.proposalDestructuringPrivate, [ babelPlugins.proposalPipelineOperator, diff --git a/yarn.lock b/yarn.lock index 34ddadbaa559..86bc3f33f8e1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1832,7 +1832,7 @@ __metadata: languageName: unknown linkType: soft -"@babel/plugin-syntax-async-explicit-resource-management@workspace:packages/babel-plugin-syntax-async-explicit-resource-management": +"@babel/plugin-syntax-async-explicit-resource-management@workspace:^, @babel/plugin-syntax-async-explicit-resource-management@workspace:packages/babel-plugin-syntax-async-explicit-resource-management": version: 0.0.0-use.local resolution: "@babel/plugin-syntax-async-explicit-resource-management@workspace:packages/babel-plugin-syntax-async-explicit-resource-management" dependencies: @@ -3708,6 +3708,7 @@ __metadata: "@babel/plugin-proposal-throw-expressions": "workspace:^" "@babel/plugin-proposal-unicode-property-regex": "workspace:^" "@babel/plugin-proposal-unicode-sets-regex": "workspace:^" + "@babel/plugin-syntax-async-explicit-resource-management": "workspace:^" "@babel/plugin-syntax-decimal": "workspace:^" "@babel/plugin-syntax-decorators": "workspace:^" "@babel/plugin-syntax-destructuring-private": "workspace:^" From 7c6f9fac938ca295a638c2eaf87079e0c44eec99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 14:41:31 -0400 Subject: [PATCH 09/15] add invalid await using binding pattern cases --- .../invalid-using-array-pattern/input.js | 3 + .../invalid-using-array-pattern/output.json | 73 +++++++++++++++++++ .../invalid-using-object-pattern/input.js | 3 + .../invalid-using-object-pattern/options.json | 3 + 4 files changed, 82 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-array-pattern/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-array-pattern/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-object-pattern/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-object-pattern/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-array-pattern/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-array-pattern/input.js new file mode 100644 index 000000000000..8f6c68a2f80b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-array-pattern/input.js @@ -0,0 +1,3 @@ +async function f() { + await using [ foo ] = f(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-array-pattern/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-array-pattern/output.json new file mode 100644 index 000000000000..9d347b2c68a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-array-pattern/output.json @@ -0,0 +1,73 @@ +{ + "type": "File", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":51}}, + "errors": [ + "SyntaxError: Invalid left-hand side in assignment expression. (2:2)" + ], + "program": { + "type": "Program", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":51}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":51,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":51}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":51,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":51}}, + "body": [ + { + "type": "ExpressionStatement", + "start":23,"end":49,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":28,"index":49}}, + "expression": { + "type": "AssignmentExpression", + "start":23,"end":48,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":27,"index":48}}, + "operator": "=", + "left": { + "type": "AwaitExpression", + "start":23,"end":42,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":21,"index":42}}, + "argument": { + "type": "MemberExpression", + "start":29,"end":42,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":21,"index":42}}, + "object": { + "type": "Identifier", + "start":29,"end":34,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":13,"index":34},"identifierName":"using"}, + "name": "using" + }, + "computed": true, + "property": { + "type": "Identifier", + "start":37,"end":40,"loc":{"start":{"line":2,"column":16,"index":37},"end":{"line":2,"column":19,"index":40},"identifierName":"foo"}, + "name": "foo" + } + } + }, + "right": { + "type": "CallExpression", + "start":45,"end":48,"loc":{"start":{"line":2,"column":24,"index":45},"end":{"line":2,"column":27,"index":48}}, + "callee": { + "type": "Identifier", + "start":45,"end":46,"loc":{"start":{"line":2,"column":24,"index":45},"end":{"line":2,"column":25,"index":46},"identifierName":"f"}, + "name": "f" + }, + "arguments": [] + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-object-pattern/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-object-pattern/input.js new file mode 100644 index 000000000000..3aadf97fbe3f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-object-pattern/input.js @@ -0,0 +1,3 @@ +async function f() { + await using { foo } = f(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-object-pattern/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-object-pattern/options.json new file mode 100644 index 000000000000..c2c8f56374f4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/invalid-using-object-pattern/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:22)" +} From 1f24171825a12be4b37a268b27468a4f9205eb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 19:38:44 -0400 Subject: [PATCH 10/15] update typings --- packages/babel-parser/typings/babel-parser.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/babel-parser/typings/babel-parser.d.ts b/packages/babel-parser/typings/babel-parser.d.ts index d80fff653c30..ee7c05c75311 100644 --- a/packages/babel-parser/typings/babel-parser.d.ts +++ b/packages/babel-parser/typings/babel-parser.d.ts @@ -4,6 +4,7 @@ import * as _babel_types from '@babel/types'; type Plugin = | "asyncDoExpressions" + | "asyncExplicitResourceManagement" | "asyncGenerators" | "bigInt" | "classPrivateMethods" From 3077cb09c645462c9904d6a7a8777514ed59fd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 27 Mar 2023 19:38:59 -0400 Subject: [PATCH 11/15] update git clean fix command --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d273840cec0..1e7d45496c42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -184,7 +184,7 @@ jobs: run: make -j prepublish-prepare-dts lint-ci - name: Ensure cwd does not contain uncommitted changes run: | - node ./scripts/assert-dir-git-clean.js code-quality + node ./scripts/assert-dir-git-clean.js "prepublish-prepare-dts lint-ci" test: name: Test on Node.js # GitHub will add ${{ matrix.node-version }} to this title From c73895714b4c2b1bebfa277f52afa4db28fede63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sat, 29 Apr 2023 09:27:23 -0400 Subject: [PATCH 12/15] add new test cases --- .../valid-await-expr-using-in/input.js | 3 + .../valid-await-expr-using-in/output.json | 55 +++++++++++++++++++ .../input.js | 3 + .../output.json | 55 +++++++++++++++++++ .../valid-await-expr-using-in/input.js | 3 + .../valid-await-expr-using-in/output.json | 55 +++++++++++++++++++ .../input.js | 3 + .../output.json | 55 +++++++++++++++++++ 8 files changed, 232 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/input.js create mode 100644 packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/output.json create mode 100644 packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/input.js create mode 100644 packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-in/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-in/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-instanceof/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-instanceof/output.json diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/input.js new file mode 100644 index 000000000000..7dcf9e0239b2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/input.js @@ -0,0 +1,3 @@ +async function f() { + await using in foo; +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/output.json new file mode 100644 index 000000000000..17b6ddee31ba --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/output.json @@ -0,0 +1,55 @@ +{ + "type": "File", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":44}}, + "program": { + "type": "Program", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":44}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":44}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":44,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":44}}, + "body": [ + { + "type": "ExpressionStatement", + "start":23,"end":42,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":21,"index":42}}, + "expression": { + "type": "BinaryExpression", + "start":23,"end":41,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":20,"index":41}}, + "left": { + "type": "AwaitExpression", + "start":23,"end":34,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":13,"index":34}}, + "argument": { + "type": "Identifier", + "start":29,"end":34,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":13,"index":34},"identifierName":"using"}, + "name": "using" + } + }, + "operator": "in", + "right": { + "type": "Identifier", + "start":38,"end":41,"loc":{"start":{"line":2,"column":17,"index":38},"end":{"line":2,"column":20,"index":41},"identifierName":"foo"}, + "name": "foo" + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/input.js new file mode 100644 index 000000000000..1818647e4761 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/input.js @@ -0,0 +1,3 @@ +async function f() { + await using instanceof foo; +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/output.json new file mode 100644 index 000000000000..39f78de56eb9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/output.json @@ -0,0 +1,55 @@ +{ + "type": "File", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":52}}, + "program": { + "type": "Program", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":52}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":52}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":52,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":52}}, + "body": [ + { + "type": "ExpressionStatement", + "start":23,"end":50,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":29,"index":50}}, + "expression": { + "type": "BinaryExpression", + "start":23,"end":49,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":28,"index":49}}, + "left": { + "type": "AwaitExpression", + "start":23,"end":34,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":13,"index":34}}, + "argument": { + "type": "Identifier", + "start":29,"end":34,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":13,"index":34},"identifierName":"using"}, + "name": "using" + } + }, + "operator": "instanceof", + "right": { + "type": "Identifier", + "start":46,"end":49,"loc":{"start":{"line":2,"column":25,"index":46},"end":{"line":2,"column":28,"index":49},"identifierName":"foo"}, + "name": "foo" + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-in/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-in/input.js new file mode 100644 index 000000000000..7dcf9e0239b2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-in/input.js @@ -0,0 +1,3 @@ +async function f() { + await using in foo; +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-in/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-in/output.json new file mode 100644 index 000000000000..17b6ddee31ba --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-in/output.json @@ -0,0 +1,55 @@ +{ + "type": "File", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":44}}, + "program": { + "type": "Program", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":44}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":44}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":44,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":44}}, + "body": [ + { + "type": "ExpressionStatement", + "start":23,"end":42,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":21,"index":42}}, + "expression": { + "type": "BinaryExpression", + "start":23,"end":41,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":20,"index":41}}, + "left": { + "type": "AwaitExpression", + "start":23,"end":34,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":13,"index":34}}, + "argument": { + "type": "Identifier", + "start":29,"end":34,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":13,"index":34},"identifierName":"using"}, + "name": "using" + } + }, + "operator": "in", + "right": { + "type": "Identifier", + "start":38,"end":41,"loc":{"start":{"line":2,"column":17,"index":38},"end":{"line":2,"column":20,"index":41},"identifierName":"foo"}, + "name": "foo" + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-instanceof/input.js b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-instanceof/input.js new file mode 100644 index 000000000000..1818647e4761 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-instanceof/input.js @@ -0,0 +1,3 @@ +async function f() { + await using instanceof foo; +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-instanceof/output.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-instanceof/output.json new file mode 100644 index 000000000000..39f78de56eb9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-expr-using-instanceof/output.json @@ -0,0 +1,55 @@ +{ + "type": "File", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":52}}, + "program": { + "type": "Program", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":52}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":52}}, + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":19,"end":52,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":52}}, + "body": [ + { + "type": "ExpressionStatement", + "start":23,"end":50,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":29,"index":50}}, + "expression": { + "type": "BinaryExpression", + "start":23,"end":49,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":28,"index":49}}, + "left": { + "type": "AwaitExpression", + "start":23,"end":34,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":13,"index":34}}, + "argument": { + "type": "Identifier", + "start":29,"end":34,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":13,"index":34},"identifierName":"using"}, + "name": "using" + } + }, + "operator": "instanceof", + "right": { + "type": "Identifier", + "start":46,"end":49,"loc":{"start":{"line":2,"column":25,"index":46},"end":{"line":2,"column":28,"index":49},"identifierName":"foo"}, + "name": "foo" + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} From 867229a7cddf3397e1589779ff529f32bc98458b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 30 Apr 2023 10:22:59 -0400 Subject: [PATCH 13/15] remove syntax-async-explicit-resource-management --- .../README.md | 19 ------- .../package.json | 50 ------------------- .../src/index.ts | 13 ----- packages/babel-standalone/package.json | 1 - .../scripts/pluginConfig.json | 1 - .../babel-standalone/src/generated/plugins.ts | 4 -- .../babel-standalone/src/preset-stage-2.ts | 1 - yarn.lock | 12 ----- 8 files changed, 101 deletions(-) delete mode 100644 packages/babel-plugin-syntax-async-explicit-resource-management/README.md delete mode 100644 packages/babel-plugin-syntax-async-explicit-resource-management/package.json delete mode 100644 packages/babel-plugin-syntax-async-explicit-resource-management/src/index.ts diff --git a/packages/babel-plugin-syntax-async-explicit-resource-management/README.md b/packages/babel-plugin-syntax-async-explicit-resource-management/README.md deleted file mode 100644 index db45b0044848..000000000000 --- a/packages/babel-plugin-syntax-async-explicit-resource-management/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# @babel/plugin-syntax-async-explicit-resource-management - -> Allow parsing of the using declarations - -See our website [@babel/plugin-syntax-async-explicit-resource-management](https://babeljs.io/docs/en/babel-plugin-syntax-async-explicit-resource-management) for more information. - -## Install - -Using npm: - -```sh -npm install --save-dev @babel/plugin-syntax-async-explicit-resource-management -``` - -or using yarn: - -```sh -yarn add @babel/plugin-syntax-async-explicit-resource-management --dev -``` diff --git a/packages/babel-plugin-syntax-async-explicit-resource-management/package.json b/packages/babel-plugin-syntax-async-explicit-resource-management/package.json deleted file mode 100644 index b18917c00342..000000000000 --- a/packages/babel-plugin-syntax-async-explicit-resource-management/package.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "name": "@babel/plugin-syntax-async-explicit-resource-management", - "version": "7.20.0", - "description": "Allow parsing of the await using declarations", - "repository": { - "type": "git", - "url": "https://github.com/babel/babel.git", - "directory": "packages/babel-plugin-syntax-async-explicit-resource-management" - }, - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "main": "./lib/index.js", - "keywords": [ - "babel-plugin" - ], - "dependencies": { - "@babel/helper-plugin-utils": "workspace:^" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - }, - "devDependencies": { - "@babel/core": "workspace:^" - }, - "engines": { - "node": ">=6.9.0" - }, - "author": "The Babel Team (https://babel.dev/team)", - "conditions": { - "BABEL_8_BREAKING": [ - null, - { - "exports": null - } - ], - "USE_ESM": [ - { - "type": "module" - }, - null - ] - }, - "exports": { - ".": "./lib/index.js", - "./package.json": "./package.json" - }, - "type": "commonjs" -} diff --git a/packages/babel-plugin-syntax-async-explicit-resource-management/src/index.ts b/packages/babel-plugin-syntax-async-explicit-resource-management/src/index.ts deleted file mode 100644 index a3d8551311db..000000000000 --- a/packages/babel-plugin-syntax-async-explicit-resource-management/src/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { declare } from "@babel/helper-plugin-utils"; - -export default declare(api => { - api.assertVersion(7); - - return { - name: "syntax-async-explicit-resource-management", - - manipulateOptions(opts, parserOpts) { - parserOpts.plugins.push("asyncExplicitResourceManagement"); - }, - }; -}); diff --git a/packages/babel-standalone/package.json b/packages/babel-standalone/package.json index ed37491fe6cc..2e9ae54db80a 100644 --- a/packages/babel-standalone/package.json +++ b/packages/babel-standalone/package.json @@ -39,7 +39,6 @@ "@babel/plugin-proposal-throw-expressions": "workspace:^", "@babel/plugin-proposal-unicode-property-regex": "workspace:^", "@babel/plugin-proposal-unicode-sets-regex": "workspace:^", - "@babel/plugin-syntax-async-explicit-resource-management": "workspace:^", "@babel/plugin-syntax-decimal": "workspace:^", "@babel/plugin-syntax-decorators": "workspace:^", "@babel/plugin-syntax-destructuring-private": "workspace:^", diff --git a/packages/babel-standalone/scripts/pluginConfig.json b/packages/babel-standalone/scripts/pluginConfig.json index 16c6e90b783c..815d03edd31c 100644 --- a/packages/babel-standalone/scripts/pluginConfig.json +++ b/packages/babel-standalone/scripts/pluginConfig.json @@ -20,7 +20,6 @@ ], "externalPlugins": [ "external-helpers", - "syntax-async-explicit-resource-management", "syntax-decimal", "syntax-decorators", "syntax-destructuring-private", diff --git a/packages/babel-standalone/src/generated/plugins.ts b/packages/babel-standalone/src/generated/plugins.ts index 7bda0a41d36d..285f8946c40c 100644 --- a/packages/babel-standalone/src/generated/plugins.ts +++ b/packages/babel-standalone/src/generated/plugins.ts @@ -4,7 +4,6 @@ */ import makeNoopPlugin from "../make-noop-plugin"; import externalHelpers from "@babel/plugin-external-helpers"; -import syntaxAsyncExplicitResourceManagement from "@babel/plugin-syntax-async-explicit-resource-management"; import syntaxDecimal from "@babel/plugin-syntax-decimal"; import syntaxDecorators from "@babel/plugin-syntax-decorators"; import syntaxDestructuringPrivate from "@babel/plugin-syntax-destructuring-private"; @@ -108,7 +107,6 @@ export const syntaxAsyncGenerators = makeNoopPlugin(), syntaxTopLevelAwait = makeNoopPlugin(); export { externalHelpers, - syntaxAsyncExplicitResourceManagement, syntaxDecimal, syntaxDecorators, syntaxDestructuringPrivate, @@ -213,8 +211,6 @@ export const all: { [k: string]: any } = { "syntax-optional-catch-binding": syntaxOptionalCatchBinding, "syntax-top-level-await": syntaxTopLevelAwait, "external-helpers": externalHelpers, - "syntax-async-explicit-resource-management": - syntaxAsyncExplicitResourceManagement, "syntax-decimal": syntaxDecimal, "syntax-decorators": syntaxDecorators, "syntax-destructuring-private": syntaxDestructuringPrivate, diff --git a/packages/babel-standalone/src/preset-stage-2.ts b/packages/babel-standalone/src/preset-stage-2.ts index 67402651631d..d1bd3788d1a2 100644 --- a/packages/babel-standalone/src/preset-stage-2.ts +++ b/packages/babel-standalone/src/preset-stage-2.ts @@ -11,7 +11,6 @@ export default (_: any, opts: any = {}) => { return { presets: [[presetStage3, opts]], plugins: [ - babelPlugins.syntaxAsyncExplicitResourceManagement, babelPlugins.proposalDestructuringPrivate, [ babelPlugins.proposalPipelineOperator, diff --git a/yarn.lock b/yarn.lock index 86bc3f33f8e1..8246ec05989b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1832,17 +1832,6 @@ __metadata: languageName: unknown linkType: soft -"@babel/plugin-syntax-async-explicit-resource-management@workspace:^, @babel/plugin-syntax-async-explicit-resource-management@workspace:packages/babel-plugin-syntax-async-explicit-resource-management": - version: 0.0.0-use.local - resolution: "@babel/plugin-syntax-async-explicit-resource-management@workspace:packages/babel-plugin-syntax-async-explicit-resource-management" - dependencies: - "@babel/core": "workspace:^" - "@babel/helper-plugin-utils": "workspace:^" - peerDependencies: - "@babel/core": ^7.0.0-0 - languageName: unknown - linkType: soft - "@babel/plugin-syntax-async-generators@npm:^7.8.4": version: 7.8.4 resolution: "@babel/plugin-syntax-async-generators@npm:7.8.4" @@ -3708,7 +3697,6 @@ __metadata: "@babel/plugin-proposal-throw-expressions": "workspace:^" "@babel/plugin-proposal-unicode-property-regex": "workspace:^" "@babel/plugin-proposal-unicode-sets-regex": "workspace:^" - "@babel/plugin-syntax-async-explicit-resource-management": "workspace:^" "@babel/plugin-syntax-decimal": "workspace:^" "@babel/plugin-syntax-decorators": "workspace:^" "@babel/plugin-syntax-destructuring-private": "workspace:^" From dc2db162f1945f04ab8559a90fc8a56839beaad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 30 Apr 2023 10:30:37 -0400 Subject: [PATCH 14/15] merge asyncExplicitResourceManagement with explicitResourceManagement --- .../test/fixtures/await-using-declarations/options.json | 2 +- packages/babel-parser/data/schema.json | 1 - packages/babel-parser/src/parser/statement.ts | 2 +- packages/babel-parser/src/typings.d.ts | 1 - .../input.js | 0 .../options.json | 2 +- .../async-explicit-resource-management/options.json | 2 +- .../valid-await-asi-using-asi-assignment/options.json | 2 +- .../valid-await-asi-using-binding/options.json | 2 +- .../valid-await-using-asi-assignment/options.json | 2 +- .../valid-module-block-top-level-using-binding/options.json | 2 +- 11 files changed, 8 insertions(+), 10 deletions(-) rename packages/babel-parser/test/fixtures/experimental/_no-plugin/{async-explicit-resource-management-variable-declaration => explicit-resource-management-variable-declaration-async}/input.js (100%) rename packages/babel-parser/test/fixtures/experimental/_no-plugin/{async-explicit-resource-management-variable-declaration => explicit-resource-management-variable-declaration-async}/options.json (55%) diff --git a/packages/babel-generator/test/fixtures/await-using-declarations/options.json b/packages/babel-generator/test/fixtures/await-using-declarations/options.json index 48bceee79c05..495a16f9a39a 100644 --- a/packages/babel-generator/test/fixtures/await-using-declarations/options.json +++ b/packages/babel-generator/test/fixtures/await-using-declarations/options.json @@ -1,3 +1,3 @@ { - "plugins": ["asyncExplicitResourceManagement"] + "plugins": ["explicitResourceManagement"] } diff --git a/packages/babel-parser/data/schema.json b/packages/babel-parser/data/schema.json index 659af3272f02..8573cc3ee88a 100644 --- a/packages/babel-parser/data/schema.json +++ b/packages/babel-parser/data/schema.json @@ -127,7 +127,6 @@ { "enum": [ "asyncDoExpressions", - "asyncExplicitResourceManagement", "asyncGenerators", "bigInt", "classPrivateMethods", diff --git a/packages/babel-parser/src/parser/statement.ts b/packages/babel-parser/src/parser/statement.ts index 6c6fdb941ca6..ed3e37800791 100644 --- a/packages/babel-parser/src/parser/statement.ts +++ b/packages/babel-parser/src/parser/statement.ts @@ -354,7 +354,7 @@ export default abstract class StatementParser extends ExpressionParser { next = this.nextTokenInLineStartSince(next + 5); const nextCh = this.codePointAtPos(next); if (this.chStartsBindingIdentifier(nextCh, next)) { - this.expectPlugin("asyncExplicitResourceManagement"); + this.expectPlugin("explicitResourceManagement"); return true; } } diff --git a/packages/babel-parser/src/typings.d.ts b/packages/babel-parser/src/typings.d.ts index bfde3490be83..3ed4a5c70b59 100644 --- a/packages/babel-parser/src/typings.d.ts +++ b/packages/babel-parser/src/typings.d.ts @@ -1,6 +1,5 @@ export type Plugin = | "asyncDoExpressions" - | "asyncExplicitResourceManagement" | "asyncGenerators" | "bigInt" | "classPrivateMethods" diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/input.js rename to packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/options.json similarity index 55% rename from packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/options.json rename to packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/options.json index 63a3dde712b5..7f3de7534e6c 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-explicit-resource-management-variable-declaration/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/options.json @@ -1,3 +1,3 @@ { - "throws": "This experimental syntax requires enabling the parser plugin: \"asyncExplicitResourceManagement\". (2:2)" + "throws": "This experimental syntax requires enabling the parser plugin: \"explicitResourceManagement\". (2:2)" } diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/options.json index 48bceee79c05..495a16f9a39a 100644 --- a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/options.json +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/options.json @@ -1,3 +1,3 @@ { - "plugins": ["asyncExplicitResourceManagement"] + "plugins": ["explicitResourceManagement"] } diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/options.json index ff1d688a13e9..495a16f9a39a 100644 --- a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/options.json +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-asi-assignment/options.json @@ -1,3 +1,3 @@ { - "plugins": ["asyncExplicitResourceManagement", "explicitResourceManagement"] + "plugins": ["explicitResourceManagement"] } diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/options.json index ff1d688a13e9..495a16f9a39a 100644 --- a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/options.json +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-asi-using-binding/options.json @@ -1,3 +1,3 @@ { - "plugins": ["asyncExplicitResourceManagement", "explicitResourceManagement"] + "plugins": ["explicitResourceManagement"] } diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/options.json index ff1d688a13e9..495a16f9a39a 100644 --- a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/options.json +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-await-using-asi-assignment/options.json @@ -1,3 +1,3 @@ { - "plugins": ["asyncExplicitResourceManagement", "explicitResourceManagement"] + "plugins": ["explicitResourceManagement"] } diff --git a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/options.json b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/options.json index 70e7070ed475..aefaa1b232dd 100644 --- a/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/options.json +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-module-block-top-level-using-binding/options.json @@ -1,4 +1,4 @@ { "sourceType": "script", - "plugins": ["asyncExplicitResourceManagement", "moduleBlocks"] + "plugins": ["explicitResourceManagement", "moduleBlocks"] } From 885d997c3d22580a5c35086c5ca146dd6d61b987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 30 Apr 2023 11:22:52 -0400 Subject: [PATCH 15/15] update typings --- packages/babel-parser/typings/babel-parser.d.ts | 1 - tsconfig.json | 4 ---- 2 files changed, 5 deletions(-) diff --git a/packages/babel-parser/typings/babel-parser.d.ts b/packages/babel-parser/typings/babel-parser.d.ts index ee7c05c75311..d80fff653c30 100644 --- a/packages/babel-parser/typings/babel-parser.d.ts +++ b/packages/babel-parser/typings/babel-parser.d.ts @@ -4,7 +4,6 @@ import * as _babel_types from '@babel/types'; type Plugin = | "asyncDoExpressions" - | "asyncExplicitResourceManagement" | "asyncGenerators" | "bigInt" | "classPrivateMethods" diff --git a/tsconfig.json b/tsconfig.json index 64106417631e..a362623d5daf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -71,7 +71,6 @@ "./packages/babel-plugin-proposal-unicode-property-regex/src/**/*.ts", "./packages/babel-plugin-proposal-unicode-sets-regex/src/**/*.ts", "./packages/babel-plugin-syntax-async-do-expressions/src/**/*.ts", - "./packages/babel-plugin-syntax-async-explicit-resource-management/src/**/*.ts", "./packages/babel-plugin-syntax-decimal/src/**/*.ts", "./packages/babel-plugin-syntax-decorators/src/**/*.ts", "./packages/babel-plugin-syntax-destructuring-private/src/**/*.ts", @@ -380,9 +379,6 @@ "@babel/plugin-syntax-async-do-expressions": [ "./packages/babel-plugin-syntax-async-do-expressions/src" ], - "@babel/plugin-syntax-async-explicit-resource-management": [ - "./packages/babel-plugin-syntax-async-explicit-resource-management/src" - ], "@babel/plugin-syntax-decimal": [ "./packages/babel-plugin-syntax-decimal/src" ],