From 4c1399dc11ed7320d6dcfcba72a82aa3f956a272 Mon Sep 17 00:00:00 2001 From: "T. Nishino" Date: Wed, 11 May 2022 19:30:30 +0900 Subject: [PATCH 1/4] Add optimization for nth-last-child and nth-last-of-type (#1220) --- lib/optimizer/level-1/tidy-rules.js | 8 +++++++- test/optimizer/level-1/optimize-test.js | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/optimizer/level-1/tidy-rules.js b/lib/optimizer/level-1/tidy-rules.js index c0399886..bb467e29 100644 --- a/lib/optimizer/level-1/tidy-rules.js +++ b/lib/optimizer/level-1/tidy-rules.js @@ -193,7 +193,13 @@ function replacePseudoClasses(value) { .replace('nth-of-type(even)', 'nth-of-type(2n)') .replace('nth-child(even)', 'nth-child(2n)') .replace('nth-of-type(2n+1)', 'nth-of-type(odd)') - .replace('nth-child(2n+1)', 'nth-child(odd)'); + .replace('nth-child(2n+1)', 'nth-child(odd)') + .replace('nth-last-child(1)', 'last-child') + .replace('nth-last-of-type(1)', 'last-of-type') + .replace('nth-last-of-type(even)', 'nth-last-of-type(2n)') + .replace('nth-last-child(even)', 'nth-last-child(2n)') + .replace('nth-last-of-type(2n+1)', 'nth-last-of-type(odd)') + .replace('nth-last-child(2n+1)', 'nth-last-child(odd)'); } function tidyRules(rules, removeUnsupported, adjacentSpace, format, warnings) { diff --git a/test/optimizer/level-1/optimize-test.js b/test/optimizer/level-1/optimize-test.js index 4667498d..0723c0dc 100644 --- a/test/optimizer/level-1/optimize-test.js +++ b/test/optimizer/level-1/optimize-test.js @@ -74,6 +74,30 @@ vows.describe('level 1 optimizations') '.block:nth-child(2n+1){color:red}', '.block:nth-child(odd){color:red}' ], + 'pseudo classes - nth-last-child(1) to last-child': [ + '.block:nth-last-child(1){color:red}', + '.block:last-child{color:red}' + ], + 'pseudo classes - nth-last-of-type(1) to last-of-type': [ + '.block:nth-last-of-type(1){color:red}', + '.block:last-of-type{color:red}' + ], + 'pseudo classes - nth-last-of-type(even) to nth-last-of-type(2n)': [ + '.block:nth-last-of-type(even){color:red}', + '.block:nth-last-of-type(2n){color:red}' + ], + 'pseudo classes - nth-last-child(even) to nth-last-child(2n)': [ + '.block:nth-last-child(even){color:red}', + '.block:nth-last-child(2n){color:red}' + ], + 'pseudo classes - nth-last-of-type(2n+1) to nth-last-of-type(odd)': [ + '.block:nth-last-of-type(2n+1){color:red}', + '.block:nth-last-of-type(odd){color:red}' + ], + 'pseudo classes - nth-last-child(2n+1) to nth-last-child(odd)': [ + '.block:nth-last-child(2n+1){color:red}', + '.block:nth-last-child(odd){color:red}' + ], 'tabs': [ 'div\t\t{color:red}', 'div{color:red}' From f311d38a5b2f60b5ef2a2c3186a841d8e177d788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D1=82=D0=B8=D0=BA=20=D0=BF=D1=83?= =?UTF-8?q?=D1=80-=D0=BF=D1=83=D1=80?= Date: Thu, 7 Apr 2022 13:08:01 +0300 Subject: [PATCH 2/4] Fixes #1218 - double hyphen in at-rule breaks parsing (#1219) --- lib/tokenizer/tokenize.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tokenizer/tokenize.js b/lib/tokenizer/tokenize.js index 07575b8f..0331012c 100644 --- a/lib/tokenizer/tokenize.js +++ b/lib/tokenizer/tokenize.js @@ -373,6 +373,7 @@ function intoTokens(source, externalContext, internalContext, isNested) { position.index++; buffer = []; isBufferEmpty = true; + isVariable = false; ruleToken[2] = intoTokens(source, externalContext, internalContext, true); ruleToken = null; From 93391d1c733de1e3a5b153e96ab7387061d9edde Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Wed, 13 Jul 2022 11:29:27 +0200 Subject: [PATCH 3/4] Updates changelog for 5.3.1 release. --- History.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/History.md b/History.md index 9b8089e5..a9170877 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,9 @@ +[5.3.1 / 2022-xx-xx](https://github.com/clean-css/clean-css/compare/v5.3.0...5.3) +================== + +* Fixed issue [#1218](https://github.com/clean-css/clean-css/issues/1218) - double hyphen in at-rule breaks parsing. +* Fixed issue [#1220](https://github.com/clean-css/clean-css/issues/1220) - adds optimization for nth-* rules. + [5.3.0 / 2022-03-31](https://github.com/clean-css/clean-css/compare/v5.2.3...v5.3.0) ================== From f1047cdbafefeaebe2c0f919c4e086ca21fa49ab Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Wed, 13 Jul 2022 11:30:58 +0200 Subject: [PATCH 4/4] Version 5.3.1. --- History.md | 2 +- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index a9170877..8336afd2 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,4 @@ -[5.3.1 / 2022-xx-xx](https://github.com/clean-css/clean-css/compare/v5.3.0...5.3) +[5.3.1 / 2022-07-13](https://github.com/clean-css/clean-css/compare/v5.3.0...v5.3.1) ================== * Fixed issue [#1218](https://github.com/clean-css/clean-css/issues/1218) - double hyphen in at-rule breaks parsing. diff --git a/package-lock.json b/package-lock.json index f3a2242b..ab298be1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "clean-css", - "version": "5.3.0", + "version": "5.3.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7ac4ead2..686ce862 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clean-css", - "version": "5.3.0", + "version": "5.3.1", "author": "Jakub Pawlowicz ", "description": "A well-tested CSS minifier", "license": "MIT",