Skip to content

Spaces removed from :not statement #996

Closed

Description

@JParkinson1991

Hello,

I have been using gulp wrapper of this package and have noticed the whitespace is removed from :not statements.

Basically if i have css:

button {
    &:not(.gmap &){
        @include button();
    }
}

The compiled css becomes (notice the space removed from .gmap and button:

button:not(.gmapbutton){/* the mixin css */}

When using the following gulp process:

return gulp.src(cssPath + '/**/*.css')
        .pipe(groupMediaQueries())
        .pipe(cleanCss({
            compatibility: ie8,
            level: 2
        }))
        .pipe(gulp.dest(cssPath));

Activity

  1. abarre commented on Mar 5, 2018

    @abarre
    Contributor

    To differentiate the case of :not(.c1, .c2){} that can be minimized to :not(.c1,.c2){} and :not(.c1 .c2){} that cannot be minimized, we could verify the presence of a ',' in the selector.

  2. jakubpawlowicz commented on Mar 5, 2018

    @jakubpawlowicz
    Collaborator

    Can you put attribute rule inside not, e.g. :not(.c1[data-id="1,2,3"] .c2)? But in general it's good idea to go that way.

  3. abarre commented on Mar 5, 2018

    @abarre
    Contributor

    Well, the exact CSS4 spec for :not states that the :not() pseudo-class requires a comma-separated list of one or more selectors as its argument. The list must not contain another negation selector or a pseudo-element.

    According to CSS 3, only simple selector are valid in the argument of :not() pseudo-class and <attribute-selector> is a valid <simple-selector>.
    According to CSS 4 grammar, <attribute-selector> is a valid <selector-list>.

    So, in theory, the case that you show is possible.

  4. abarre commented on Mar 5, 2018

    @abarre
    Contributor

    Did you differentiate a <selector-list> and a <complex-selector> in the selector parser ? I didn't find if clean-css has implemented a selector parser or not.
    We may have a look at css-tree for the selector parsing part.

  5. jakubpawlowicz commented on Mar 6, 2018

    @jakubpawlowicz
    Collaborator

    Thanks @abarre for having a closer look at it.

    clean-css doesn't have a selector parser, just simple optimizer - see https://github.com/jakubpawlowicz/clean-css/blob/master/lib/optimizer/level-1/tidy-rules.js, as I haven't found a good reason to have it.

  6. tobiasvielmetter commented on Aug 21, 2019

    @tobiasvielmetter

    I have the same issue with

    .container:not(#BorlabsCookieBox .container) {
        max-width: 1280px !important;
    }
    

    being minified to:

    .container:not(#BorlabsCookieBox.container){max-width: 1280px !important;}
    

    Which is not the same selector. Any suggestions how to circumvent this?

  7. added a commit that references this issue on Jan 20, 2021
  8. jakubpawlowicz commented on Jan 20, 2021

    @jakubpawlowicz
    Collaborator

    Fixed in e651f24

  9. lluerich commented on Mar 4, 2021

    @lluerich

    I just ran into the same issue and a quick check on https://jakubpawlowicz.github.io/clean-css/ running v5.1.1. doesn't seem to have solved the issue.
    e.g. the example code that @tobiasvielmetter provided still produces the same minified output.

  10. jakubpawlowicz commented on Mar 5, 2021

    @jakubpawlowicz
    Collaborator

    Hmmm, you are right @lluerich. I have no idea how it slipped through the tests. Let's reopen it.

  11. added a commit that references this issue on Mar 19, 2021
    5d7d6aa
  12. jakubpawlowicz commented on Mar 19, 2021

    @jakubpawlowicz
    Collaborator

    This time it is fine, please see @tobiasvielmetter example in test cases - 64d8c27#diff-893825b7389c9d5a4f8db929537b0649c75836c0cb03446de8fb1d2716e1ddffR273

    Sorry for trouble with extra testing & reporting.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions