-
Notifications
You must be signed in to change notification settings - Fork 11
Using async generator methods leads to syntax errors #33
Copy link
Copy link
Open
Description
My application code contains some async generator methods, e.g.:
export default {
async *generator(param) { /* ... */ }
}
The bundled code is valid and the application starts correctly. However, when running the TestCafe tests, I get a SyntaxError: Unexpected reserved word because the async keyword has been dropped. The reason is that async methods and generator methods are treated as mutually exclusive here and here. To make the TestCafe tests run, I had to patch this library as follows:
diff --git a/node_modules/esotope-hammerhead/esotope.js b/node_modules/esotope-hammerhead/esotope.js
index f8f4a37..dea67f9 100644
--- a/node_modules/esotope-hammerhead/esotope.js
+++ b/node_modules/esotope-hammerhead/esotope.js
@@ -1481,7 +1481,9 @@ var ExprRawGen = {
}
else {
- if ($expr.value.generator)
+ if ($expr.value.generator && $expr.value.async)
+ _.js += exprJs + 'async *' + keyJs;
+ else if ($expr.value.generator)
_.js += exprJs + '*' + keyJs;
else if ($expr.value.async)
_.js += exprJs + 'async ' + keyJs;
@@ -1510,7 +1512,9 @@ var ExprRawGen = {
_.js += keyJs;
else if ($expr.method) {
- if ($val.generator)
+ if ($val.generator && $val.async)
+ keyJs = 'async *' + keyJs;
+ else if ($val.generator)
keyJs = '*' + keyJs;
else if ($val.async)
keyJs = 'async ' + keyJs;Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels