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

Appearance settings

[AssetMapper] Circular reference error because IMPORT_PATTERN regexp matches comments as well #51291

Copy link
Copy link
Closed
@mhitza

Description

@mhitza
Issue body actions

Symfony version(s) affected

6.3.2

Description

I'm trying to integrate AssetMapper within one of my projects, and I'm stuck because I get a circular reference error.

In MappedAssetFactory.php line 39:
                                                                                                 
  Circular reference detected while creating asset for "js/htmx.js": "js/htmx.js -> js/htmx.js"

How to reproduce

The issue shows with htmx.js library, as it has the following style of comments within the code:

/**
 *
 * @param {HTMLElement} elt
 * @param {string} swapInfoOverride
 * @returns {import("./htmx").HtmxSwapSpecification}
 */
function getSwapSpecification(elt, swapInfoOverride) {

The import syntax within the return annotations trips up the import pattern regexp causing a false positive when checking for circular references.

Possible Solution

Short of writing/integratng a proper javascript parser, the only quicker workaround I can think of right now would be to use the PREG_OFFSET_CAPTURE flag for the replace regexp in JavaScriptImportPathCompiler.php, and use that offset information to slice a context around the position in order to deduce if the the match is within a comment or string (?) context (requiering the implementation of these two type of parsers).

Additional Context

As a workaround, if it is useful for other users landing on this issue, I have written a small js script to strip out all the comments from a JavaScript file https://gist.github.com/mhitza/ddc8326e1c94094bdab762e6171e459a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.