Skip to content

Commit 045aeca

Browse files
committed
Allow value definitions with commas in them.
This makes value declarations slight more strict: there must now be only one declaration per @value (imports still work as before, and multiple values can be imported in a single @value). By doing this, it allows us to be more permissive of what the definitions can contain, thus allowing for support of things such as: - Multiple box-shadow shadows - Multiple transition specifications - Multiple media query conditions (OR'd) It does allow for a little bit of weirder usage in this, e.g. for specifying multiple values in a comma-separate rgba value: @value redAndGreen: 150, 150; .foo { background-color: rgba(redAndGreen, 0, 1); } I don't think that's a super-desirable usage, but I also don't think it really harms anything by being allowed, so I haven't attempted to mitigate it. Fixes #11.
1 parent aa28589 commit 045aeca

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
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 matchValueDefinition = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|\w+\([^\)]+\)|[^,]+)\s?/g;
20+
var matchValueDefinition = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|.+?)\s*$/g;
2121
var matchImport = /^([\w-]+)(?:\s+as\s+([\w-]+))?/;
2222
var options = {};
2323
var importIndex = 0;
@@ -30,6 +30,7 @@ exports['default'] = function (css) {
3030
var definitions = {};
3131

3232
var addDefinition = function addDefinition(atRule) {
33+
console.dir(atRule);
3334
var matches = undefined;
3435
while (matches = matchValueDefinition.exec(atRule.params)) {
3536
var _matches = matches;

src/index.js

Lines changed: 1 addition & 1 deletion
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 matchValueDefinition = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|\w+\([^\)]+\)|[^,]+)\s?/g
5+
const matchValueDefinition = /(?:\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|.+?)\s*$/g
66
const matchImport = /^([\w-]+)(?:\s+as\s+([\w-]+))?/
77
let options = {}
88
let importIndex = 0

test/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,12 @@ describe('constants', () => {
110110
':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' +
111111
'.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); }')
112112
})
113+
114+
it('should allow definitions with commas in them', () => {
115+
test(
116+
'@value coolShadow: 0 11px 15px -7px rgba(0,0,0,.2),0 24px 38px 3px rgba(0,0,0,.14) ;\n' +
117+
'.foo { box-shadow: coolShadow; }',
118+
':export {\n coolShadow: 0 11px 15px -7px rgba(0,0,0,.2),0 24px 38px 3px rgba(0,0,0,.14);\n}\n' +
119+
'.foo { box-shadow: 0 11px 15px -7px rgba(0,0,0,.2),0 24px 38px 3px rgba(0,0,0,.14); }')
120+
})
113121
})

0 commit comments

Comments
 (0)