Skip to content

Commit 04bf2a0

Browse files
author
volker
committed
Handle doubled rule correctly in the compressed formatter if previous
rule ends with an block
1 parent 49b1556 commit 04bf2a0

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/com/inet/lib/less/CompressCssFormatter.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*/
2727
package com.inet.lib.less;
2828

29-
3029
/**
3130
* A version of the CssFormatter that produce a compressed output.
3231
*/
@@ -148,8 +147,13 @@ private void checkSemicolon() {
148147
CssFormatter startBlock( String[] selectors ) {
149148
checkSemicolon();
150149
CssFormatter formatter = super.startBlock( selectors );
151-
if( formatter != this && formatter.getOutput().length() > 0 ) { // two rules with same selector was merged
152-
formatter.semicolon();
150+
if( formatter != this ) { // two rules with same selector was merged
151+
StringBuilder output = formatter.getOutput();
152+
int length = output.length();
153+
if( length > 0 && output.charAt( length-1 ) != '}' ) {
154+
// the previous rule of the same selector ends with a property
155+
formatter.semicolon();
156+
}
153157
}
154158
return formatter;
155159
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@supports selector {
2+
surrounding .parentclass {
3+
background: red;
4+
}
5+
surrounding .parentclass .element {
6+
display: flex;
7+
}
8+
surrounding .parentclass .another {
9+
border-color: green;
10+
}
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@supports selector{surrounding .parentclass{background:#f00}surrounding .parentclass .element{display:flex}surrounding .parentclass .another{border-color:#008000}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
surrounding {
2+
@supports selector {
3+
.parentclass {
4+
background: red;
5+
6+
.element {
7+
display: flex;
8+
}
9+
10+
.another {
11+
border-color: green;
12+
}
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)