Skip to content

Commit c24881e

Browse files
committed
[fixes #5] colour values can have commas in them, but only within brackets
1 parent 8a70f70 commit c24881e

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var _icssReplaceSymbols = require('icss-replace-symbols');
1717
var _icssReplaceSymbols2 = _interopRequireDefault(_icssReplaceSymbols);
1818

1919
var matchImports = /^(.+?)\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/;
20-
var matchLet = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|[^,]+)\s?/g;
20+
var matchValueDefinition = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|\w+\([^\)]+\)|[^,]+)\s?/g;
2121
var matchImport = /^([\w-]+)(?:\s+as\s+([\w-]+))?/;
2222
var options = {};
2323
var importIndex = 0;
@@ -31,7 +31,7 @@ exports['default'] = function (css) {
3131

3232
var addDefinition = function addDefinition(atRule) {
3333
var matches = undefined;
34-
while (matches = matchLet.exec(atRule.params)) {
34+
while (matches = matchValueDefinition.exec(atRule.params)) {
3535
var _matches = matches;
3636

3737
var _matches2 = _slicedToArray(_matches, 3);

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import postcss from 'postcss'
22
import replaceSymbols, { replaceAll } from 'icss-replace-symbols'
33

44
const matchImports = /^(.+?)\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/
5-
const matchLet = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|[^,]+)\s?/g
5+
const matchValueDefinition = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|\w+\([^\)]+\)|[^,]+)\s?/g
66
const matchImport = /^([\w-]+)(?:\s+as\s+([\w-]+))?/
77
let options = {}
88
let importIndex = 0
@@ -14,7 +14,7 @@ export default css => {
1414

1515
const addDefinition = atRule => {
1616
let matches
17-
while (matches = matchLet.exec(atRule.params)) {
17+
while (matches = matchValueDefinition.exec(atRule.params)) {
1818
let [/*match*/, key, value] = matches
1919
// Add to the definitions, knowing that values can refer to each other
2020
definitions[key] = replaceAll(definitions, value)

test/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,12 @@ describe('constants', () => {
102102
':export {\n --red: i__const___red_9;\n}\n' +
103103
'.foo { color: i__const___red_9; }')
104104
})
105-
})
106105

106+
it('should allow all colour types', () => {
107+
test(
108+
'@value named: red; @value 3char #0f0; @value 6char #00ff00; @value rgba rgba(34, 12, 64, 0.3); @value hsla hsla(220, 13.0%, 18.0%, 1);\n' +
109+
'.foo { color: named; background-color: 3char; border-top-color: 6char; border-bottom-color: rgba; outline-color: hsla; }',
110+
':export {\n named: red;\n 3char: #0f0;\n 6char: #00ff00;\n rgba: rgba(34, 12, 64, 0.3);\n hsla: hsla(220, 13.0%, 18.0%, 1);\n}\n' +
111+
'.foo { color: red; background-color: #0f0; border-top-color: #00ff00; border-bottom-color: rgba(34, 12, 64, 0.3); outline-color: hsla(220, 13.0%, 18.0%, 1); }')
112+
})
113+
})

0 commit comments

Comments
 (0)