From 3130fced359920aff9ef0af58438a3493a1874de Mon Sep 17 00:00:00 2001 From: Marcel Jackwerth Date: Fri, 9 Mar 2012 16:08:14 +0100 Subject: [PATCH 1/3] support strings as properties Example: @property: "border-radius"; ~"-webkit-@{property}": 5px; --- lib/less/parser.js | 12 ++++++++++++ lib/less/tree/rule.js | 10 +++++++--- test/css/variables.css | 4 ++++ test/less/variables.less | 7 +++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/less/parser.js b/lib/less/parser.js index 4b3efd541..fe45c6bb4 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -1034,6 +1034,18 @@ less.Parser = function Parser(env) { furthest = i; restore(); } + } else if (name = $(this.entities.quoted)) { + if ($(/\s*:/)) { + value = $(this.value); + important = $(this.important); + + if (value && $(this.end)) { + return new(tree.Rule)(name, value, important, memo); + } else { + furthest = i; + restore(); + } + } } }, diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index 9e4e54a3a..2fe42c27b 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -6,22 +6,26 @@ tree.Rule = function (name, value, important, index, inline) { this.important = important ? ' ' + important.trim() : ''; this.index = index; this.inline = inline || false; + this.quotedName = false; - if (name.charAt(0) === '@') { + if (!name.charAt) { + this.quotedName = true; + } else if (name.charAt(0) === '@') { this.variable = true; } else { this.variable = false } }; tree.Rule.prototype.toCSS = function (env) { if (this.variable) { return "" } else { - return this.name + (env.compress ? ':' : ': ') + + return (this.quotedName ? this.name.toCSS(env) : this.name) + + (env.compress ? ':' : ': ') + this.value.toCSS(env) + this.important + (this.inline ? "" : ";"); } }; tree.Rule.prototype.eval = function (context) { - return new(tree.Rule)(this.name, + return new(tree.Rule)(this.quotedName ? this.name.eval(context) : this.name, this.value.eval(context), this.important, this.index, this.inline); diff --git a/test/css/variables.css b/test/css/variables.css index 961fe6959..78a2ef495 100644 --- a/test/css/variables.css +++ b/test/css/variables.css @@ -25,3 +25,7 @@ a:nth-child(2) { border: 1px; } +div { + -webkit-border-radius: 5px; + border-radius: 5px; +} diff --git a/test/less/variables.less b/test/less/variables.less index 66ab4efff..72b7583d6 100644 --- a/test/less/variables.less +++ b/test/less/variables.less @@ -16,6 +16,8 @@ @quotes: "~" "~"; @q: @quotes; +@property: "border-radius"; + .variables { height: @b + @x + 0px; // 24px color: @c; @@ -52,3 +54,8 @@ a:nth-child(@a) { border: 1px; } + +div { + ~"-webkit-@{property}": 5px; + ~"@{property}": 5px; +} \ No newline at end of file From 5862230f0b4f1252e447662482d673ff70aaeaef Mon Sep 17 00:00:00 2001 From: Marcel Jackwerth Date: Fri, 9 Mar 2012 16:33:28 +0100 Subject: [PATCH 2/3] make sure state is restored properly --- lib/less/parser.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/less/parser.js b/lib/less/parser.js index fe45c6bb4..799f3a575 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -1035,16 +1035,15 @@ less.Parser = function Parser(env) { restore(); } } else if (name = $(this.entities.quoted)) { - if ($(/\s*:/)) { - value = $(this.value); - important = $(this.important); - - if (value && $(this.end)) { - return new(tree.Rule)(name, value, important, memo); - } else { - furthest = i; - restore(); - } + $(/\s*:/); + value = $(this.value); + important = $(this.important); + + if (value && $(this.end)) { + return new(tree.Rule)(name, value, important, memo); + } else { + furthest = i; + restore(); } } }, From f07aba9324a26ab8af44f97c3c193b8ab012627d Mon Sep 17 00:00:00 2001 From: Marcel Jackwerth Date: Fri, 9 Mar 2012 16:35:29 +0100 Subject: [PATCH 3/3] test with instanceof instead of existence of charAt --- lib/less/tree/rule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index 2fe42c27b..5b14de281 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -8,7 +8,7 @@ tree.Rule = function (name, value, important, index, inline) { this.inline = inline || false; this.quotedName = false; - if (!name.charAt) { + if (name instanceof tree.Quoted) { this.quotedName = true; } else if (name.charAt(0) === '@') { this.variable = true;