From bc14debc5b6b6572b0cf8edf7e7c472de34fcdc0 Mon Sep 17 00:00:00 2001 From: hulinbo Date: Wed, 25 Dec 2024 10:48:31 +0800 Subject: [PATCH] fix: ParserError occurs when a css variable is multiplied by a negative number --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 7f4de0e..9d0b4f3 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,11 @@ function extractStyles(rules, cssText, {extraAllowableClasses = []} = {}) { declaration.value = declaration.value.replace(/var\(([^,]+),\s*(var\(--color-.+?\))\)/, 'var($1)'); } + // 'calc(var(--base-size-8)*-1);' -> 'calc(var(--base-size-8)* -1);' + if (/(\*\s*)-(\d)/g.test(declaration.value)) { + declaration.value = declaration.value.replaceAll(/(\*\s*)-(\d)/g, '* -$2'); + } + // '-webkit-appearance: x' << 'appearance: x' if (declaration.prop === '-webkit-appearance') { declaration.after(postcss.decl({prop: 'appearance', value: declaration.value}));