Skip to content

Commit

Permalink
Accept whitespace in var( --var ) expression (#93)
Browse files Browse the repository at this point in the history
* Accept whitespace in var(   --var    ) expression
  • Loading branch information
benwest authored and MadLittleMods committed Feb 21, 2019
1 parent 62f2c85 commit 500f2fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/resolve-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var cloneSpliceParentOntoNodeWhen = require('./clone-splice-parent-onto-node-whe
// var() = var( <custom-property-name> [, <any-value> ]? )
// matches `name[, fallback]`, captures "name" and "fallback"
// See: http://dev.w3.org/csswg/css-variables/#funcdef-var
var RE_VAR_FUNC = (/var\((--[^,\s]+?)(?:\s*,\s*(.+))?\)/);
var RE_VAR_FUNC = (/var\(\s*(--[^,\s]+?)(?:\s*,\s*(.+))?\s*\)/);

function toString(value) {
return String(value);
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/whitespace-in-var-declaration.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:root {
--foo: 1px;
}

.bar {
width: var( --foo );
height: var( --foo);
margin-top: var(--foo );
}
5 changes: 5 additions & 0 deletions test/fixtures/whitespace-in-var-declaration.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.bar {
width: 1px;
height: 1px;
margin-top: 1px;
}
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ describe('postcss-css-variables', function() {
test('should not mangle outer function parentheses', 'nested-inside-other-func');
});

test('should accept whitespace in var() declarations', 'whitespace-in-var-declaration' )

it('should not parse malformed var() declarations', function() {
return expect(testPlugin(
'./test/fixtures/malformed-variable-usage.css',
Expand Down

0 comments on commit 500f2fa

Please sign in to comment.