A variable used in a calc statement is compressed into a non usable reference.
Instead of calc(50% - (0.5 * var(--test-value))) the result is calc(50% - (0.5 * var(- - test-value))).
Further information and test cases below.
Working compression using variable without further statements.
@Test
public void testVariable() throws Exception {
String input = "body { --test-value: red; \n color: var(--test-value);}";
CssCompressor compressor = new CssCompressor(new StringReader(input));
compressor.compress(output, -1);
String result = output.toString();
assertTrue("Should preserve variable", result.contains("body{--test-value:red;color:var(--test-value)}"));
}
This test fails as the variable usage get spaced to much.
Instead of the below Test snippet we get result body{--test-value:10px;grid-template-columns:calc(50% - (0.5 * var(- - test-value))) 1fr}
@Test
public void testVariableInCalc() throws Exception {
String input = "body { --test-value: 10px; \n grid-template-columns: calc(50% - (0.5 * var(--test-value))) 1fr';}";
CssCompressor compressor = new CssCompressor(new StringReader(input));
compressor.compress(output, -1);
String result = output.toString();
assertTrue("Should preserve variable", result.contains("body{--test-value:10px;grid-template-columns:calc(50% - (0.5 * var(--test-value))) 1fr'}"));
}
}
A variable used in a calc statement is compressed into a non usable reference.
Instead of
calc(50% - (0.5 * var(--test-value)))the result iscalc(50% - (0.5 * var(- - test-value))).Further information and test cases below.
Working compression using variable without further statements.
This test fails as the variable usage get spaced to much.
Instead of the below Test snippet we get result
body{--test-value:10px;grid-template-columns:calc(50% - (0.5 * var(- - test-value))) 1fr}