Skip to content

Commit b724f5a

Browse files
committed
Merge pull request #2380 from seven-phases-max/referencing-variable-by-color-keyword
Colour keyword as variable name reference
2 parents 669cc3d + 112bfec commit b724f5a

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

lib/less/functions/color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ colorFunctions = {
259259
return new Color(c.value.slice(1));
260260
}
261261
if ((c instanceof Color) || (c = Color.fromKeyword(c.value))) {
262-
c.keyword = undefined;
262+
c.value = undefined;
263263
return c;
264264
}
265265
throw {

lib/less/functions/svg.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = function(environment) {
22
var Dimension = require("../tree/dimension"),
33
Color = require("../tree/color"),
4+
Expression = require("../tree/expression"),
45
Quoted = require("../tree/quoted"),
56
URL = require("../tree/url"),
67
functionRegistry = require("./function-registry");
@@ -50,7 +51,7 @@ module.exports = function(environment) {
5051
'<' + gradientType + 'Gradient id="gradient" gradientUnits="userSpaceOnUse" ' + gradientDirectionSvg + '>';
5152

5253
for (i = 0; i < stops.length; i+= 1) {
53-
if (stops[i].value) {
54+
if (stops[i] instanceof Expression) {
5455
color = stops[i].value[0];
5556
position = stops[i].value[1];
5657
} else {

lib/less/tree/color.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ Color.prototype.genCSS = function (context, output) {
5656
Color.prototype.toCSS = function (context, doNotCompress) {
5757
var compress = context && context.compress && !doNotCompress, color, alpha;
5858

59-
// `keyword` is set if this color was originally
59+
// `value` is set if this color was originally
6060
// converted from a named color string so we need
6161
// to respect this and try to output named color too.
62-
if (this.keyword) {
63-
return this.keyword;
62+
if (this.value) {
63+
return this.value;
6464
}
6565

6666
// If we have some transparency, the only way to represent it
@@ -179,7 +179,7 @@ Color.fromKeyword = function(keyword) {
179179
}
180180

181181
if (c) {
182-
c.keyword = keyword;
182+
c.value = keyword;
183183
return c;
184184
}
185185
};

test/css/variables.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@
2222
multi-important: #888888 #888888, 'Trebuchet' !important;
2323
multi: something 'A', B, C, 'Trebuchet';
2424
}
25-
.variable-names {
25+
.variable-names .quoted {
26+
name: 'hello';
27+
}
28+
.variable-names .unquoted {
29+
name: 'hello';
30+
}
31+
.variable-names .color-keyword {
2632
name: 'hello';
2733
}
2834
.alpha {

test/less/variables.less

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,23 @@
5151
}
5252

5353
.variable-names {
54-
@var: 'hello';
55-
@name: 'var';
56-
name: @@name;
54+
.quoted {
55+
@var: 'hello';
56+
@name: 'var';
57+
name: @@name;
58+
}
59+
60+
.unquoted {
61+
@var: 'hello';
62+
@name: var;
63+
name: @@name;
64+
}
65+
66+
.color-keyword {
67+
@red: 'hello';
68+
@name: red;
69+
name: @@name;
70+
}
5771
}
5872

5973
.alpha {

0 commit comments

Comments
 (0)