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 93ed711c5c..81199e7d0d 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 160ca32995..83724709a8 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 3f7019a82e..0da40cc08e 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 0000000000..54b0a1353b --- /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 0000000000..aa91c74fb0 --- /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 0000000000..94fd7ea361 --- /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 0000000000..26a551e14e --- /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 0000000000..97925bbcb6 --- /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 0000000000..640c3d9845 --- /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 48d37a300e..0e005fd229 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 27d699e825..3da6f2d991 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 777ee42b20..194bc1aa74 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 fa716fd62f..6a890ac8f4 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 0000000000..214ceb1386 --- /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 0000000000..082c82b3ae --- /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 0000000000..214ceb1386 --- /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 0000000000..5af0fa0b53 --- /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 0000000000..64f17ab55b --- /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 0000000000..0958732d49 --- /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 0000000000..1b0cef3906 --- /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 0000000000..484a2b5ee5 --- /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 0000000000..63e7b8867e --- /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 0000000000..21fdf1bc4b --- /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 0000000000..77dd5e7da6 --- /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 0000000000..b6d30323e4 --- /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 0000000000..82c96b93e3 --- /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 0000000000..a9b0e3f498 --- /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 0000000000..3019c2ff7a --- /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 0000000000..ff10d08731 --- /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 0000000000..c5f2e4fc00 --- /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 0000000000..3d6b9e7153 --- /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 0000000000..87c41a048d --- /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 0000000000..9f66131f91 --- /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 0000000000..9da4a4a2bf --- /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 0000000000..e3a6917152 --- /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 0000000000..b2fb42c337 --- /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 3f5de76a0e..aa5f8bfc91 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 ea87774559..abf839ec45 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 e3935122a5..cff7b87dc7 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 3363e00e6d..cce77f778a 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 e77303e8aa..cccbb6ee67 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 b593175700..30756decb9 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 1093dabf11..9c483cd137 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 7f5b97a418..4241e8133c 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 344da50b5d..fe3ce80ecf 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}}, 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 e36e609e28..bf6ede1d56 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 b12167e9c6..7caf81f88f 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 0321177a10..219ca99243 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 aebaee1b7d..2832b644d7 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 a6331818eb..eeba925617 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 e3b406e4da..755cd321de 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 297a910a32..dd9fcbf438 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 d90e701dc4..9878d79bcb 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 57f62fe4a6..8d5530075b 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 2c33b45a64..0950c46fe9 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 a2a0ef2bc6..34f0d23338 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 e966a43e47..5336763b54 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 6ea4db4a6f..3a96fb221a 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 215e0119e4..c490e152ba 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 8493ab8735..3746c77c6b 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 117b71e8c5..428361a1a5 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 74e0c37287..62b6e3d02e 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 0e266f4100..09127eaf4a 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 4f22e6656d..109dfd3dae 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 73a3226789..a13a01da62 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 0000000000..22fca666fa --- /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 0000000000..00ef26d6cb --- /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 0000000000..292b678191 --- /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 0000000000..f980694583 --- /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 0000000000..e0b12f824a --- /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 0000000000..36fc479d3e --- /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 0000000000..f2805280be --- /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 3476f1c2a0..3094bdb713 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -1609,6 +1609,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 68c33b7205..d4407bb618 100755 --- a/packages/babel-types/src/builders/generated/index.ts +++ b/packages/babel-types/src/builders/generated/index.ts @@ -1051,7 +1051,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 d463bef6c0..e09dcfab0e 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 e08ed1afd7..a4cf916dbc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1512,6 +1512,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.4": version: 7.8.4 resolution: "@babel/plugin-syntax-async-generators@npm:7.8.4"