Skip to content

Commit 99aa363

Browse files
committed
fix, less with compression (-x) was unable to parse auto\9
1 parent 900daac commit 99aa363

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

lib/less/parser.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,29 +1197,38 @@ less.Parser = function Parser(env) {
11971197
restore();
11981198
}
11991199
},
1200-
rule: function () {
1200+
rule: function (tryAnonymous) {
12011201
var name, value, c = input.charAt(i), important, match;
12021202
save();
12031203

12041204
if (c === '.' || c === '#' || c === '&') { return }
12051205

12061206
if (name = $(this.variable) || $(this.property)) {
1207-
if (!env.compress && (name.charAt(0) != '@') && (match = /^([^@+\/'"*`(;{}-]*);/.exec(chunks[j]))) {
1208-
i += match[0].length - 1;
1209-
value = new(tree.Anonymous)(match[1]);
1210-
} else {
1211-
value = $(this.value);
1212-
}
1207+
// prefer to try to parse first if its a variable or we are compressing
1208+
// but always fallback on the other one
1209+
value = !tryAnonymous && (env.compress || (name.charAt(0) === '@')) ?
1210+
($(this.value) || $(this.anonymousValue)) :
1211+
($(this.anonymousValue) || $(this.value));
1212+
12131213
important = $(this.important);
12141214

12151215
if (value && $(this.end)) {
12161216
return new(tree.Rule)(name, value, important, memo, env.currentFileInfo);
12171217
} else {
12181218
furthest = i;
12191219
restore();
1220+
if (value && !tryAnonymous) {
1221+
return this.rule(true);
1222+
}
12201223
}
12211224
}
12221225
},
1226+
anonymousValue: function () {
1227+
if (match = /^([^@+\/'"*`(;{}-]*);/.exec(chunks[j])) {
1228+
i += match[0].length - 1;
1229+
return new(tree.Anonymous)(match[1]);
1230+
}
1231+
},
12231232

12241233
//
12251234
// An @import directive

test/css/compression/compression.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#colours{color1:#fea;color2:#fea;color3:rgba(255,238,170,0.1);string:"#ffeeaa"}
2-
dimensions{val:.1px;val:0;val:4cm;val:.2;val:5;angles-must-have-unit:0deg}
2+
dimensions{val:.1px;val:0;val:4cm;val:.2;val:5;angles-must-have-unit:0deg;width:auto\9}

test/css/css.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ p + h1 {
7474
background: -webkit-gradient(linear, left top, left bottom, from(#ff0000), to(#0000ff));
7575
margin: ;
7676
filter: alpha(opacity=100);
77+
width: auto\9;
7778
}
7879
.misc .nested-multiple {
7980
multiple-semi-colons: yes;

test/less/compression/compression.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ dimensions {
1212
val: 0.2;
1313
val: 5;
1414
angles-must-have-unit: 0deg;
15+
width: auto\9;
1516
}

test/less/css.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ p + h1 {
8585
multiple-semi-colons: yes;;;;;;
8686
};
8787
filter: alpha(opacity=100);
88+
width: auto\9;
8889
}
8990

9091
#important {

0 commit comments

Comments
 (0)