diff --git a/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php b/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php index 25508d3422c7b..576e056d29ed8 100644 --- a/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php +++ b/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php @@ -172,7 +172,12 @@ private function findAssetForRelativeImport(string $importedModule, MappedAsset return null; } - $dependentAsset = $assetMapper->getAsset($resolvedSourcePath); + try { + $dependentAsset = $assetMapper->getAssetFromSourcePath($resolvedSourcePath); + } catch (CircularAssetsException $exception) { + $dependentAsset = $exception->getIncompleteMappedAsset(); + } + if ($dependentAsset) { return $dependentAsset; } diff --git a/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php b/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php index 8b8cfe3801c83..e7415def4eea6 100644 --- a/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php +++ b/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php @@ -173,7 +173,6 @@ public static function provideCompileTests(): iterable ]; yield 'importing_non_existent_file_without_strict_mode_is_ignored_and_no_import_added' => [ - 'sourceLogicalName' => 'app.js', 'input' => "import './non-existent.js';", 'expectedJavaScriptImports' => [], ]; @@ -277,7 +276,6 @@ public static function provideCompileTests(): iterable ]; yield 'absolute_import_ignored_and_no_dependency_added' => [ - 'sourceLogicalName' => 'app.js', 'input' => 'import "https://example.com/module.js";', 'expectedJavaScriptImports' => [], ]; @@ -415,14 +413,14 @@ public static function providePathsCanUpdateTests(): iterable public function testCompileHandlesCircularRelativeAssets() { - $appAsset = new MappedAsset('app.js', 'anythingapp', '/assets/app.js'); - $otherAsset = new MappedAsset('other.js', 'anythingother', '/assets/other.js'); + $appAsset = new MappedAsset('app.js', '/project/assets/app.js', '/assets/app.js'); + $otherAsset = new MappedAsset('other.js', '/project/assets/other.js', '/assets/other.js'); $importMapConfigReader = $this->createMock(ImportMapConfigReader::class); $assetMapper = $this->createMock(AssetMapperInterface::class); $assetMapper->expects($this->once()) - ->method('getAsset') - ->with('other.js') + ->method('getAssetFromSourcePath') + ->with('/project/assets/other.js') ->willThrowException(new CircularAssetsException($otherAsset)); $compiler = new JavaScriptImportPathCompiler($importMapConfigReader);