Fix preserving CSS custom properties during minification
This commit is contained in:
@@ -592,6 +592,12 @@ class CssVariablesMinifierPlugin extends aCssMinifierPlugin
|
||||
for ($i = 0, $l = count($m[0]); $i < $l; $i++)
|
||||
{
|
||||
$variable = trim($m[1][$i]);
|
||||
// Native CSS custom properties are resolved by the browser and must
|
||||
// not be treated as variables from CssMin's @variables syntax.
|
||||
if (substr($variable, 0, 2) === "--")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach ($mediaTypes as $mediaType)
|
||||
{
|
||||
if (isset($this->variables[$mediaType], $this->variables[$mediaType][$variable]))
|
||||
|
||||
35
tests/Unit/CssMinTest.php
Normal file
35
tests/Unit/CssMinTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CssMinTest extends TestCase
|
||||
{
|
||||
public function testNativeCssCustomPropertiesArePreserved()
|
||||
{
|
||||
$css = ':root { --sidebar-width: 360px; } .sidebar { width: var(--sidebar-width); }';
|
||||
|
||||
$this->assertSame(
|
||||
':root{--sidebar-width:360px}.sidebar{width:var(--sidebar-width)}',
|
||||
\CssMin::minify($css)
|
||||
);
|
||||
}
|
||||
|
||||
public function testNativeCssCustomPropertiesInsideClampArePreserved()
|
||||
{
|
||||
$css = '.sidebar { width: clamp(280px, 25vw, var(--sidebar-width)); }';
|
||||
|
||||
$this->assertSame(
|
||||
'.sidebar{width:clamp(280px, 25vw, var(--sidebar-width))}',
|
||||
\CssMin::minify($css)
|
||||
);
|
||||
}
|
||||
|
||||
public function testLegacyCssMinVariablesAreStillResolved()
|
||||
{
|
||||
$css = '@variables { sidebarWidth: 360px; } .sidebar { width: var(sidebarWidth); }';
|
||||
|
||||
$this->assertSame('.sidebar{width:360px}', \CssMin::minify($css));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user