Skip to content

[AssetMapper] Improve import statements extraction #54134

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 2 commits into from

Conversation

smnandre
Copy link
Member

@smnandre smnandre commented Mar 2, 2024

Q A
Branch? 7.1
Bug fix? no
New feature? no
Deprecations? no
Issues Fix #
License MIT

This PR introduce a tiny JS parser responsible to split the code into distinct parts:

  • default (code)
  • comments
  • enclosed strings

By parsing step by step, only analysing what's necessary in parallel of the preg_replace_callback, it may ease the Compiler choice to keep or not an import statement.

This also allow us to use a lighter regexp, avoiding any JIT trouble.

It was just a game/test at first, but as it seem to work really well, let's open the discussion :)

(poke @nicolas-grekas @weaverryan)

This PR introduce a tiny JS parser responsible to split the code into distinct parts:
* default (code)
* comments
* enclosed strings

By parsing step by step, only analysing what's necessary in parallel of the preg_replace_callback, it may ease the Compiler choice to keep or not an import statement.

This also allow us to use a lighter regexp, avoiding any JIT trouble.

It was just a game/test at first, but as it seem to work really well, let's open the discussion :)
@smnandre
Copy link
Member Author

smnandre commented Mar 8, 2024

Friendly ping @weaverryan @nicolas-grekas ? It makes the import collection a lot "safer" to me... but there may be downsides i don"t see

@nicolas-grekas
Copy link
Member

I like that but I'm wondering if we shouldn't put this on-hold (aka close for now) until we have a real need for that? Maybe the current regexp is good enough?

@smnandre
Copy link
Member Author

@nicolas-grekas : works for me, it's there if we need it later :)

@smnandre smnandre closed this Mar 18, 2024
smnandre added a commit to smnandre/symfony that referenced this pull request Nov 26, 2024
smnandre added a commit to smnandre/symfony that referenced this pull request Nov 27, 2024
Third attempt after symfony#54134 and symfony#58999.. this is the good one.

I initially started this PR to learn / try things, but it really behaves well.. and _may_
stop (or help stopping) what seems to be a never-ending suite of special cases.

Open to any feedback
smnandre added a commit to smnandre/symfony that referenced this pull request Jan 19, 2025
Third attempt after symfony#54134 and symfony#58999.. this is the good one.

I initially started this PR to learn / try things, but it really behaves well.. and _may_
stop (or help stopping) what seems to be a never-ending suite of special cases.

Open to any feedback
fabpot added a commit that referenced this pull request Jan 25, 2025
…nandre)

This PR was squashed before being merged into the 7.3 branch.

Discussion
----------

[AssetMapper] Detect import with a sequence parser

| Q             | A
| ------------- | ---
| Branch?       | 7.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #58928  and #58944  (maybe)
| License       | MIT

Third attempt after #54134 and #58999.. this is the good one 👍

I initially started this PR to learn / try things, but it really behaves well.. and _may_ stop (or help stopping) what seems to be a never-ending suite of special cases.

Open to any feedback

Commits
-------

720c387 [AssetMapper] Detect import with a sequence parser
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.

3 participants