From d8441445a506336d9c4229aa5b4d3a5ef202bbf7 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 3 Jan 2012 22:41:14 +0100 Subject: [PATCH] change negation operators to be more cssy --- lib/less/parser.js | 6 +++--- lib/less/tree/condition.js | 4 ++-- test/css/mixins-guards.css | 2 ++ test/less/mixins-guards.less | 8 ++++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/less/parser.js b/lib/less/parser.js index 62321666..e828b52e 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -1171,17 +1171,17 @@ less.Parser = function Parser(env) { condition: function () { var a, b, c, op, index = i, negate = false; + if ($(/^not/)) { negate = true } expect('('); - if ($('!')) { negate = true } if (a = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) { - if (op = $(/^(?:>=|=<|\!=|[<=>])/)) { + if (op = $(/^(?:>=|=<|\^=|[<=>])/)) { if (b = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) { c = new(tree.Condition)(op, a, b, index); } else { error('expected expression'); } } else { - c = new(tree.Condition)(negate ? '!=' : '=', a, new(tree.Keyword)('true'), index); + c = new(tree.Condition)(negate ? '^=' : '=', a, new(tree.Keyword)('true'), index); } expect(')'); return $(/^and/) ? new(tree.Condition)('and', c, $(this.condition)) : c; diff --git a/lib/less/tree/condition.js b/lib/less/tree/condition.js index 9dcdbf70..83cd0925 100644 --- a/lib/less/tree/condition.js +++ b/lib/less/tree/condition.js @@ -28,9 +28,9 @@ tree.Condition.prototype.eval = function (env) { index: i }; } switch (result) { - case -1: return this.op === '<' || this.op === '=<' || this.op === '!='; + case -1: return this.op === '<' || this.op === '=<' || this.op === '^='; case 0: return this.op === '=' || this.op === '>=' || this.op === '=<'; - case 1: return this.op === '>' || this.op === '>=' || this.op === '!='; + case 1: return this.op === '>' || this.op === '>=' || this.op === '^='; } } }; diff --git a/test/css/mixins-guards.css b/test/css/mixins-guards.css index d7e92db3..0c563e52 100644 --- a/test/css/mixins-guards.css +++ b/test/css/mixins-guards.css @@ -53,4 +53,6 @@ content: false, true and true; content: false, false, true; content: false, true and true and true, false; + content: not false; + content: not false and false, not false; } diff --git a/test/less/mixins-guards.less b/test/less/mixins-guards.less index c131c287..0166b7df 100644 --- a/test/less/mixins-guards.less +++ b/test/less/mixins-guards.less @@ -43,7 +43,7 @@ .ops (@a) when (@a =< 0) { height: lt-or-eq; } -.ops (@a) when (@a != 0) { +.ops (@a) when (@a ^= 0) { height: not-eq; } .ops1 { .ops(0) } @@ -63,7 +63,7 @@ .test (@a) when (@a) { content: "true."; } -.test (@a) when (!@a) { +.test (@a) when not (@a) { content: "false."; } @@ -86,5 +86,9 @@ .bool () when (false), (false), (true) { content: false, false, true } // TRUE .bool () when (false), (false) and (true), (false) { content: false, false and true, false } // FALSE .bool () when (false), (true) and (true) and (true), (false) { content: false, true and true and true, false } // TRUE +.bool () when not (false) { content: not false } +.bool () when not (true) and not (false) { content: not true and not false } +.bool () when not (true) and not (true) { content: not true and not true } +.bool () when not (false) and (false), not (false) { content: not false and false, not false } .bool1 { .bool }