[Pkg-javascript-commits] [less.js] 15/88: Added support for property merge via `+_`;

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


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

js pushed a commit to annotated tag v1.7.0
in repository less.js.

commit 9f4818d8fde110f18f4a2c7e004757e441c3178b
Author: seven-phases-max <seven.phases.max at gmail.com>
Date:   Tue Feb 4 06:54:05 2014 +0400

    Added support for property merge via `+_`;
---
 lib/less/parser.js         |  6 +++---
 lib/less/to-css-visitor.js | 30 ++++++++++++++++++++++++++----
 test/css/merge.css         |  7 +++++++
 test/less/merge.less       | 19 ++++++++++++++++++-
 4 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/lib/less/parser.js b/lib/less/parser.js
index 9466929..0f19d48 100644
--- a/lib/less/parser.js
+++ b/lib/less/parser.js
@@ -1484,7 +1484,7 @@ less.Parser = function Parser(env) {
                 }
             },
             rule: function (tryAnonymous) {
-                var name, value, c = input.charAt(i), important, merge = false;
+                var name, value, c = input.charAt(i), important, merge;
                 save();
 
                 if (c === '.' || c === '#' || c === '&') { return; }
@@ -1502,7 +1502,7 @@ less.Parser = function Parser(env) {
                     // a name returned by this.ruleProperty() is always an array of the form:
                     // [string-1, ..., string-n, ""] or [string-1, ..., string-n, "+"]
                     // where each item is a tree.Keyword or tree.Variable
-                    merge = name.pop && (name.pop().value === "+");
+                    merge = name.pop && name.pop().value;
 
                     if (value && this.end()) {
                         return new (tree.Rule)(name, value, important, merge, memo, env.currentFileInfo);
@@ -1944,7 +1944,7 @@ less.Parser = function Parser(env) {
 
                 match(/^(\*?)/);
                 while (match(/^((?:[\w-]+)|(?:@\{[\w-]+\}))/)); // !
-                if ((name.length > 1) && match(/^\s*(\+?)\s*:/)) {
+                if ((name.length > 1) && match(/^\s*((?:\+_|\+)?)\s*:/)) {
                     // at last, we have the complete match now. move forward, 
                     // convert name particles to tree objects and return:
                     skipWhitespace(length);
diff --git a/lib/less/to-css-visitor.js b/lib/less/to-css-visitor.js
index af4ac54..15d448c 100644
--- a/lib/less/to-css-visitor.js
+++ b/lib/less/to-css-visitor.js
@@ -199,14 +199,36 @@
             }
 
             Object.keys(groups).map(function (k) {
+
+                function toExpression(values) {
+                    return new (tree.Expression)(values.map(function (p) {
+                        return p.value;
+                    }));
+                }
+
+                function toValue(values) {
+                    return new (tree.Value)(values.map(function (p) {
+                        return p;
+                    }));
+                }
+
                 parts = groups[k];
 
                 if (parts.length > 1) {
                     rule = parts[0];
-
-                    rule.value = new (tree.Value)(parts.map(function (p) {
-                        return p.value;
-                    }));
+                    var spacedGroups = [];
+                    var lastSpacedGroup = [];
+                    parts.map(function (p) {
+                    if (p.merge==="+") {
+                        if (lastSpacedGroup.length > 0) {
+                                spacedGroups.push(toExpression(lastSpacedGroup));
+                            }
+                            lastSpacedGroup = [];
+                        }
+                        lastSpacedGroup.push(p);
+                    });
+                    spacedGroups.push(toExpression(lastSpacedGroup));
+                    rule.value = toValue(spacedGroups);
                 }
             });
         }
diff --git a/test/css/merge.css b/test/css/merge.css
index 18539f1..4168f19 100644
--- a/test/css/merge.css
+++ b/test/css/merge.css
@@ -24,3 +24,10 @@
   transform: t1, t2, t3;
   background: b1, b2, b3;
 }
+.test-spaced {
+  transform: t1 t2 t3;
+  background: b1 b2, b3;
+}
+.test-interleaved-with-spaced {
+  transform: t1a t1b, b1 t2a t2b t2c, b2, b3 t3a t3b;
+}
diff --git a/test/less/merge.less b/test/less/merge.less
index f7070d6..664ec2c 100644
--- a/test/less/merge.less
+++ b/test/less/merge.less
@@ -56,4 +56,21 @@
     transform+:  t2;
     background+: b2, b3;
     transform+:  t3;
-}
\ No newline at end of file
+}
+.test-spaced {
+    transform+_:  t1;
+    background+_: b1;
+    transform+_:  t2;
+    background+_: b2, b3;
+    transform+_:  t3;
+}
+.test-interleaved-with-spaced {
+    transform+_:  t1a;
+    transform+_:  t1b;
+    transform+:   b1;
+    transform+_:  t2a;
+    transform+_:  t2b t2c;
+    transform+:   b2, b3;
+    transform+_:  t3a;
+    transform+_:  t3b;
+}

-- 
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