[Pkg-javascript-commits] [less.js] 103/285: Iterated string interpolation

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit 796d37cc663a6f940b4e2cb9191628284f6f0bed
Author: jurcovicovam <meri at meri.org>
Date:   Fri Sep 5 16:47:37 2014 +0200

    Iterated string interpolation
    
    Solves issue #2094 .
---
 lib/less/tree/quoted.js | 23 +++++++++++++++--------
 test/css/strings.css    | 12 ++++++++++++
 test/less/strings.less  | 16 ++++++++++++++++
 3 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/lib/less/tree/quoted.js b/lib/less/tree/quoted.js
index b8f63b9..da7bc6b 100644
--- a/lib/less/tree/quoted.js
+++ b/lib/less/tree/quoted.js
@@ -20,14 +20,21 @@ tree.Quoted.prototype = {
     },
     toCSS: tree.toCSS,
     eval: function (env) {
-        var that = this;
-        var value = this.value.replace(/`([^`]+)`/g, function (_, exp) {
-            return new(tree.JavaScript)(exp, that.index, true).eval(env).value;
-        }).replace(/@\{([\w-]+)\}/g, function (_, name) {
-            var v = new(tree.Variable)('@' + name, that.index, that.currentFileInfo).eval(env, true);
-            return (v instanceof tree.Quoted) ? v.value : v.toCSS();
-        });
-        return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index, this.currentFileInfo);
+      var that = this;
+      var value = this.value.replace(/`([^`]+)`/g, function (_, exp) {
+        return new(tree.JavaScript)(exp, that.index, true).eval(env).value;
+      });
+      var evaluatedValue = value;
+      var interpolationReplacementFnc = function (_, name) {
+        var v = new(tree.Variable)('@' + name, that.index, that.currentFileInfo).eval(env, true);
+        return (v instanceof tree.Quoted) ? v.value : v.toCSS();
+      };
+      do {
+        value = evaluatedValue;
+        evaluatedValue = value.replace(/@\{([\w-]+)\}/g, interpolationReplacementFnc);
+      } while  (value!==evaluatedValue);
+      value = evaluatedValue;
+      return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index, this.currentFileInfo);
     },
     compare: function (x) {
         if (!x.toCSS) {
diff --git a/test/css/strings.css b/test/css/strings.css
index cd6d602..9243086 100644
--- a/test/css/strings.css
+++ b/test/css/strings.css
@@ -41,3 +41,15 @@
 .watermark {
   family: Univers, Arial, Verdana, San-Serif;
 }
+#iterated-interpolation .mixin {
+  width: 100px;
+  weird: 100px;
+  width-str: "100px";
+  weird-str: "100px";
+}
+#iterated-interpolation .interpolation-mixin {
+  width: 100px;
+  weird: 100px;
+  width-str: "100px";
+  weird-str: "100px";
+}
diff --git a/test/less/strings.less b/test/less/strings.less
index c43e368..4374605 100644
--- a/test/less/strings.less
+++ b/test/less/strings.less
@@ -55,3 +55,19 @@
   @family: ~"Univers, @{test}";
   family: @family;
 }
+#iterated-interpolation {
+  @box-small: 10px;
+  @box-large: 100px;
+
+  .mixin { // both ruleset and mixin
+    width: ~"@{box-@{suffix}}";
+    weird: ~"@{box}-@{suffix}}";
+    width-str: "@{box-@{suffix}}";
+    weird-str: "@{box}-@{suffix}}";
+    @box: ~"@{box";
+    @suffix: large;
+  }
+  .interpolation-mixin {
+    .mixin(); //call the above as mixin
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list