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

Commit 33855da

Browse filesBrowse files
ousamabenyounesnicolas-grekas
authored andcommitted
[AssetMapper] Render an empty import map as a JSON object
1 parent 6ae13cf commit 33855da
Copy full SHA for 33855da

2 files changed

+16-1Lines changed: 16 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Symfony/Component/AssetMapper/ImportMap/ImportMapRenderer.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/ImportMap/ImportMapRenderer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function render(string|array $entryPoint, array $attributes = []): string
9696
}
9797

9898
$scriptAttributes = $this->createAttributesString($attributes);
99-
$importMapJson = json_encode(['imports' => $importMap], \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_HEX_TAG);
99+
$importMapJson = json_encode(['imports' => $importMap ?: new \stdClass()], \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_HEX_TAG);
100100
$output .= <<<HTML
101101
102102
<script type="importmap"$scriptAttributes>
Collapse file

‎src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapRendererTest.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapRendererTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,19 @@ public function testItAddsPreloadLinks()
204204
$this->assertSame(['as' => 'style'], $linkProvider->getLinks()[0]->getAttributes());
205205
$this->assertSame('/assets/styles/app-preload-d1g35t.css', $linkProvider->getLinks()[0]->getHref());
206206
}
207+
208+
public function testEmptyImportMapRendersAsJsonObject()
209+
{
210+
$importMapGenerator = $this->createMock(ImportMapGenerator::class);
211+
$importMapGenerator->expects($this->once())
212+
->method('getImportMapData')
213+
->with([])
214+
->willReturn([]);
215+
216+
$renderer = new ImportMapRenderer($importMapGenerator);
217+
$html = $renderer->render([]);
218+
219+
$this->assertStringContainsString('"imports": {}', $html);
220+
$this->assertStringNotContainsString('"imports": []', $html);
221+
}
207222
}

0 commit comments

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