Permalink
Browse files

support nested interpolations #345

  • Loading branch information...
1 parent 655abb3 commit 21a012ff48b289e3e500ebd7c45ca90d5acbd39c @leafo committed Feb 12, 2013
Showing with 27 additions and 8 deletions.
  1. +11 −8 lessc.inc.php
  2. +11 −0 tests/inputs/interpolation.less
  3. +5 −0 tests/outputs/interpolation.css
View
@@ -1215,6 +1215,10 @@ protected function funcToColor($func) {
protected function reduce($value, $forExpression = false) {
switch ($value[0]) {
+ case "interpolate":
+ $reduced = $this->reduce($value[1]);
+ $var = $this->compileValue($reduced);
+ return $this->lib_e($this->reduce(array("variable", $this->vPrefix . $var)));
case "variable":
$key = $value[1];
if (is_array($key)) {
@@ -1490,7 +1494,7 @@ function lib_red($color){
if (is_null($color)) {
$this->throwError('color expected for red()');
}
-
+
return $color[1];
}
@@ -1499,7 +1503,7 @@ function lib_green($color){
if (is_null($color)) {
$this->throwError('color expected for green()');
}
-
+
return $color[2];
}
@@ -1508,7 +1512,7 @@ function lib_blue($color){
if (is_null($color)) {
$this->throwError('color expected for blue()');
}
-
+
return $color[3];
}
@@ -2644,12 +2648,11 @@ protected function openString($end, &$out, $nestingOpen=null, $rejectStrs = null
continue;
}
- if (in_array($tok, $rejectStrs)) {
- $count = null;
+ if (!empty($rejectStrs) && in_array($tok, $rejectStrs)) {
+ $ount = null;
break;
}
-
$content[] = $tok;
$this->count+= strlen($tok);
}
@@ -2724,10 +2727,10 @@ protected function interpolation(&$out) {
$s = $this->seek();
if ($this->literal("@{") &&
- $this->keyword($var) &&
+ $this->openString("}", $interp, null, array("'", '"', ";")) &&
$this->literal("}", false))
{
- $out = array("variable", $this->lessc->vPrefix . $var);
+ $out = array("interpolate", $interp);
$this->eatWhiteDefault = $oldWhite;
if ($this->eatWhiteDefault) $this->whitespace();
return true;
@@ -0,0 +1,11 @@
+
+@cool-hello: "yes";
+@cool-yes: "okay";
+@var: "hello";
+
+div {
+ color: ~"@{cool-hello}";
+ color: ~"@{cool-@{var}}";
+ color: ~"@{cool-@{cool-@{var}}}";
+}
+
@@ -0,0 +1,5 @@
+div {
+ color: yes;
+ color: yes;
+ color: okay;
+}

1 comment on commit 21a012f

@srsgores

It fixed my errors. Thanks.

Please sign in to comment.