Problem/Motivation

Drupal's core dependency mck89/peast have a bug which was fixed in 1.15.2. This affects Drupal JsOptimizer which is used for JavaScript aggregation and optimization. Before that version async functions were compressed without async keyword which break aggregated JS file completely if such function rely on that (e.g. use await).

Upstream issue https://github.com/mck89/peast/issues/58

Steps to reproduce

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

Expects to be Foo={async bar(){},baz:async()=>{}}; but Foo={bar(){},baz:async()=>{}}; provided.

bar() lost its async prefix and any await inside will lead to JS error and break aggregated JS file completely.

Proposed resolution

This was fixed in 1.15.2 version. We need to udpate dependency for Drupal core.

Comments

Niklan created an issue. See original summary.

niklan’s picture

StatusFileSize
new1.37 KB
catch’s picture

That is probably a bug in Peast https://github.com/mck89/peast

edit: posted an upstream report https://github.com/mck89/peast/issues/58

niklan’s picture

Title: JsOptimizer removes 'async' from functions and break JavaScript » Update mck89/peast composer dependency to 1.15.2
Component: asset library system » composer
Category: Bug report » Task
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new3.48 KB

Seems like it was fixed and available in Peast 1.15.2 release. So I think we have to update this issue to reflect that.

Not sure if we should keep provided test, because it tests third-party library, actually.

P.s. I'm not certain about bumping minimal version, but it sounds reasonable, because otherwise it can break aggregation.

andypost’s picture

Component: composer » javascript
Category: Task » Bug report
Issue summary: View changes

Can you add a unit test to prevent regressions in future, that's a bug

chi’s picture

I think there is no need to create tests for third party packages. If this functionality is critical it's better to submit the test to upstream project.

spokje’s picture

Category: Bug report » Task
Status: Needs review » Reviewed & tested by the community

I agree with @Chi on this one (sorry @andypost), let's see what core committers think.

catch’s picture

Peast added their own test coverage so I think it's very unlikely to regress.

What we could maybe do if we wanted to would be to change the content of another existing test file for that test class, to include the syntax here (since they don't have any particular syntax in, just whitespace to strip) - then we'd be covering this bug without actually adding more tests to maintain overall.

I will aim to commit this early next week either way so that it definitely lands in the next patch release. Very good find and also extremely encouraging that Peast fixed it within half a day of us opening the issue.

  • catch committed bf041f4c on 10.1.x
    Issue #3374660 by Niklan, catch, andypost, Chi, Spokje: Update mck89/...

  • catch committed 8f2d25b6 on 11.x
    Issue #3374660 by Niklan, catch, andypost, Chi, Spokje: Update mck89/...
spokje’s picture

@catch: Could it be that this issue, due to the new non-auto-checkbox-for-credit-checking on d.o. doesn't have the credits which you would expect from reading the commit message?

I really don't need the credit, but I feel at the very least Niklan should get one for reporting the issue here, writing a fail test and commenting on the peast issue in their queue.

INSTA-EDIT: Hmm, might also be credit-less because it's not marked as fixed yet?

catch’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new2.41 KB

The MR diff didn't cleanly apply to 11.x, I also noticed that it increased the minimum Peast version in composer.json.

So I did the update locally - Peast still updated to the latest version, but without the composer.json change.

Committed/pushed to 11.x and cherry-picked to 10.1.x, thanks!

edit: yes I was waiting for commits to push and writing the comment etc. credited everyone because the test-or-not discussion was useful for deciding that we really didn't need our own test and had thought about it enough.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.