Skip to content

Commit b143c3a

Browse files
authored
fix: support parsing */ expressions without surrounding spaces (#144)
fixes #138
1 parent a59fac9 commit b143c3a

File tree

5 files changed

+1381
-0
lines changed

5 files changed

+1381
-0
lines changed

lib/ValuesParser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ module.exports = class ValuesParser extends Parser {
148148

149149
if (Punctuation.chars.includes(type)) {
150150
Punctuation.fromTokens(tokens, this);
151+
} else if (type === 'word' && Operator.test(tokens, this)) {
152+
Operator.fromTokens(tokens, this);
151153
} else if (Func.test(tokens)) {
152154
Func.fromTokens(tokens, this);
153155
} else if (this.options.interpolation && Interpolation.test(tokens, this)) {

lib/nodes/Operator.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Node = require('./Node');
1414

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

1819
class Operator extends Node {
1920
constructor(options) {
@@ -33,6 +34,13 @@ class Operator extends Node {
3334
return operRegex;
3435
}
3536

37+
static test(tokens, parser) {
38+
const [first] = tokens;
39+
const [, value] = first;
40+
const { lastNode } = parser;
41+
return lastNode && lastNode.type === 'func' && compactRegex.test(value);
42+
}
43+
3644
static tokenize(tokens, parser) {
3745
const [first, ...rest] = tokens;
3846
const [, value, startLine, , endLine, endChar] = first;

test/fixtures/func.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ module.exports = {
2929
'lCH(40% 68.8 34.5 / 50%)',
3030
'hwb(90deg 0% 0% / 0.5)',
3131
'calc(-0.5 * var(foo))',
32+
'calc(var(--foo)*var(--bar))',
3233
'calc(1px + -2vw - 4px)',
3334
'calc(((768px - 100vw) / 2) - 15px)',
35+
'calc(((768px - 100vw)/2) - 15px)',
3436
'bar(baz(black, 10%), 10%)',
3537
'-webkit-linear-gradient(0)',
3638
'var(--foo)',

0 commit comments

Comments
 (0)