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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
return $fullImportString;
}

// Ignore self-referencing import
if ($dependentAsset->logicalPath === $asset->logicalPath) {
return $fullImportString;
}

// List as a JavaScript import.
// This will cause the asset to be included in the importmap (for relative imports)
// and will be used to generate the preloads in the importmap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,34 @@ public function testCompileHandlesCircularBareImportAssets()
$this->assertSame($popperAsset->logicalPath, $bootstrapAsset->getJavaScriptImports()[0]->assetLogicalPath);
}

public function testCompileIgnoresSelfReferencingBareImportAssets()
{
$bootstrapAsset = new MappedAsset('foo.js', 'foo.js', 'foo.js');

$importMapConfigReader = $this->createMock(ImportMapConfigReader::class);
$importMapConfigReader->expects($this->once())
->method('findRootImportMapEntry')
->with('foobar')
->willReturn(ImportMapEntry::createRemote('foobar', ImportMapType::JS, 'foo.js', '1.2.3', 'foobar', false));
$importMapConfigReader->expects($this->any())
->method('convertPathToFilesystemPath')
->with('foo.js')
->willReturn('foo.js');

$assetMapper = $this->createMock(AssetMapperInterface::class);
$assetMapper->expects($this->once())
->method('getAssetFromSourcePath')
->with('foo.js')
->willReturn($bootstrapAsset);

$compiler = new JavaScriptImportPathCompiler($importMapConfigReader);
$input = 'import { foo } from "foobar";';
$compiler->compile($input, $bootstrapAsset, $assetMapper);
$this->assertCount(0, $bootstrapAsset->getDependencies());
$this->assertCount(0, $bootstrapAsset->getFileDependencies());
$this->assertCount(0, $bootstrapAsset->getJavaScriptImports());
}

/**
* @dataProvider provideMissingImportModeTests
*/
Expand Down