Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async function declaration gets stripped #58

Closed
catch56 opened this issue Jul 15, 2023 · 3 comments
Closed

async function declaration gets stripped #58

catch56 opened this issue Jul 15, 2023 · 3 comments

Comments

@catch56
Copy link

catch56 commented Jul 15, 2023

There seems to be an issue parsing async function declarations, couldn't find an existing or old issue about this.

Given:

Foo = {
  async bar() {},
  baz: async () => {},
}

Run through:

$ast = Peast::latest($data)->parse();
$renderer = new Renderer();
$renderer->setFormatter(new CompactFormatter());
print $renderer->render($ast);

You would expect:

Foo={async bar(){},baz:async()=>{}};

But instead you get:

Foo={bar(){},baz:async()=>{}};

Steps to reproduce aren't mine, just copying from: https://www.drupal.org/project/drupal/issues/3374660

@Niklan
Copy link

Niklan commented Jul 15, 2023

We faced this on the project with AlpineJS. Basically, code was something like:

Alpine.data('foo', () => ({
  async bar() {
    await Baz.bar();
  }
}))

This worked fine until Drupal 10.1 update, which introduced Peast as JS optimizer.

We updated our code to be:

Alpine.data('foo', () => ({
  bar: async () => {
    await Baz.bar();
  }
}))

This solves the problem, but seems like a bug, because the first example is also a valid JS syntax. Peast removes async from bar() and browser fails with await notation without async for function.

Maybe this information will be more helpful with an exact problem, rather than synthetic from a test.

@mck89 mck89 closed this as completed in 07d82a2 Jul 15, 2023
@mck89
Copy link
Owner

mck89 commented Jul 15, 2023

Fixed, i forgot to handle the async keyword when rendering objects methods. Thank you for reporting.

@catch56
Copy link
Author

catch56 commented Jul 15, 2023

Thanks for the quick response and release! We'll try to get this into the next patch version of Drupal core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants