diff --git a/lib/less/parser.js b/lib/less/parser.js index 94669292a..0f19d487b 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 af4ac5432..15d448c8c 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 18539f1a8..fe29dc83b 100644 --- a/test/css/merge.css +++ b/test/css/merge.css @@ -24,3 +24,11 @@ transform: t1, t2, t3; background: b1, b2, b3; } +.test-spaced { + transform: t1 t2 t3; + background: b1 b2, b3; +} +.test-interleaved-with-spaced { + transform: t1s, t2 t3s, t4 t5s t6s; + background: b1 b2s, b3, b4; +} diff --git a/test/less/merge.less b/test/less/merge.less index f7070d631..5b5def35b 100644 --- a/test/less/merge.less +++ b/test/less/merge.less @@ -56,4 +56,23 @@ 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+_: t1s; + transform+: t2; + background+: b1; + transform+_: t3s; + transform+: t4 t5s; + background+_: b2s, b3; + transform+_: t6s; + background+: b4; +}