Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[AssetMapper] Revert "Fix JavaScript compiler load imports from JS strings" #54012

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

Closed
wants to merge 1 commit into from

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

This reverts commit 4fe7828, reversing changes made to ad1563b.

Reverts #53652 because it breaks loading app.css on a webapp skeleton.
There are two reasons for this:

  1. the string regexp generates a JIT stack overflow - this can be fixed by making the internal pattern greedy
  2. but then it still fails because app.js uses import './styles/app.css' and this is matched by the "quoted strings" subpart of the current pattern and thus ignored by the "import" subpart.

I don't know how this would be fixed using the regexp only so I'm proposing to revert so that we can consider this before the next release.

/cc @smnandre and @weaverryan

I'm wondering what's the plan on this topic? Couldn't the CDN we use provide some API endpoint that'd prevent us from parsing any JS? Is there any effort ongoing on the topic? Alternatively, shouldn't we switch to a regexp-less parser? (a small state machine that'd be able to split apart comments, strings and code)?

…imports from JS strings (smnandre)"

This reverts commit 4fe7828, reversing
changes made to ad1563b.
@weaverryan
Copy link
Member

Dang :/

Couldn't the CDN we use provide some API endpoint that'd prevent us from parsing any JS? Is there any effort ongoing on the topic?

I think you may be mixing this up with the other spot in JsDelivrEsmResolver where we parse the code from the CDN. Here's the issue about that - jsdelivr/jsdelivr#18538 - no public movement. But as they will ultimately give us a finite number of import synaxes, I believe that situation is solveable with regex.

Alternatively, shouldn't we switch to a regexp-less parser? (a small state machine that'd be able to split apart comments, strings and code)?

In this situation, we're dealing with userland code, which could look like anything. This was always going to be tricky to do perfectly without actually parsing the JS... my hope was to get it 99.5% correct (which I think we have). For that last 0.5%, I'm not sure. Can we make something to get to 99.999%? Or do we need to provide an "escape hatch" where the user can define special situations where over-matching import statements (e.g. because they are inside a console.log('import ...')) that should be ignored?

@smnandre
Copy link
Member

This could fix the regexp:

https://regex101.com/r/jtTZUA/1

(not handling multi-line enquoted string ... as that does not exist in JS)

@smnandre
Copy link
Member

smnandre commented Feb 20, 2024

Alternative: i opened #54014 (should fix this bug)

@nicolas-grekas
Copy link
Member Author

Closing in favor of #54014 then :)

@nicolas-grekas nicolas-grekas deleted the am-revert branch February 20, 2024 18:10
fabpot added a commit that referenced this pull request Feb 21, 2024
This PR was squashed before being merged into the 6.4 branch.

Discussion
----------

[AssetMapper] Fix enquoted string pattern

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54012
| License       | MIT

Alternative to #54012 (fixes the bug and avoid a revert that will reintroduce other previous bugs / missmatches)

+ add a test to check things work as expected with the standard `app.js` file

cc `@weaverryan` `@nicolas`-grekas

Commits
-------

df618bd [AssetMapper] Fix enquoted string pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants