mirror of
https://github.com/less/less.js.git
synced 2026-01-26 23:58:29 -05:00
improve condition parser, support true/false values
This commit is contained in:
@@ -517,7 +517,7 @@ less.Parser = function Parser(env) {
|
||||
// detect named color
|
||||
return new(tree.Color)(tree.colors[k].slice(1));
|
||||
} else {
|
||||
return new(tree.Keyword)(k)
|
||||
return new(tree.Keyword)(k);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1159,16 +1159,20 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
},
|
||||
condition: function () {
|
||||
var a, b, op, index = i;
|
||||
if ($('(')) {
|
||||
if (a = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
|
||||
if (op = $(/^(?:>=|=<|\!=|[<=>])/)) {
|
||||
if (b = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
|
||||
if ($(')')) {
|
||||
return new(tree.Condition)(op, a, b, index);
|
||||
}
|
||||
}
|
||||
var a, b, op, index = i, negate = false;
|
||||
expect('(');
|
||||
if ($('!')) { negate = true }
|
||||
if (a = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
|
||||
if (op = $(/^(?:>=|=<|\!=|[<=>])/)) {
|
||||
if (b = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
|
||||
expect(')');
|
||||
return new(tree.Condition)(op, a, b, index);
|
||||
} else {
|
||||
error('expected expression');
|
||||
}
|
||||
} else {
|
||||
expect(')');
|
||||
return new(tree.Condition)(negate ? '!=' : '=', a, new(tree.Keyword)('true'), index);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -30,3 +30,9 @@
|
||||
.default1 {
|
||||
content: default;
|
||||
}
|
||||
.test1 {
|
||||
content: "true.";
|
||||
}
|
||||
.test2 {
|
||||
content: "false.";
|
||||
}
|
||||
|
||||
@@ -58,3 +58,14 @@
|
||||
content: default;
|
||||
}
|
||||
.default1 { .default }
|
||||
|
||||
// true & false keywords
|
||||
.test (@a) when (@a) {
|
||||
content: "true.";
|
||||
}
|
||||
.test (@a) when (!@a) {
|
||||
content: "false.";
|
||||
}
|
||||
|
||||
.test1 { .test(true) }
|
||||
.test2 { .test(false) }
|
||||
|
||||
Reference in New Issue
Block a user