Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: clean-css/clean-css
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.1.1
Choose a base ref
...
head repository: clean-css/clean-css
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.1.2
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Mar 3, 2021

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    jakubpawlowicz Jakub Pawlowicz
    Copy the full SHA
    ebf9ea7 View commit details

Commits on Mar 19, 2021

  1. Fixes #996 - outstanding issue with spaces removed inside pseudoclasses.

    I thought we fixed it with #1062 but this case was different.
    jakubpawlowicz committed Mar 19, 2021

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    jakubpawlowicz Jakub Pawlowicz
    Copy the full SHA
    5d7d6aa View commit details
  2. Version 5.1.2.

    jakubpawlowicz committed Mar 19, 2021

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    jakubpawlowicz Jakub Pawlowicz
    Copy the full SHA
    aa250dd View commit details
Showing with 44 additions and 6 deletions.
  1. +5 −0 History.md
  2. +1 −1 docs/index.html
  3. +1 −1 docs/js/optimizer-worker.js
  4. +27 −2 lib/optimizer/level-1/tidy-rules.js
  5. +1 −1 package-lock.json
  6. +1 −1 package.json
  7. +8 −0 test/optimizer/level-1/optimize-test.js
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[5.1.2 / 2021-03-19](https://github.com/jakubpawlowicz/clean-css/compare/v5.1.1...v5.1.2)
==================

* Fixed issue [#996](https://github.com/jakubpawlowicz/clean-css/issues/996) - space removed from pseudo classes.

[5.1.1 / 2021-03-03](https://github.com/jakubpawlowicz/clean-css/compare/v5.1.0...v5.1.1)
==================

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ <h1 class="logo">
<form class="settings settings--collapsed js-settings">
<fieldset class="settings__group">
<select class="settings__option settings__option--version" name="version">
<option value="v5.1.0" selected>5.1.0 (latest)</option>
<option value="v5.1.1" selected>5.1.1 (latest)</option>
</select>
</fieldset>
<fieldset class="settings__group settings__group--advanced">
2 changes: 1 addition & 1 deletion docs/js/optimizer-worker.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ onmessage = function(event) {
case 'initialize':
if (!initialized) {
initialized = true
importScripts('//jakubpawlowicz.github.io/clean-css-builds/v5.1.0.js')
importScripts('//jakubpawlowicz.github.io/clean-css-builds/v5.1.1.js')
}
break
case 'optimize':
29 changes: 27 additions & 2 deletions lib/optimizer/level-1/tidy-rules.js
Original file line number Diff line number Diff line change
@@ -16,6 +16,18 @@ var ASTERISK_PLUS_HTML_HACK = '*+html ';
var ASTERISK_FIRST_CHILD_PLUS_HTML_HACK = '*:first-child+html ';
var LESS_THAN = '<';

var PSEUDO_CLASSES_WITH_SELECTORS = [
':current',
':future',
':has',
':host',
':host-context',
':is',
':not',
':past',
':where'
];

function hasInvalidCharacters(value) {
var isEscaped;
var isInvalid = false;
@@ -57,8 +69,9 @@ function removeWhitespace(value, format) {
var isAttribute;
var isRelation;
var isWhitespace;
var isPseudoClass = value[0] == Marker.COLON;
var isSpaceAwarePseudoClass;
var roundBracketLevel = 0;
var wasComma = false;
var wasRelation = false;
var wasWhitespace = false;
var withCaseAttribute = CASE_ATTRIBUTE_PATTERN.test(value);
@@ -73,6 +86,9 @@ function removeWhitespace(value, format) {
isQuoted = isSingleQuoted || isDoubleQuoted;
isRelation = !isAttribute && !isEscaped && roundBracketLevel === 0 && RELATION_PATTERN.test(character);
isWhitespace = WHITESPACE_PATTERN.test(character);
isSpaceAwarePseudoClass = roundBracketLevel == 1 && character == Marker.CLOSE_ROUND_BRACKET ?
false :
isSpaceAwarePseudoClass || (roundBracketLevel === 0 && character == Marker.COLON && isPseudoClassWithSelectors(value, i));

if (wasEscaped && isQuoted && isNewLineWin) {
// swallow escaped new windows lines in comments
@@ -112,7 +128,9 @@ function removeWhitespace(value, format) {
} else if (!isWhitespace && wasRelation && spaceAroundRelation) {
stripped.push(Marker.SPACE);
stripped.push(character);
} else if (isWhitespace && !wasWhitespace && roundBracketLevel > 0 && isPseudoClass) {
} else if (isWhitespace && !wasWhitespace && wasComma && roundBracketLevel > 0 && isSpaceAwarePseudoClass) {
// skip space
} else if (isWhitespace && !wasWhitespace && roundBracketLevel > 0 && isSpaceAwarePseudoClass) {
stripped.push(character);
} else if (isWhitespace && (isAttribute || roundBracketLevel > 0) && !isQuoted) {
// skip space
@@ -136,13 +154,20 @@ function removeWhitespace(value, format) {
isEscaped = character == Marker.BACK_SLASH;
wasRelation = isRelation;
wasWhitespace = isWhitespace;
wasComma = character == Marker.COMMA;
}

return withCaseAttribute ?
stripped.join('').replace(CASE_RESTORE_PATTERN, '$1 $2]') :
stripped.join('');
}

function isPseudoClassWithSelectors(value, colonPosition) {
var pseudoClass = value.substring(colonPosition, value.indexOf(Marker.OPEN_ROUND_BRACKET, colonPosition));

return PSEUDO_CLASSES_WITH_SELECTORS.indexOf(pseudoClass) > -1;
}

function removeQuotes(value) {
if (value.indexOf('\'') == -1 && value.indexOf('"') == -1) {
return value;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clean-css",
"version": "5.1.1",
"version": "5.1.2",
"author": "Jakub Pawlowicz <contact@jakubpawlowicz.com> (https://jakubpawlowicz.com)",
"description": "A well-tested CSS minifier",
"license": "MIT",
8 changes: 8 additions & 0 deletions test/optimizer/level-1/optimize-test.js
Original file line number Diff line number Diff line change
@@ -257,13 +257,21 @@ vows.describe('level 1 optimizations')
':host-context(main article){color:red}',
':host-context(main article){color:red}'
],
'extra spaces with comma are removed': [
':host-context(main, article){color:red}',
':host-context(main,article){color:red}'
],
'space is not removed in multiple rules': [
':host-context(main footer),:host-context(main header){color:red}',
':host-context(main footer),:host-context(main header){color:red}'
],
'space is not removed from :not pseudo-class': [
':not(.block1 .block1__block2){color:red}',
':not(.block1 .block1__block2){color:red}'
],
'space in scoped pseudo class': [
'.container:not(#BorlabsCookieBox .container){max-width:1280px!important}',
'.container:not(#BorlabsCookieBox .container){max-width:1280px!important}'
]
}, { level: 1 })
)