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
This commit is contained in:
Huáng Jùnliàng
2021-04-07 12:24:33 -04:00
committed by Nicolò Ribaudo
parent f30c99aa24
commit 28d7442aae
76 changed files with 897 additions and 23 deletions

View File

@@ -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 {

View File

@@ -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(

View File

@@ -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,
},
},
});