Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ValuesParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ module.exports = class ValuesParser extends Parser {

if (Punctuation.chars.includes(type)) {
Punctuation.fromTokens(tokens, this);
} else if (type === 'word' && Operator.test(tokens, this)) {
Operator.fromTokens(tokens, this);
} else if (Func.test(tokens)) {
Func.fromTokens(tokens, this);
} else if (this.options.interpolation && Interpolation.test(tokens, this)) {
Expand Down
8 changes: 8 additions & 0 deletions lib/nodes/Operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Node = require('./Node');

const operators = ['+', '-', '/', '*', '%', '=', '<=', '>=', '<', '>'];
const operRegex = new RegExp(`([/|*}])`);
const compactRegex = /^[*/]\b/;

class Operator extends Node {
constructor(options) {
Expand All @@ -33,6 +34,13 @@ class Operator extends Node {
return operRegex;
}

static test(tokens, parser) {
const [first] = tokens;
const [, value] = first;
const { lastNode } = parser;
return lastNode && lastNode.type === 'func' && compactRegex.test(value);
}

static tokenize(tokens, parser) {
const [first, ...rest] = tokens;
const [, value, startLine, , endLine, endChar] = first;
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ module.exports = {
'lCH(40% 68.8 34.5 / 50%)',
'hwb(90deg 0% 0% / 0.5)',
'calc(-0.5 * var(foo))',
'calc(var(--foo)*var(--bar))',
'calc(1px + -2vw - 4px)',
'calc(((768px - 100vw) / 2) - 15px)',
'calc(((768px - 100vw)/2) - 15px)',
'bar(baz(black, 10%), 10%)',
'-webkit-linear-gradient(0)',
'var(--foo)',
Expand Down
Loading