Skip to content

YUI Compressor is breaking some CSS, specifically calc(100% + ##px) #59

Closed

Description

@djgilcrease
.issue-59 {
    width:100%;
    width: -webkit-calc(100% + 30px);
    width: -moz-calc(100% + 30px);
    width: calc(100% + 30px);
}

turns into
.issue-59{width:100%;width:-webkit-calc(100%+30px);width:-moz-calc(100%+30px);width:calc(100%+30px)}

instead of

.issue-59{width:100%;width:-webkit-calc(100% + 30px);width:-moz-calc(100% + 30px);width:calc(100% + 30px)}

Notice the missing spaces

Activity

  1. ghost assigned on Mar 31, 2013
  2. tml commented on Mar 31, 2013

    @tml
    Contributor

    calc() is specifically called out as "at risk of being dropped during the CR period", but we should probably still address this one, as the blasted spec does - in fact - require at least one whitespace character around + and - operators.

  3. filipewl commented on Apr 4, 2013

    @filipewl

    I'm having exactly the same problem. I'm using Jammit to compress the CSS for production and my calc() expressions are breaking because the compressor is removing, sometimes, spaces before and after operators and parenthesis.

    Examples:
    Original: calc(100% * 2 + 20px * (2 - 1))
    Compressed: calc(100% * 2+20px *(2 - 1))

    Does anybody know a workaround for this? I see no other option but to exclude this part of the CSS from Jammit's pipeline.

  4. alfredxing commented on May 12, 2013

    @alfredxing

    I'm having the same issue. Although calc is considered "experimental", it's a great tool to use (and it does work with major browsers).
    It would be great to have this fixed; I can't seem to find a workaround.

  5. yetithefoot commented on Jul 4, 2013

    @yetithefoot

    Same here! Vote for this!

  6. DanFinchUK commented on Jul 4, 2013

    @DanFinchUK

    Me too.

  7. kmxz commented on Aug 7, 2013

    @kmxz

    Same problem troubled me

  8. kris-o3 commented on Sep 3, 2013

    @kris-o3
    background-position: calc(65% - (100px - 350px * 0.65)) 0;
    

    gets compressed as:

    background-position:calc(65% -(100px - 350px * .65)) 0;
    

    i currently have to add a space after the - before the inner expression.
    like so:

    background-position:calc(65% - (100px - 350px * .65)) 0;
    

    i have to do this every time i commit css-related changes.
    it is making me very sad indeed.

  9. eaoliver commented on Sep 28, 2013

    @eaoliver

    Has there been any progress on this bug? It's maddening. Nested expressions are still being compressed, which breaks the calc function under Safari and Firefox. It works under Chrome.

    Example: (source calcs had spaces been operations)

    left: -moz-calc((100% - 106px)/2+64px);
    left: -webkit-calc((100% - 106px)/2+64px);
    left: calc((100% - 106px)/2+64px);

  10. kris-o3 commented on Sep 30, 2013

    @kris-o3

    i attempted to locate which of the many regex's might need tweaking for this but was caught up in the muck and mire of a very long if( ) statement indeed... surely someone who worked on it or familiar with it can have a look?

  11. djgilcrease commented on Sep 30, 2013

    @djgilcrease
    ContributorAuthor

    We had fixed this in our local version, I just forgot to commit it back for upstream pull request #107

  12. kris-o3 commented on Sep 30, 2013

    @kris-o3

    great! let us know when the merge has been approved / is complete?

  13. tml commented on Sep 30, 2013

    @tml
    Contributor

    The PR breaks the build, but it's a huge step forward. Thanks, @djgilcrease!

  14. djgilcrease commented on Sep 30, 2013

    @djgilcrease
    ContributorAuthor

    How does it break the build? I was able to run the ant build and all the tests that were passing before changes were still passing.

  15. tml commented on Sep 30, 2013

    @tml
    Contributor

    See the Travis status on #107

    Or just check the build: https://travis-ci.org/yui/yuicompressor/builds/11968385

  16. 58 remaining items

  17. sunnybear commented on Apr 18, 2018

    @sunnybear

    Any news on this? YUI Compressor breaks CSS calc for 5 years!

  18. himanshuwt commented on Apr 18, 2018

    @himanshuwt

    @sunnybear agree with you. 5 years done. And, still I faced the issue "+" then again i replace it with calc(x - - y). :D

  19. sunnybear commented on Apr 18, 2018

    @sunnybear

    Does anybody have a list of issues with calc? We've faced with
    100% + 6px -> 100%+px
    100% - (10% * 6) -> 100% -(10% * 6)
    It seems also
    (100vw - 40px) * .73) + 40px -> (100vw - 40px) * .73)+ 40px

  20. MarjanAshofteh commented on Jun 4, 2018

    @MarjanAshofteh

    @beaktor
    using two - beside + works for me too.
    thanks

  21. ramarro123 commented on Nov 15, 2018

    @ramarro123

    it's yui compressor still mantained?

  22. DrLightman commented on Nov 28, 2019

    @DrLightman

    Using YuiCompressor 2.4.8 and the bug is still on.

  23. frangarcia commented on Jun 4, 2020

    @frangarcia

    This version, https://mvnrepository.com/artifact/com.yahoo.platform.yui/yuicompressor/2.4.9-BSI-2, seems to have fixed the problem. I followed the examples @svaponi added using this file

    body{
    	font-size: calc(50% - 3px);
    	font-size: calc(50% + 3px);
    	font-size: calc(50% + +3px);
    	font-size: calc((50%) + (3px));
    	font-size: calc(50% + (+3px));
    	font-size: calc(50% + (3px));
    	font-size: calc(50% - (-3px));
    	font-size: calc(50% - -3px);
    }
    

    and when running this command:

    java -jar yuicompressor-2.4.9-BSI-2.jar --line-break 0 -o process.css.min file.css

    this output was generated:

    body{font-size:calc(50% - 3px);font-size:calc(50% + 3px);font-size:calc(50% + +3px);font-size:calc((50%)+(3px));font-size:calc(50% + (+3px));font-size:calc(50% + (3px));font-size:calc(50% - (-3px));font-size:calc(50% - -3px)}

    which looks correct.

    It seems the repo in charge of this is this fork https://github.com/BSI-Business-Systems-Integration-AG/yuicompressor

  24. Aleuck commented on Aug 23, 2020

    @Aleuck

    This is not correct, @frangarcia
    calc((50%)+(3px))

  25. R-W-C commented on Sep 28, 2022

    @R-W-C

    September 2022 and still broken.
    Version 2.4.8 has got several bugs. One of them is described here: https://stackoverflow.com/a/19339287/760777
    Version 2.4.9 has never been released.

    So back to version 2.4.7
    There is the calc bug. Just use the double minus solution.

    So

    left: calc(100% + 14px);

    becomes

    left: calc(100 - -14px); /* + replaced with - - because of yuicompressor bug */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions