Skip to content

Usage of variable in calc(..) statements result in a non working variable reference #7

@yannicklamprecht

Description

@yannicklamprecht

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'}"));
    }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions