Skip to content

Commit

Permalink
support for css variables (fixes #279)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Mar 9, 2016
1 parent cba0fc3 commit a06c343
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,11 +964,13 @@ function getVarFunctionBody() {
var node = [getInfo(pos), NodeType.FunctionBodyType];

readSC(node);
node.push(readIdent(true));
node.push(getIdentifier(true));

if (pos < tokens.length && tokens[pos].type === TokenType.Comma) {
pos++;
node.push(getValue(true));
node.push(
getOperator(),
getValue(true)
);
readSC(node);
}

Expand Down Expand Up @@ -1155,8 +1157,8 @@ function getNamespacedIdentifier(checkColon) {
];
}

function getIdentifier() {
return [getInfo(pos), NodeType.IdentType, readIdent()];
function getIdentifier(varAllowed) {
return [getInfo(pos), NodeType.IdentType, readIdent(varAllowed)];
}

// ! ws* important
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/compress/variables.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions test/fixture/internal/value.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,46 @@
]
}
},
"css variables": {
"source": "var(--foo, blue)",
"translate": "var(--foo,blue)",
"ast": {
"type": "Value",
"important": false,
"sequence": [
{
"type": "Function",
"name": "var",
"arguments": [
{
"type": "Argument",
"sequence": [
{
"type": "Identifier",
"name": "--foo"
}
]
},
{
"type": "Argument",
"sequence": [
{
"type": "Value",
"important": false,
"sequence": [
{
"type": "Identifier",
"name": "blue"
}
]
}
]
}
]
}
]
}
},
"important.0": {
"source": "#123456 !important",
"translate": "#123456!important",
Expand Down

0 comments on commit a06c343

Please sign in to comment.