Skip to content

Using async generator methods leads to syntax errors #33

@thomas-jakemeyn

Description

@thomas-jakemeyn

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions