Skip to content

Commit 500f2fa

Browse files
benwestMadLittleMods
authored andcommitted
Accept whitespace in var( --var ) expression (MadLittleMods#93)
* Accept whitespace in var( --var ) expression
1 parent 62f2c85 commit 500f2fa

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

lib/resolve-value.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var cloneSpliceParentOntoNodeWhen = require('./clone-splice-parent-onto-node-whe
1010
// var() = var( <custom-property-name> [, <any-value> ]? )
1111
// matches `name[, fallback]`, captures "name" and "fallback"
1212
// See: http://dev.w3.org/csswg/css-variables/#funcdef-var
13-
var RE_VAR_FUNC = (/var\((--[^,\s]+?)(?:\s*,\s*(.+))?\)/);
13+
var RE_VAR_FUNC = (/var\(\s*(--[^,\s]+?)(?:\s*,\s*(.+))?\s*\)/);
1414

1515
function toString(value) {
1616
return String(value);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:root {
2+
--foo: 1px;
3+
}
4+
5+
.bar {
6+
width: var( --foo );
7+
height: var( --foo);
8+
margin-top: var(--foo );
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.bar {
2+
width: 1px;
3+
height: 1px;
4+
margin-top: 1px;
5+
}

test/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ describe('postcss-css-variables', function() {
257257
test('should not mangle outer function parentheses', 'nested-inside-other-func');
258258
});
259259

260+
test('should accept whitespace in var() declarations', 'whitespace-in-var-declaration' )
261+
260262
it('should not parse malformed var() declarations', function() {
261263
return expect(testPlugin(
262264
'./test/fixtures/malformed-variable-usage.css',

0 commit comments

Comments
 (0)