Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[AssetMapper] Ignore comment lines in JavaScriptImportPathCompiler#53893

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.4fromsmnandre:fix/js-compiler-regexp
Feb 11, 2024

Conversation

smnandre
Copy link
Member

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix#53849
LicenseMIT

The following code was wrongly treated asone line of comment

// importimport"foo.js"

This PR updates the regexp to ignore comment lines (andfix#53849)

Also added a comment explaining how the regexp works for future maintenance.

Copy link
Member

@weaverryanweaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Very complex regex, as expected :). We’re living by the tests on this by necessity. Thanks for fixing this!

smnandre and asrorbekh reacted with laugh emoji
*
* @see https://regex101.com/r/1iBAIb/1
*/
private const IMPORT_PATTERN = '/^(?:\/\/.*)|(?:\'(?:[^\'\\\\]|\\\\.)*\'|"(?:[^"\\\\]|\\\\.)*")|(?:import\s*(?:(?:\*\s*as\s+\w+|\s+[\w\s{},*]+)\s*from\s*)?|\bimport\()\s*[\'"`](\.\/[^\'"`]+|(\.\.\/)*[^\'"`]+)[\'"`]\s*[;\)]?/m';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We can probably inline the comments directly in the regex (and add some spaces/new lines) to make the regex more easily understandable by using/ms.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is that better... or a bit too much ?

privateconstIMPORT_PATTERN ='/    ^        (?:\/\/.*)                     # Lines that start with comments    |        (?:\'(?:[^\'\\\\]|\\\\.)*\'   # Strings enclosed in single quotes        |            "(?:[^"\\\\]|\\\\.)*"      # Strings enclosed in double quotes        )    |        (?:                            # Import statements (script captured)            import\s*                (?:                    (?:\*\s*as\s+\w+|\s+[\w\s{},*]+)                    \s*from\s*                )?        |            \bimport\(        )        \s*[\'"`](\.\/[^\'"`]+|(\.\.\/)*[^\'"`]+)[\'"`]\s*[;\)]    ?/mx';

Copy link
Contributor

@AurelienPillevesseAurelienPillevesseFeb 10, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Another solution can be :

privateconstPATTERN_LINES_START_WITH_COMMENTS ='(?:\/\/.*)';privateconstPATTERN_STRINGS_ENCLOSED_SINGLE_OR_DOUBLE_QUOTES ='(?:\'(?:[^\'\\\\]|\\\\.)*\'   # Strings enclosed in single quotes        |            "(?:[^"\\\\]|\\\\.)*"      # Strings enclosed in double quotes        )';// ...

And you concat everything in theIMPORT_PATTERN. What do you think about it ?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I genuinely have no opinion here, just happy if the next person to work with this pattern does not lose time to understand why and how we made this regexp :) So you guys tell me

@fabpot
Copy link
Member

Thank you@smnandre.

@fabpotfabpot merged commitca8c10d intosymfony:6.4Feb 11, 2024
This was referencedFeb 27, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AurelienPillevesseAurelienPillevesseAurelienPillevesse left review comments

@fabpotfabpotfabpot approved these changes

@weaverryanweaverryanweaverryan approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

5 participants
@smnandre@fabpot@weaverryan@AurelienPillevesse@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp