Skip to content

Property merge with +_ (replaces #1788) #1847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/less/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 26 additions & 4 deletions lib/less/to-css-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions test/css/merge.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
21 changes: 20 additions & 1 deletion test/less/merge.less
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,23 @@
transform+: t2;
background+: b2, b3;
transform+: t3;
}
}

.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;
}