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 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..495a16f9a39a --- /dev/null +++ b/packages/babel-generator/test/fixtures/await-using-declarations/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["explicitResourceManagement"] +} diff --git a/packages/babel-parser/data/schema.json b/packages/babel-parser/data/schema.json index ec354824d433..8573cc3ee88a 100644 --- a/packages/babel-parser/data/schema.json +++ b/packages/babel-parser/data/schema.json @@ -126,6 +126,7 @@ }, { "enum": [ + "asyncDoExpressions", "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 bd023239ef5b..ed3e37800791 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, @@ -349,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("explicitResourceManagement"); + return true; + } + } + return false; + } + // https://tc39.es/ecma262/#prod-ModuleItem parseModuleItem(this: Parser) { return this.parseStatementLike( @@ -483,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 ( @@ -913,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 @@ -1159,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(); @@ -1492,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 = []); @@ -1534,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, { @@ -2458,11 +2505,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 { 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/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/_no-plugin/explicit-resource-management-variable-declaration-async/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/input.js new file mode 100644 index 000000000000..0f2a5dfcc635 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/input.js @@ -0,0 +1,3 @@ +async function f() { + await using reader = getReader(); +} diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/options.json new file mode 100644 index 000000000000..7f3de7534e6c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/explicit-resource-management-variable-declaration-async/options.json @@ -0,0 +1,3 @@ +{ + "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/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-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-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/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)" +} 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..495a16f9a39a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["explicitResourceManagement"] +} 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..495a16f9a39a --- /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": ["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..495a16f9a39a --- /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": ["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-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": [] + } +} 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..495a16f9a39a --- /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": ["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..aefaa1b232dd --- /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": ["explicitResourceManagement", "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": [] + } +} 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": [] + } +} 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; 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: {