From a6b98a7eafcfeccc89d95ad7e8ade28e05af576b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 7 Apr 2021 12:24:33 -0400 Subject: [PATCH] Parse async do expressions (#13043) * parse async do expressions * add test cases * update test fixtures * chore: add syntax-async-do-expressions * generater support * fix: do not transform async do expressions * chore: add asyncDoExpressions to missing plugin helpers * update ast types * add more test cases * throw when asyncDoExpressions is enabled but not doExpressions * avoid add parentheses for async do expressions * address review comments * chore: update parser typings --- .../src/parser/util/missing-plugin-helper.ts | 6 + .../src/generators/expressions.ts | 4 + .../babel-generator/src/node/parentheses.ts | 3 +- .../async-do-expressions/basic/input.js | 5 + .../async-do-expressions/basic/output.js | 4 + .../async-do-expressions/options.json | 3 + .../retain-lines/input.js | 3 + .../retain-lines/options.json | 3 + .../retain-lines/output.js | 3 + packages/babel-parser/ast/spec.md | 1 + .../babel-parser/src/parser/expression.js | 22 ++- packages/babel-parser/src/plugin-utils.js | 12 ++ packages/babel-parser/src/types.js | 1 + .../input.js | 1 + .../options.json | 6 + .../_no-plugin/async-do-expressions/input.js | 1 + .../async-do-expressions/options.json | 4 + .../asi-async-and-do-while/input.js | 5 + .../asi-async-and-do-while/output.json | 51 +++++++ .../asi-async-do-and-while/input.js | 4 + .../asi-async-do-and-while/output.json | 55 ++++++++ .../async-do-expressions/asi/input.js | 4 + .../async-do-expressions/asi/options.json | 3 + .../conditional-statement/input.js | 5 + .../conditional-statement/output.json | 132 ++++++++++++++++++ .../expression-statement/input.js | 3 + .../expression-statement/output.json | 46 ++++++ .../invalid-break/input.js | 8 ++ .../invalid-break/output.json | 94 +++++++++++++ .../invalid-generators/input.js | 5 + .../invalid-generators/output.json | 81 +++++++++++ .../invalid-return/input.js | 5 + .../invalid-return/output.json | 68 +++++++++ .../async-do-expressions/options.json | 3 + .../scoping-variable/input.js | 4 + .../scoping-variable/output.json | 100 +++++++++++++ .../conditional-statement/output.json | 1 + .../scoping-variable/output.json | 1 + .../do-expressions/with-jsx/output.json | 11 +- .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 9 +- .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 1 + .../output.json | 9 +- .../output.json | 9 +- .../output.json | 9 +- .../output.json | 1 + .../babel-parser/typings/babel-parser.d.ts | 1 + .../src/index.js | 7 +- .../async-do-expressions/basic/input.js | 1 + .../async-do-expressions/basic/output.js | 1 + .../async-do-expressions/options.json | 3 + .../.npmignore | 3 + .../README.md | 19 +++ .../package.json | 31 ++++ .../src/index.ts | 13 ++ .../src/ast-types/generated/index.ts | 1 + .../src/builders/generated/index.ts | 5 +- .../src/definitions/experimental.ts | 5 + yarn.lock | 11 ++ 76 files changed, 901 insertions(+), 27 deletions(-) create mode 100644 packages/babel-generator/test/fixtures/async-do-expressions/basic/input.js create mode 100644 packages/babel-generator/test/fixtures/async-do-expressions/basic/output.js create mode 100644 packages/babel-generator/test/fixtures/async-do-expressions/options.json create mode 100644 packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/input.js create mode 100644 packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/options.json create mode 100644 packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/output.js create mode 100644 packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/conditional-statement/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/conditional-statement/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/expression-statement/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/expression-statement/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-break/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-break/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-generators/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-generators/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-return/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-return/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/scoping-variable/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/async-do-expressions/scoping-variable/output.json create mode 100644 packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/basic/input.js create mode 100644 packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/basic/output.js create mode 100644 packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/options.json create mode 100644 packages/babel-plugin-syntax-async-do-expressions/.npmignore create mode 100644 packages/babel-plugin-syntax-async-do-expressions/README.md create mode 100644 packages/babel-plugin-syntax-async-do-expressions/package.json create mode 100644 packages/babel-plugin-syntax-async-do-expressions/src/index.ts diff --git a/packages/babel-core/src/parser/util/missing-plugin-helper.ts b/packages/babel-core/src/parser/util/missing-plugin-helper.ts index 93ed711c5c14..81199e7d0db1 100644 --- a/packages/babel-core/src/parser/util/missing-plugin-helper.ts +++ b/packages/babel-core/src/parser/util/missing-plugin-helper.ts @@ -1,4 +1,10 @@ const pluginNameMap = { + asyncDoExpressions: { + syntax: { + name: "@babel/plugin-syntax-async-do-expressions", + url: "https://git.io/JYer8", + }, + }, classProperties: { syntax: { name: "@babel/plugin-syntax-class-properties", diff --git a/packages/babel-generator/src/generators/expressions.ts b/packages/babel-generator/src/generators/expressions.ts index 160ca3299575..83724709a8a7 100644 --- a/packages/babel-generator/src/generators/expressions.ts +++ b/packages/babel-generator/src/generators/expressions.ts @@ -20,6 +20,10 @@ export function UnaryExpression(this: Printer, node: t.UnaryExpression) { } export function DoExpression(this: Printer, node: t.DoExpression) { + if (node.async) { + this.word("async"); + this.space(); + } this.word("do"); this.space(); this.print(node.body, node); diff --git a/packages/babel-generator/src/node/parentheses.ts b/packages/babel-generator/src/node/parentheses.ts index 26789bf13d10..fe10bf5886c8 100644 --- a/packages/babel-generator/src/node/parentheses.ts +++ b/packages/babel-generator/src/node/parentheses.ts @@ -82,7 +82,8 @@ export function DoExpression( parent: any, printStack: Array, ): boolean { - return isFirstInStatement(printStack); + // `async do` can start an expression statement + return !node.async && isFirstInStatement(printStack); } export function Binary(node: any, parent: any): boolean { diff --git a/packages/babel-generator/test/fixtures/async-do-expressions/basic/input.js b/packages/babel-generator/test/fixtures/async-do-expressions/basic/input.js new file mode 100644 index 000000000000..54b0a1353b89 --- /dev/null +++ b/packages/babel-generator/test/fixtures/async-do-expressions/basic/input.js @@ -0,0 +1,5 @@ +async do { + 1; +}; + +(async do {}); diff --git a/packages/babel-generator/test/fixtures/async-do-expressions/basic/output.js b/packages/babel-generator/test/fixtures/async-do-expressions/basic/output.js new file mode 100644 index 000000000000..aa91c74fb0f9 --- /dev/null +++ b/packages/babel-generator/test/fixtures/async-do-expressions/basic/output.js @@ -0,0 +1,4 @@ +async do { + 1; +}; +async do {}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/async-do-expressions/options.json b/packages/babel-generator/test/fixtures/async-do-expressions/options.json new file mode 100644 index 000000000000..94fd7ea36118 --- /dev/null +++ b/packages/babel-generator/test/fixtures/async-do-expressions/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["asyncDoExpressions", "doExpressions"] +} diff --git a/packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/input.js b/packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/input.js new file mode 100644 index 000000000000..26a551e14ec1 --- /dev/null +++ b/packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/input.js @@ -0,0 +1,3 @@ +/* leading comments +*/async do +{ 1 } + 0; diff --git a/packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/options.json b/packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/options.json new file mode 100644 index 000000000000..97925bbcb61b --- /dev/null +++ b/packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/options.json @@ -0,0 +1,3 @@ +{ + "retainLines": true +} diff --git a/packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/output.js b/packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/output.js new file mode 100644 index 000000000000..640c3d984594 --- /dev/null +++ b/packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/output.js @@ -0,0 +1,3 @@ +/* leading comments +*/async do +{1;} + 0; \ No newline at end of file diff --git a/packages/babel-parser/ast/spec.md b/packages/babel-parser/ast/spec.md index 48d37a300eb8..0e005fd2295e 100644 --- a/packages/babel-parser/ast/spec.md +++ b/packages/babel-parser/ast/spec.md @@ -1084,6 +1084,7 @@ An expression wrapped by parentheses. By default `@babel/parser` does not create interface DoExpression <: Expression { type: "DoExpression"; body: BlockStatement; + async: boolean; } ``` diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 9a3271a8262b..6a4c0e8a5fb2 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1033,6 +1033,8 @@ export default class ExpressionParser extends LValParser { ); } else if (this.match(tt.name)) { return this.parseAsyncArrowUnaryFunction(id); + } else if (this.match(tt._do)) { + return this.parseDo(true); } } @@ -1049,7 +1051,7 @@ export default class ExpressionParser extends LValParser { } case tt._do: { - return this.parseDo(); + return this.parseDo(false); } case tt.regexp: { @@ -1231,13 +1233,27 @@ export default class ExpressionParser extends LValParser { } // https://github.com/tc39/proposal-do-expressions - parseDo(): N.DoExpression { + // https://github.com/tc39/proposal-async-do-expressions + parseDo(isAsync: boolean): N.DoExpression { this.expectPlugin("doExpressions"); + if (isAsync) { + this.expectPlugin("asyncDoExpressions"); + } const node = this.startNode(); + node.async = isAsync; this.next(); // eat `do` const oldLabels = this.state.labels; this.state.labels = []; - node.body = this.parseBlock(); + if (isAsync) { + // AsyncDoExpression : + // async [no LineTerminator here] do Block[~Yield, +Await, ~Return] + this.prodParam.enter(PARAM_AWAIT); + node.body = this.parseBlock(); + this.prodParam.exit(); + } else { + node.body = this.parseBlock(); + } + this.state.labels = oldLabels; return this.finishNode(node, "DoExpression"); } diff --git a/packages/babel-parser/src/plugin-utils.js b/packages/babel-parser/src/plugin-utils.js index 777ee42b20bf..194bc1aa7465 100644 --- a/packages/babel-parser/src/plugin-utils.js +++ b/packages/babel-parser/src/plugin-utils.js @@ -117,6 +117,18 @@ export function validatePlugins(plugins: PluginList) { RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "), ); } + + if ( + hasPlugin(plugins, "asyncDoExpressions") && + !hasPlugin(plugins, "doExpressions") + ) { + const error = new Error( + "'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.", + ); + // $FlowIgnore + error.missingPlugins = "doExpressions"; // so @babel/core can provide better error message + throw error; + } } // These plugins are defined using a mixin which extends the parser class. diff --git a/packages/babel-parser/src/types.js b/packages/babel-parser/src/types.js index 92f1c678a0af..593da56126bf 100644 --- a/packages/babel-parser/src/types.js +++ b/packages/babel-parser/src/types.js @@ -402,6 +402,7 @@ export type ArrayExpression = NodeBase & { export type DoExpression = NodeBase & { type: "DoExpression", body: ?BlockStatement, + async: boolean, }; export type TupleExpression = NodeBase & { diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/input.js new file mode 100644 index 000000000000..214ceb13862c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/input.js @@ -0,0 +1 @@ +(async do {x}) diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/options.json new file mode 100644 index 000000000000..082c82b3aead --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/options.json @@ -0,0 +1,6 @@ +{ + "throws": "This experimental syntax requires enabling the parser plugin: 'asyncDoExpressions' (1:7)", + "plugins": [ + "doExpressions" + ] +} diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/input.js new file mode 100644 index 000000000000..214ceb13862c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/input.js @@ -0,0 +1 @@ +(async do {x}) diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/options.json new file mode 100644 index 000000000000..5af0fa0b53a9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/options.json @@ -0,0 +1,4 @@ +{ + "throws": "This experimental syntax requires enabling the parser plugin: 'doExpressions' (1:7)", + "plugins": [] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/input.js b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/input.js new file mode 100644 index 000000000000..64f17ab55b30 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/input.js @@ -0,0 +1,5 @@ +async +do { + 42 +} +while (false); diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/output.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/output.json new file mode 100644 index 000000000000..0958732d4937 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/output.json @@ -0,0 +1,51 @@ +{ + "type": "File", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":14}}, + "program": { + "type": "Program", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":14}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, + "expression": { + "type": "Identifier", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5},"identifierName":"async"}, + "name": "async" + } + }, + { + "type": "DoWhileStatement", + "start":6,"end":32,"loc":{"start":{"line":2,"column":0},"end":{"line":5,"column":14}}, + "body": { + "type": "BlockStatement", + "start":9,"end":17,"loc":{"start":{"line":2,"column":3},"end":{"line":4,"column":1}}, + "body": [ + { + "type": "ExpressionStatement", + "start":13,"end":15,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":4}}, + "expression": { + "type": "NumericLiteral", + "start":13,"end":15,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":4}}, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ], + "directives": [] + }, + "test": { + "type": "BooleanLiteral", + "start":25,"end":30,"loc":{"start":{"line":5,"column":7},"end":{"line":5,"column":12}}, + "value": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/input.js b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/input.js new file mode 100644 index 000000000000..1b0cef39060d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/input.js @@ -0,0 +1,4 @@ +async do { + 42 +} +while (false); diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/output.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/output.json new file mode 100644 index 000000000000..484a2b5ee528 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/output.json @@ -0,0 +1,55 @@ +{ + "type": "File", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":14}}, + "program": { + "type": "Program", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":14}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "expression": { + "type": "DoExpression", + "start":6,"end":17,"loc":{"start":{"line":1,"column":6},"end":{"line":3,"column":1}}, + "async": true, + "body": { + "type": "BlockStatement", + "start":9,"end":17,"loc":{"start":{"line":1,"column":9},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ExpressionStatement", + "start":13,"end":15,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":4}}, + "expression": { + "type": "NumericLiteral", + "start":13,"end":15,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":4}}, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ], + "directives": [] + } + } + }, + { + "type": "WhileStatement", + "start":18,"end":32,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":14}}, + "test": { + "type": "BooleanLiteral", + "start":25,"end":30,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":12}}, + "value": false + }, + "body": { + "type": "EmptyStatement", + "start":31,"end":32,"loc":{"start":{"line":4,"column":13},"end":{"line":4,"column":14}} + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/input.js b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/input.js new file mode 100644 index 000000000000..63e7b8867e81 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/input.js @@ -0,0 +1,4 @@ +async +do { + 42 +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/options.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/options.json new file mode 100644 index 000000000000..21fdf1bc4b62 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \"while\" (4:1)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/conditional-statement/input.js b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/conditional-statement/input.js new file mode 100644 index 000000000000..77dd5e7da681 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/conditional-statement/input.js @@ -0,0 +1,5 @@ +let x = async do { + if (foo()) { f() } + else if (bar()) { g() } + else { h() } +}; diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/conditional-statement/output.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/conditional-statement/output.json new file mode 100644 index 000000000000..b6d30323e45a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/conditional-statement/output.json @@ -0,0 +1,132 @@ +{ + "type": "File", + "start":0,"end":83,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "program": { + "type": "Program", + "start":0,"end":83,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":83,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":4,"end":82,"loc":{"start":{"line":1,"column":4},"end":{"line":5,"column":1}}, + "id": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"x"}, + "name": "x" + }, + "init": { + "type": "DoExpression", + "start":14,"end":82,"loc":{"start":{"line":1,"column":14},"end":{"line":5,"column":1}}, + "async": true, + "body": { + "type": "BlockStatement", + "start":17,"end":82,"loc":{"start":{"line":1,"column":17},"end":{"line":5,"column":1}}, + "body": [ + { + "type": "IfStatement", + "start":21,"end":80,"loc":{"start":{"line":2,"column":2},"end":{"line":4,"column":14}}, + "test": { + "type": "CallExpression", + "start":25,"end":30,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":11}}, + "callee": { + "type": "Identifier", + "start":25,"end":28,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9},"identifierName":"foo"}, + "name": "foo" + }, + "arguments": [] + }, + "consequent": { + "type": "BlockStatement", + "start":32,"end":39,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":20}}, + "body": [ + { + "type": "ExpressionStatement", + "start":34,"end":37,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":18}}, + "expression": { + "type": "CallExpression", + "start":34,"end":37,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":18}}, + "callee": { + "type": "Identifier", + "start":34,"end":35,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":16},"identifierName":"f"}, + "name": "f" + }, + "arguments": [] + } + } + ], + "directives": [] + }, + "alternate": { + "type": "IfStatement", + "start":47,"end":80,"loc":{"start":{"line":3,"column":7},"end":{"line":4,"column":14}}, + "test": { + "type": "CallExpression", + "start":51,"end":56,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":16}}, + "callee": { + "type": "Identifier", + "start":51,"end":54,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":14},"identifierName":"bar"}, + "name": "bar" + }, + "arguments": [] + }, + "consequent": { + "type": "BlockStatement", + "start":58,"end":65,"loc":{"start":{"line":3,"column":18},"end":{"line":3,"column":25}}, + "body": [ + { + "type": "ExpressionStatement", + "start":60,"end":63,"loc":{"start":{"line":3,"column":20},"end":{"line":3,"column":23}}, + "expression": { + "type": "CallExpression", + "start":60,"end":63,"loc":{"start":{"line":3,"column":20},"end":{"line":3,"column":23}}, + "callee": { + "type": "Identifier", + "start":60,"end":61,"loc":{"start":{"line":3,"column":20},"end":{"line":3,"column":21},"identifierName":"g"}, + "name": "g" + }, + "arguments": [] + } + } + ], + "directives": [] + }, + "alternate": { + "type": "BlockStatement", + "start":73,"end":80,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":14}}, + "body": [ + { + "type": "ExpressionStatement", + "start":75,"end":78,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":12}}, + "expression": { + "type": "CallExpression", + "start":75,"end":78,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":12}}, + "callee": { + "type": "Identifier", + "start":75,"end":76,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":10},"identifierName":"h"}, + "name": "h" + }, + "arguments": [] + } + } + ], + "directives": [] + } + } + } + ], + "directives": [] + } + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/expression-statement/input.js b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/expression-statement/input.js new file mode 100644 index 000000000000..82c96b93e34a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/expression-statement/input.js @@ -0,0 +1,3 @@ +async do { + await 42 +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/expression-statement/output.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/expression-statement/output.json new file mode 100644 index 000000000000..a9b0e3f49819 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/expression-statement/output.json @@ -0,0 +1,46 @@ +{ + "type": "File", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "expression": { + "type": "DoExpression", + "start":6,"end":23,"loc":{"start":{"line":1,"column":6},"end":{"line":3,"column":1}}, + "async": true, + "body": { + "type": "BlockStatement", + "start":9,"end":23,"loc":{"start":{"line":1,"column":9},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ExpressionStatement", + "start":13,"end":21,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10}}, + "expression": { + "type": "AwaitExpression", + "start":13,"end":21,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10}}, + "argument": { + "type": "NumericLiteral", + "start":19,"end":21,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":10}}, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + } + ], + "directives": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-break/input.js b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-break/input.js new file mode 100644 index 000000000000..3019c2ff7ac0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-break/input.js @@ -0,0 +1,8 @@ +function iter() { + switch(1) { + default: + var x = async do { + break; + } + } +}; diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-break/output.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-break/output.json new file mode 100644 index 000000000000..ff10d087311e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-break/output.json @@ -0,0 +1,94 @@ +{ + "type": "File", + "start":0,"end":99,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":2}}, + "errors": [ + "SyntaxError: Unsyntactic break (5:8)" + ], + "program": { + "type": "Program", + "start":0,"end":99,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":2}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":98,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}}, + "id": { + "type": "Identifier", + "start":9,"end":13,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":13},"identifierName":"iter"}, + "name": "iter" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":16,"end":98,"loc":{"start":{"line":1,"column":16},"end":{"line":8,"column":1}}, + "body": [ + { + "type": "SwitchStatement", + "start":20,"end":96,"loc":{"start":{"line":2,"column":2},"end":{"line":7,"column":3}}, + "discriminant": { + "type": "NumericLiteral", + "start":27,"end":28,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":10}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "cases": [ + { + "type": "SwitchCase", + "start":36,"end":92,"loc":{"start":{"line":3,"column":4},"end":{"line":6,"column":7}}, + "consequent": [ + { + "type": "VariableDeclaration", + "start":51,"end":92,"loc":{"start":{"line":4,"column":6},"end":{"line":6,"column":7}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":55,"end":92,"loc":{"start":{"line":4,"column":10},"end":{"line":6,"column":7}}, + "id": { + "type": "Identifier", + "start":55,"end":56,"loc":{"start":{"line":4,"column":10},"end":{"line":4,"column":11},"identifierName":"x"}, + "name": "x" + }, + "init": { + "type": "DoExpression", + "start":65,"end":92,"loc":{"start":{"line":4,"column":20},"end":{"line":6,"column":7}}, + "async": true, + "body": { + "type": "BlockStatement", + "start":68,"end":92,"loc":{"start":{"line":4,"column":23},"end":{"line":6,"column":7}}, + "body": [ + { + "type": "BreakStatement", + "start":78,"end":84,"loc":{"start":{"line":5,"column":8},"end":{"line":5,"column":14}}, + "label": null + } + ], + "directives": [] + } + } + } + ], + "kind": "var" + } + ], + "test": null + } + ] + } + ], + "directives": [] + } + }, + { + "type": "EmptyStatement", + "start":98,"end":99,"loc":{"start":{"line":8,"column":1},"end":{"line":8,"column":2}} + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-generators/input.js b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-generators/input.js new file mode 100644 index 000000000000..c5f2e4fc0041 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-generators/input.js @@ -0,0 +1,5 @@ +async function *iter() { + await async do { + yield 1; + } +}; diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-generators/output.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-generators/output.json new file mode 100644 index 000000000000..3d6b9e71535d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-generators/output.json @@ -0,0 +1,81 @@ +{ + "type": "File", + "start":0,"end":63,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "errors": [ + "SyntaxError: Missing semicolon (3:9)" + ], + "program": { + "type": "Program", + "start":0,"end":63,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "id": { + "type": "Identifier", + "start":16,"end":20,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":20},"identifierName":"iter"}, + "name": "iter" + }, + "generator": true, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":23,"end":62,"loc":{"start":{"line":1,"column":23},"end":{"line":5,"column":1}}, + "body": [ + { + "type": "ExpressionStatement", + "start":27,"end":60,"loc":{"start":{"line":2,"column":2},"end":{"line":4,"column":3}}, + "expression": { + "type": "AwaitExpression", + "start":27,"end":60,"loc":{"start":{"line":2,"column":2},"end":{"line":4,"column":3}}, + "argument": { + "type": "DoExpression", + "start":39,"end":60,"loc":{"start":{"line":2,"column":14},"end":{"line":4,"column":3}}, + "async": true, + "body": { + "type": "BlockStatement", + "start":42,"end":60,"loc":{"start":{"line":2,"column":17},"end":{"line":4,"column":3}}, + "body": [ + { + "type": "ExpressionStatement", + "start":48,"end":53,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":9}}, + "expression": { + "type": "Identifier", + "start":48,"end":53,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":9},"identifierName":"yield"}, + "name": "yield" + } + }, + { + "type": "ExpressionStatement", + "start":54,"end":56,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":12}}, + "expression": { + "type": "NumericLiteral", + "start":54,"end":55,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":11}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "directives": [] + } + } + } + } + ], + "directives": [] + } + }, + { + "type": "EmptyStatement", + "start":62,"end":63,"loc":{"start":{"line":5,"column":1},"end":{"line":5,"column":2}} + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-return/input.js b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-return/input.js new file mode 100644 index 000000000000..87c41a048d2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-return/input.js @@ -0,0 +1,5 @@ +function iter() { + return async do { + return 1; + } +}; diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-return/output.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-return/output.json new file mode 100644 index 000000000000..9f66131f91a7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/invalid-return/output.json @@ -0,0 +1,68 @@ +{ + "type": "File", + "start":0,"end":58,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "errors": [ + "SyntaxError: 'return' outside of function (3:4)" + ], + "program": { + "type": "Program", + "start":0,"end":58,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":57,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "id": { + "type": "Identifier", + "start":9,"end":13,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":13},"identifierName":"iter"}, + "name": "iter" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":16,"end":57,"loc":{"start":{"line":1,"column":16},"end":{"line":5,"column":1}}, + "body": [ + { + "type": "ReturnStatement", + "start":20,"end":55,"loc":{"start":{"line":2,"column":2},"end":{"line":4,"column":3}}, + "argument": { + "type": "DoExpression", + "start":33,"end":55,"loc":{"start":{"line":2,"column":15},"end":{"line":4,"column":3}}, + "async": true, + "body": { + "type": "BlockStatement", + "start":36,"end":55,"loc":{"start":{"line":2,"column":18},"end":{"line":4,"column":3}}, + "body": [ + { + "type": "ReturnStatement", + "start":42,"end":51,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":13}}, + "argument": { + "type": "NumericLiteral", + "start":49,"end":50,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":12}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "directives": [] + } + } + } + ], + "directives": [] + } + }, + { + "type": "EmptyStatement", + "start":57,"end":58,"loc":{"start":{"line":5,"column":1},"end":{"line":5,"column":2}} + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/options.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/options.json new file mode 100644 index 000000000000..9da4a4a2bf0c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["doExpressions", "asyncDoExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/scoping-variable/input.js b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/scoping-variable/input.js new file mode 100644 index 000000000000..e3a6917152ec --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/scoping-variable/input.js @@ -0,0 +1,4 @@ +let x = async do { + let tmp = f(); + tmp * tmp + 1 +}; diff --git a/packages/babel-parser/test/fixtures/experimental/async-do-expressions/scoping-variable/output.json b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/scoping-variable/output.json new file mode 100644 index 000000000000..b2fb42c3379a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/async-do-expressions/scoping-variable/output.json @@ -0,0 +1,100 @@ +{ + "type": "File", + "start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "program": { + "type": "Program", + "start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":4,"end":53,"loc":{"start":{"line":1,"column":4},"end":{"line":4,"column":1}}, + "id": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"x"}, + "name": "x" + }, + "init": { + "type": "DoExpression", + "start":14,"end":53,"loc":{"start":{"line":1,"column":14},"end":{"line":4,"column":1}}, + "async": true, + "body": { + "type": "BlockStatement", + "start":17,"end":53,"loc":{"start":{"line":1,"column":17},"end":{"line":4,"column":1}}, + "body": [ + { + "type": "VariableDeclaration", + "start":21,"end":35,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":25,"end":34,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":15}}, + "id": { + "type": "Identifier", + "start":25,"end":28,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9},"identifierName":"tmp"}, + "name": "tmp" + }, + "init": { + "type": "CallExpression", + "start":31,"end":34,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15}}, + "callee": { + "type": "Identifier", + "start":31,"end":32,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":13},"identifierName":"f"}, + "name": "f" + }, + "arguments": [] + } + } + ], + "kind": "let" + }, + { + "type": "ExpressionStatement", + "start":38,"end":51,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":15}}, + "expression": { + "type": "BinaryExpression", + "start":38,"end":51,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":15}}, + "left": { + "type": "BinaryExpression", + "start":38,"end":47,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":11}}, + "left": { + "type": "Identifier", + "start":38,"end":41,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5},"identifierName":"tmp"}, + "name": "tmp" + }, + "operator": "*", + "right": { + "type": "Identifier", + "start":44,"end":47,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":11},"identifierName":"tmp"}, + "name": "tmp" + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start":50,"end":51,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":15}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ], + "directives": [] + } + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/do-expressions/conditional-statement/output.json b/packages/babel-parser/test/fixtures/experimental/do-expressions/conditional-statement/output.json index 3f5de76a0efd..aa5f8bfc9113 100644 --- a/packages/babel-parser/test/fixtures/experimental/do-expressions/conditional-statement/output.json +++ b/packages/babel-parser/test/fixtures/experimental/do-expressions/conditional-statement/output.json @@ -22,6 +22,7 @@ "init": { "type": "DoExpression", "start":8,"end":76,"loc":{"start":{"line":1,"column":8},"end":{"line":5,"column":1}}, + "async": false, "body": { "type": "BlockStatement", "start":11,"end":76,"loc":{"start":{"line":1,"column":11},"end":{"line":5,"column":1}}, diff --git a/packages/babel-parser/test/fixtures/experimental/do-expressions/scoping-variable/output.json b/packages/babel-parser/test/fixtures/experimental/do-expressions/scoping-variable/output.json index ea877745593d..abf839ec454b 100644 --- a/packages/babel-parser/test/fixtures/experimental/do-expressions/scoping-variable/output.json +++ b/packages/babel-parser/test/fixtures/experimental/do-expressions/scoping-variable/output.json @@ -22,6 +22,7 @@ "init": { "type": "DoExpression", "start":8,"end":47,"loc":{"start":{"line":1,"column":8},"end":{"line":4,"column":1}}, + "async": false, "body": { "type": "BlockStatement", "start":11,"end":47,"loc":{"start":{"line":1,"column":11},"end":{"line":4,"column":1}}, diff --git a/packages/babel-parser/test/fixtures/experimental/do-expressions/with-jsx/output.json b/packages/babel-parser/test/fixtures/experimental/do-expressions/with-jsx/output.json index e3935122a552..cff7b87dc720 100644 --- a/packages/babel-parser/test/fixtures/experimental/do-expressions/with-jsx/output.json +++ b/packages/babel-parser/test/fixtures/experimental/do-expressions/with-jsx/output.json @@ -28,6 +28,10 @@ "argument": { "type": "JSXElement", "start":32,"end":216,"loc":{"start":{"line":3,"column":4},"end":{"line":14,"column":10}}, + "extra": { + "parenthesized": true, + "parenStart": 26 + }, "openingElement": { "type": "JSXOpeningElement", "start":32,"end":37,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":9}}, @@ -90,6 +94,7 @@ "expression": { "type": "DoExpression", "start":69,"end":197,"loc":{"start":{"line":6,"column":8},"end":{"line":12,"column":9}}, + "async": false, "body": { "type": "BlockStatement", "start":72,"end":197,"loc":{"start":{"line":6,"column":11},"end":{"line":12,"column":9}}, @@ -173,11 +178,7 @@ }, "value": "\n " } - ], - "extra": { - "parenthesized": true, - "parenStart": 26 - } + ] } } ], diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/output.json index 06a45df42fac..72ed96d1b277 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/output.json @@ -29,6 +29,7 @@ "expression": { "type": "DoExpression", "start":9,"end":42,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":42}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":42,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":42}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/output.json index e673a7df67c9..cd7bc1364079 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/output.json @@ -44,6 +44,7 @@ "expression": { "type": "DoExpression", "start":34,"end":75,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":52}}, + "async": false, "body": { "type": "BlockStatement", "start":37,"end":75,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":52}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/output.json index b413aeb837f3..41d29053db26 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/output.json @@ -29,6 +29,7 @@ "expression": { "type": "DoExpression", "start":9,"end":49,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":49}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":49,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":49}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/output.json index f907f6c39b60..eeebfc866853 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/output.json @@ -29,6 +29,7 @@ "expression": { "type": "DoExpression", "start":9,"end":36,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":36}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":36,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":36}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/output.json index b5610cbd5590..01551d682e74 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/output.json @@ -29,6 +29,7 @@ "expression": { "type": "DoExpression", "start":9,"end":38,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":38}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":38,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":38}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/output.json index cd596f541bf2..a585aaae74cf 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/output.json @@ -28,6 +28,7 @@ "expression": { "type": "DoExpression", "start":9,"end":78,"loc":{"start":{"line":1,"column":9},"end":{"line":4,"column":1}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":78,"loc":{"start":{"line":1,"column":12},"end":{"line":4,"column":1}}, @@ -53,12 +54,12 @@ "start":22,"end":26,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":12},"identifierName":"JSON"}, "name": "JSON" }, + "computed": false, "property": { "type": "Identifier", "start":27,"end":32,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":18},"identifierName":"parse"}, "name": "parse" - }, - "computed": false + } }, "arguments": [ { @@ -97,12 +98,12 @@ "start":57,"end":64,"loc":{"start":{"line":3,"column":18},"end":{"line":3,"column":25},"identifierName":"console"}, "name": "console" }, + "computed": false, "property": { "type": "Identifier", "start":65,"end":70,"loc":{"start":{"line":3,"column":26},"end":{"line":3,"column":31},"identifierName":"error"}, "name": "error" - }, - "computed": false + } }, "arguments": [ { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/output.json index cde715cc8a70..ac4abf954905 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/output.json @@ -29,6 +29,7 @@ "expression": { "type": "DoExpression", "start":9,"end":38,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":38}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":38,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":38}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/output.json index 10719f0083a3..2d2eb044da0f 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/output.json @@ -29,6 +29,7 @@ "expression": { "type": "DoExpression", "start":9,"end":28,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":28}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":28,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":28}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/output.json index 0321177a1072..219ca99243a6 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":41,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":41}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":41,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":41}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/output.json index aebaee1b7d4e..2832b644d755 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/output.json @@ -40,6 +40,7 @@ "expression": { "type": "DoExpression", "start":34,"end":68,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":45}}, + "async": false, "body": { "type": "BlockStatement", "start":37,"end":68,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":45}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/output.json index a6331818eb10..eeba9256176f 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":59,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":59}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":59,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":59}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/output.json index e3b406e4daa4..755cd321de4f 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":31,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":31}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":31,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":31}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/output.json index 297a910a329c..dd9fcbf438bf 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":31,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":31}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":31,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":31}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/output.json index d90e701dc4dd..9878d79bcb5c 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":18,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":18}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":18,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":18}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/output.json index 57f62fe4a6b1..8d5530075b12 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":46,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":46}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":46,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":46}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/output.json index 2c33b45a64be..0950c46fe98e 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":38,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":38}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":38,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":38}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/output.json index a2a0ef2bc6b6..34f0d233389b 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":27,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":27}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":27,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":27}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/output.json index e966a43e47ea..5336763b5451 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":33,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":33}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":33,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":33}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/output.json index 6ea4db4a6f24..3a96fb221a6f 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":94,"loc":{"start":{"line":1,"column":9},"end":{"line":7,"column":1}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":94,"loc":{"start":{"line":1,"column":12},"end":{"line":7,"column":1}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/output.json index 215e0119e445..c490e152baab 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":83,"loc":{"start":{"line":1,"column":9},"end":{"line":7,"column":1}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":83,"loc":{"start":{"line":1,"column":12},"end":{"line":7,"column":1}}, diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/output.json index 8493ab87355f..3746c77c6bf9 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":117,"loc":{"start":{"line":1,"column":9},"end":{"line":5,"column":1}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":117,"loc":{"start":{"line":1,"column":12},"end":{"line":5,"column":1}}, @@ -50,12 +51,12 @@ "start":22,"end":26,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":12},"identifierName":"JSON"}, "name": "JSON" }, + "computed": false, "property": { "type": "Identifier", "start":27,"end":32,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":18},"identifierName":"parse"}, "name": "parse" - }, - "computed": false + } }, "arguments": [ { @@ -95,12 +96,12 @@ "start":64,"end":71,"loc":{"start":{"line":3,"column":18},"end":{"line":3,"column":25},"identifierName":"console"}, "name": "console" }, + "computed": false, "property": { "type": "Identifier", "start":72,"end":77,"loc":{"start":{"line":3,"column":26},"end":{"line":3,"column":31},"identifierName":"error"}, "name": "error" - }, - "computed": false + } }, "arguments": [ { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/output.json index 117b71e8c537..428361a1a59a 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":109,"loc":{"start":{"line":1,"column":9},"end":{"line":5,"column":1}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":109,"loc":{"start":{"line":1,"column":12},"end":{"line":5,"column":1}}, @@ -50,12 +51,12 @@ "start":22,"end":26,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":12},"identifierName":"JSON"}, "name": "JSON" }, + "computed": false, "property": { "type": "Identifier", "start":27,"end":32,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":18},"identifierName":"parse"}, "name": "parse" - }, - "computed": false + } }, "arguments": [ { @@ -94,12 +95,12 @@ "start":57,"end":64,"loc":{"start":{"line":3,"column":18},"end":{"line":3,"column":25},"identifierName":"console"}, "name": "console" }, + "computed": false, "property": { "type": "Identifier", "start":65,"end":70,"loc":{"start":{"line":3,"column":26},"end":{"line":3,"column":31},"identifierName":"error"}, "name": "error" - }, - "computed": false + } }, "arguments": [ { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/output.json index 74e0c37287ce..62b6e3d02ec4 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":82,"loc":{"start":{"line":1,"column":9},"end":{"line":4,"column":1}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":82,"loc":{"start":{"line":1,"column":12},"end":{"line":4,"column":1}}, @@ -50,12 +51,12 @@ "start":22,"end":26,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":12},"identifierName":"JSON"}, "name": "JSON" }, + "computed": false, "property": { "type": "Identifier", "start":27,"end":32,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":18},"identifierName":"parse"}, "name": "parse" - }, - "computed": false + } }, "arguments": [ { @@ -94,12 +95,12 @@ "start":57,"end":64,"loc":{"start":{"line":3,"column":18},"end":{"line":3,"column":25},"identifierName":"console"}, "name": "console" }, + "computed": false, "property": { "type": "Identifier", "start":65,"end":70,"loc":{"start":{"line":3,"column":26},"end":{"line":3,"column":31},"identifierName":"error"}, "name": "error" - }, - "computed": false + } }, "arguments": [ { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/output.json index 0e266f4100f6..09127eaf4a11 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/output.json @@ -25,6 +25,7 @@ "expression": { "type": "DoExpression", "start":9,"end":37,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":37}}, + "async": false, "body": { "type": "BlockStatement", "start":12,"end":37,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":37}}, diff --git a/packages/babel-parser/typings/babel-parser.d.ts b/packages/babel-parser/typings/babel-parser.d.ts index 4f22e6656d2b..109dfd3dae63 100644 --- a/packages/babel-parser/typings/babel-parser.d.ts +++ b/packages/babel-parser/typings/babel-parser.d.ts @@ -108,6 +108,7 @@ export interface ParserOptions { } export type ParserPlugin = + | "asyncDoExpressions" | "asyncGenerators" | "bigInt" | "classPrivateMethods" diff --git a/packages/babel-plugin-proposal-do-expressions/src/index.js b/packages/babel-plugin-proposal-do-expressions/src/index.js index 73a322678976..a13a01da6239 100644 --- a/packages/babel-plugin-proposal-do-expressions/src/index.js +++ b/packages/babel-plugin-proposal-do-expressions/src/index.js @@ -11,7 +11,12 @@ export default declare(api => { visitor: { DoExpression: { exit(path) { - const body = path.node.body.body; + const { node } = path; + if (node.async) { + // Async do expressions are not yet supported + return; + } + const body = node.body.body; if (body.length) { path.replaceExpressionWithStatements(body); } else { diff --git a/packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/basic/input.js b/packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/basic/input.js new file mode 100644 index 000000000000..22fca666fa11 --- /dev/null +++ b/packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/basic/input.js @@ -0,0 +1 @@ +(async do {}); diff --git a/packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/basic/output.js b/packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/basic/output.js new file mode 100644 index 000000000000..00ef26d6cb6b --- /dev/null +++ b/packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/basic/output.js @@ -0,0 +1 @@ +async do {}; diff --git a/packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/options.json b/packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/options.json new file mode 100644 index 000000000000..292b6781915b --- /dev/null +++ b/packages/babel-plugin-proposal-do-expressions/test/fixtures/async-do-expressions/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["syntax-async-do-expressions", "proposal-do-expressions"] +} diff --git a/packages/babel-plugin-syntax-async-do-expressions/.npmignore b/packages/babel-plugin-syntax-async-do-expressions/.npmignore new file mode 100644 index 000000000000..f9806945836e --- /dev/null +++ b/packages/babel-plugin-syntax-async-do-expressions/.npmignore @@ -0,0 +1,3 @@ +src +test +*.log diff --git a/packages/babel-plugin-syntax-async-do-expressions/README.md b/packages/babel-plugin-syntax-async-do-expressions/README.md new file mode 100644 index 000000000000..e0b12f824aec --- /dev/null +++ b/packages/babel-plugin-syntax-async-do-expressions/README.md @@ -0,0 +1,19 @@ +# @babel/plugin-syntax-async-do-expressions + +> Allow parsing of async do expressions + +See our website [@babel/plugin-syntax-async-do-expressions](https://babel.dev/docs/en/babel-plugin-syntax-async-do-expressions) for more information. + +## Install + +Using npm: + +```sh +npm install --save-dev @babel/plugin-syntax-async-do-expressions +``` + +or using yarn: + +```sh +yarn add @babel/plugin-syntax-async-do-expressions --dev +``` diff --git a/packages/babel-plugin-syntax-async-do-expressions/package.json b/packages/babel-plugin-syntax-async-do-expressions/package.json new file mode 100644 index 000000000000..36fc479d3e00 --- /dev/null +++ b/packages/babel-plugin-syntax-async-do-expressions/package.json @@ -0,0 +1,31 @@ +{ + "name": "@babel/plugin-syntax-async-do-expressions", + "version": "7.13.0", + "description": "Allow parsing of async do expressions", + "repository": { + "type": "git", + "url": "https://github.com/babel/babel.git", + "directory": "packages/babel-plugin-syntax-async-do-expressions" + }, + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "main": "./lib/index.js", + "exports": { + ".": "./lib/index.js" + }, + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "@babel/helper-plugin-utils": "workspace:^7.12.13" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + }, + "devDependencies": { + "@babel/core": "workspace:*" + }, + "homepage": "https://babel.dev/docs/en/next/babel-plugin-syntax-async-do-expressions" +} diff --git a/packages/babel-plugin-syntax-async-do-expressions/src/index.ts b/packages/babel-plugin-syntax-async-do-expressions/src/index.ts new file mode 100644 index 000000000000..f2805280beae --- /dev/null +++ b/packages/babel-plugin-syntax-async-do-expressions/src/index.ts @@ -0,0 +1,13 @@ +import { declare } from "@babel/helper-plugin-utils"; + +export default declare(api => { + api.assertVersion(7); + + return { + name: "syntax-async-do-expressions", + + manipulateOptions(opts, parserOpts) { + parserOpts.plugins.push("asyncDoExpressions", "doExpressions"); + }, + }; +}); diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index df363a9e857d..d1fb0222285b 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -1591,6 +1591,7 @@ export interface Decorator extends BaseNode { export interface DoExpression extends BaseNode { type: "DoExpression"; body: BlockStatement; + async: boolean; } export interface ExportDefaultSpecifier extends BaseNode { diff --git a/packages/babel-types/src/builders/generated/index.ts b/packages/babel-types/src/builders/generated/index.ts index 2ade18539370..7d44f56788b2 100755 --- a/packages/babel-types/src/builders/generated/index.ts +++ b/packages/babel-types/src/builders/generated/index.ts @@ -1039,7 +1039,10 @@ export function importAttribute( export function decorator(expression: t.Expression): t.Decorator { return builder("Decorator", ...arguments); } -export function doExpression(body: t.BlockStatement): t.DoExpression { +export function doExpression( + body: t.BlockStatement, + async?: boolean, +): t.DoExpression { return builder("DoExpression", ...arguments); } export function exportDefaultSpecifier( diff --git a/packages/babel-types/src/definitions/experimental.ts b/packages/babel-types/src/definitions/experimental.ts index d463bef6c03a..e09dcfab0ef4 100644 --- a/packages/babel-types/src/definitions/experimental.ts +++ b/packages/babel-types/src/definitions/experimental.ts @@ -188,11 +188,16 @@ defineType("Decorator", { defineType("DoExpression", { visitor: ["body"], + builder: ["body", "async"], aliases: ["Expression"], fields: { body: { validate: assertNodeType("BlockStatement"), }, + async: { + validate: assertValueType("boolean"), + default: false, + }, }, }); diff --git a/yarn.lock b/yarn.lock index 605fda1024e0..7d903b4412d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1537,6 +1537,17 @@ __metadata: languageName: unknown linkType: soft +"@babel/plugin-syntax-async-do-expressions@workspace:packages/babel-plugin-syntax-async-do-expressions": + version: 0.0.0-use.local + resolution: "@babel/plugin-syntax-async-do-expressions@workspace:packages/babel-plugin-syntax-async-do-expressions" + dependencies: + "@babel/core": "workspace:*" + "@babel/helper-plugin-utils": "workspace:^7.12.13" + peerDependencies: + "@babel/core": ^7.0.0-0 + languageName: unknown + linkType: soft + "@babel/plugin-syntax-async-generators@npm:^7.8.0, @babel/plugin-syntax-async-generators@npm:^7.8.4": version: 7.8.4 resolution: "@babel/plugin-syntax-async-generators@npm:7.8.4"