diff --git a/lib/parser/index.js b/lib/parser/index.js index e2cd71e9..3a51d8c2 100644 --- a/lib/parser/index.js +++ b/lib/parser/index.js @@ -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); } @@ -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 diff --git a/test/fixture/compress/variables.min.css b/test/fixture/compress/variables.min.css index f4ce79b6..f1bea9d1 100644 --- a/test/fixture/compress/variables.min.css +++ b/test/fixture/compress/variables.min.css @@ -1 +1 @@ -:root{--mainColor:#fb4c42;--test-var:5px}.test{color:var(--mainColor, blue);border: 1px solid var(--test-var)}a::after{content:" (" var(--external-link) ")"}.example7{--main-color: #c06;--accent-background:linear-gradient(to top,var(--main-color),white)}.example8{--one:calc(var(--two) + 20px);--two:calc(var(--one) - 20px)}one{--foo:10px}two{--bar:calc(var(--foo) + 10px)}three{--foo:calc(var(--bar) + 10px)} +:root{--mainColor:#fb4c42;--test-var:5px}.test{color:var(--mainColor,#00f);border:1px solid var(--test-var)}a::after{content:" (" var(--external-link)")"}.example7{--main-color:#c06;--accent-background:linear-gradient(to top,var(--main-color),#fff)}.example8{--one:calc(var(--two)+ 20px);--two:calc(var(--one)- 20px)}one{--foo:10px}two{--bar:calc(var(--foo)+ 10px)}three{--foo:calc(var(--bar)+ 10px)} diff --git a/test/fixture/internal/value.json b/test/fixture/internal/value.json index 076db15c..fae4385b 100644 --- a/test/fixture/internal/value.json +++ b/test/fixture/internal/value.json @@ -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",