Skip to content

Commit 957d860

Browse files
committed
Pass through the "important" flag of a mixin to inner mixins.
1 parent c365287 commit 957d860

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ private static class SharedState {
108108
private CssFormatter header;
109109

110110
private boolean isReference;
111+
112+
private int importantCount;
111113
}
112114

113115
private String[] selectors;
@@ -122,8 +124,6 @@ private static class SharedState {
122124

123125
private StringBuilder insets = new StringBuilder();
124126

125-
private boolean important;
126-
127127
private boolean inlineMode;
128128

129129
private final DecimalFormat decFormat = new DecimalFormat( "#.########", DecimalFormatSymbols.getInstance( Locale.ENGLISH ) );
@@ -732,7 +732,7 @@ void appendProperty( @Nonnull String name, @Nonnull Expression value ) {
732732
} else {
733733
value.appendTo( this );
734734
}
735-
if( important || value.isImportant() ) {
735+
if( state.importantCount > 0 || value.isImportant() ) {
736736
output.append( " !important" );
737737
}
738738
semicolon();
@@ -766,12 +766,17 @@ void appendFontPropertyValue( Operation value ) {
766766
}
767767

768768
/**
769-
* Set the flag important.
770-
*
771-
* @param important the new value
769+
* Increment the important flag.
770+
*/
771+
void incImportant() {
772+
state.importantCount++;
773+
}
774+
775+
/**
776+
* Decrement the important flag.
772777
*/
773-
void setImportant( boolean important ) {
774-
this.important = important;
778+
void decImportant() {
779+
state.importantCount--;
775780
}
776781

777782
/**

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ public final int getType() {
7676
*/
7777
@Override
7878
public void appendTo( CssFormatter formatter ) {
79-
formatter.setImportant( important );
8079
try {
80+
if( important ) {
81+
formatter.incImportant();
82+
}
8183
for( MixinMatch match : getRules( formatter ) ) {
8284
Rule rule = match.getRule();
8385
formatter.addMixin( rule, match.getMixinParameters(), rule.getVariables() );
@@ -89,8 +91,11 @@ public void appendTo( CssFormatter formatter ) {
8991
throw ex;
9092
} catch( StackOverflowError soe ) {
9193
throw createException( "Maximum call stack size exceeded in mixin: " + name, soe );
94+
} finally {
95+
if( important ) {
96+
formatter.decImportant();
97+
}
9298
}
93-
formatter.setImportant( false );
9499
}
95100

96101
/**
@@ -100,6 +105,9 @@ public void appendTo( CssFormatter formatter ) {
100105
*/
101106
void appendSubRules( String[] parentSelector, CssFormatter formatter ) {
102107
try {
108+
if( important ) {
109+
formatter.incImportant();
110+
}
103111
for( MixinMatch match : getRules( formatter ) ) {
104112
Rule rule = match.getRule();
105113
formatter.addMixin( rule, match.getMixinParameters(), rule.getVariables() );
@@ -114,6 +122,10 @@ void appendSubRules( String[] parentSelector, CssFormatter formatter ) {
114122
} catch( LessException ex ) {
115123
ex.addPosition( filename, line, column );
116124
throw ex;
125+
} finally {
126+
if( important ) {
127+
formatter.decImportant();
128+
}
117129
}
118130
}
119131

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.class {
2+
border: 1;
3+
boxer: 1;
4+
border-width: 1;
5+
border: 2 !important;
6+
boxer: 2 !important;
7+
border-width: 2 !important;
8+
border: 3;
9+
boxer: 3;
10+
border-width: 3;
11+
border: 4 !important;
12+
boxer: 4 !important;
13+
border-width: 4 !important;
14+
border: 5;
15+
boxer: 5;
16+
border-width: 5;
17+
border: 0 !important;
18+
boxer: 0 !important;
19+
border-width: 0 !important;
20+
border: 9 !important;
21+
border: 9;
22+
boxer: 9;
23+
border-width: 9;
24+
}
25+
.class .inner {
26+
test: 1;
27+
test: 2 !important;
28+
test: 3;
29+
test: 4 !important;
30+
test: 5;
31+
test: 0 !important;
32+
test: 9;
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.submixin(@a) {
2+
border-width: @a;
3+
}
4+
.mixin (9) {
5+
border: 9 !important;
6+
}
7+
.mixin (@a: 0) {
8+
border: @a;
9+
boxer: @a;
10+
.inner {
11+
test: @a;
12+
}
13+
// comment
14+
.submixin(@a);
15+
}
16+
17+
.class {
18+
.mixin(1);
19+
.mixin(2) !important;
20+
.mixin(3);
21+
.mixin(4) !important;
22+
.mixin(5);
23+
.mixin !important;
24+
.mixin(9);
25+
}

0 commit comments

Comments
 (0)