Huáng Jùnliàng 28d7442aae 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
2021-04-28 18:26:01 +02:00

30 lines
730 B
JavaScript

import { declare } from "@babel/helper-plugin-utils";
import syntaxDoExpressions from "@babel/plugin-syntax-do-expressions";
export default declare(api => {
api.assertVersion(7);
return {
name: "proposal-do-expressions",
inherits: syntaxDoExpressions,
visitor: {
DoExpression: {
exit(path) {
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 {
path.replaceWith(path.scope.buildUndefinedNode());
}
},
},
},
};
});