Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New lines not created after comments within :root selectors #1009

Closed
overdodactyl opened this issue Feb 24, 2018 · 2 comments
Closed

New lines not created after comments within :root selectors #1009

overdodactyl opened this issue Feb 24, 2018 · 2 comments
Labels

Comments

@overdodactyl
Copy link

overdodactyl commented Feb 24, 2018

Environment

  • clean-css version - npm ls clean-css:
    ├─┬ clean-css-cli@4.1.10
    │ └── clean-css@4.1.9
    └─┬ gulp-clean-css@3.9.0
    └── clean-css@4.1.9 deduped

  • node.js version - node -v: v8.9.3

  • operating system: macOS 10.13

Configuration options

cleancss -o test.min.css -f beautify test.css

or, alternatively,

'use strict';

var gulp = require('gulp');
var cleanCSS = require('gulp-clean-css');


gulp.task('minify-css', () => {
  return gulp.src(['test.css'])
    .pipe(cleanCSS({
      level : 2 ,
      format: 'beautify'
    }))
    .pipe(gulp.dest('./test.min.css'));
});

Input CSS

:root {
  --example-1: 1;
  /*! Comment 1 inside root */
  /*! Comment 2 inside root */
  --example-2: 2;
  --example-3: 3;
}

/*! Comment 1 outside root */
/*! Comment 2 outside root */
#example {
  color: blue;
}

Actual output CSS

:root {
  --example-1: 1;
  /*! Comment 1 inside root *//*! Comment 2 inside root */--example-2: 2;
  --example-3: 3
}
/*! Comment 1 outside root */
/*! Comment 2 outside root */
#example {
  color: #00f
}

Expected output CSS

:root {
  --example-1: 1;
  /*! Comment 1 inside root */
  /*! Comment 2 inside root */
  --example-2: 2;
  --example-3: 3
}
/*! Comment 1 outside root */
/*! Comment 2 outside root */
#example {
  color: blue
}

As seen above, if there are any comments within :root, the line breaks after them are removed (this is in contrast to comments outside of :root selectors). This also occurs if you use specify afterComment: true in the breaks formatting option. To me, it doesn't seem like this should be expected behavior, but I apologize if it is :)

@overdodactyl overdodactyl changed the title New lines not created after comments withing :root selectors New lines not created after comments within :root selectors Feb 24, 2018
@overdodactyl
Copy link
Author

Just to add to this, it seems like there are a few other inconsistencies when comments are kept inside some form of bracket. For example,

@media screen and (-moz-windows-theme) {
  /*! Comment inside @media */
  #sample {
    /*! Comment inside id */
    color:red;
  }
}
@media screen and (-moz-windows-theme) {
  #sample {
    color:red;
  }
}

gets reduced to

@media screen and (-moz-windows-theme) {
  /*! Comment inside @media */
#sample {
    /*! Comment inside id */color: red
  }
}
@media screen and (-moz-windows-theme) {
  #sample {
    color: red
  }
}

In the above example, a comment inside @media does get a newline after it, but the one inside #sample does not. Additionally, the indent level seems to be get lost in #sample when keeping a comment.

@jakubpawlowicz
Copy link
Collaborator

Yup, it doesn't work as intended, thanks for 👍 bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants