Skip to content

Commit

Permalink
[wip] fix: support parsing */ expressions without surrounding spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjake committed Nov 22, 2021
1 parent 5aea4d7 commit 04ad8f7
Show file tree
Hide file tree
Showing 5 changed files with 993 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ValuesParser.js
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.compact.test(value)) {
Operator.fromTokens(tokens, this);
} else if (Func.test(tokens)) {
Func.fromTokens(tokens, this);
} else if (this.options.interpolation && Interpolation.test(tokens, this)) {
Expand Down
5 changes: 5 additions & 0 deletions lib/nodes/Operator.js
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,10 @@ class Operator extends Node {
return operRegex;
}

static get compact() {
return compactRegex;
}

static tokenize(tokens, parser) {
const [first, ...rest] = tokens;
const [, value, startLine, , endLine, endChar] = first;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/func.js
Expand Up @@ -29,6 +29,7 @@ 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)',
'bar(baz(black, 10%), 10%)',
Expand Down

0 comments on commit 04ad8f7

Please sign in to comment.