Skip to content

Commit d65c771

Browse files
committed
chore: [#1308] Fixes problem with last implementation for parsing CSS variables
1 parent 8786172 commit d65c771

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

packages/happy-dom/src/css/declaration/element-style/CSSStyleDeclarationElementStyle.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import CSSMeasurementConverter from '../measurement-converter/CSSMeasurementConv
1919
import MediaQueryList from '../../../match-media/MediaQueryList.js';
2020
import WindowBrowserSettingsReader from '../../../window/WindowBrowserSettingsReader.js';
2121

22-
const CSS_VARIABLE_REGEXP = /var\( *(--[^), ]+)\)|var\( *(--[^), ]+), *([^), ]+)\)/g;
22+
const CSS_VARIABLE_REGEXP = /var\( *(--[^), ]+)\)|var\( *(--[^), ]+), *([^), ]+)\)/;
2323
const CSS_MEASUREMENT_REGEXP = /[0-9.]+(px|rem|em|vw|vh|%|vmin|vmax|cm|mm|in|pt|pc|Q)/g;
2424

2525
type IStyleAndElement = {
@@ -364,11 +364,10 @@ export default class CSSStyleDeclarationElementStyle {
364364
* @returns CSS value.
365365
*/
366366
private parseCSSVariablesInValue(value: string, cssVariables: { [k: string]: string }): string {
367-
const regexp = new RegExp(CSS_VARIABLE_REGEXP);
368367
let newValue = value;
369368
let match;
370369

371-
while ((match = regexp.exec(newValue)) !== null) {
370+
while ((match = newValue.match(CSS_VARIABLE_REGEXP)) !== null) {
372371
// Fallback value - E.g. var(--my-var, #FFFFFF)
373372
if (match[2] !== undefined) {
374373
newValue = newValue.replace(match[0], cssVariables[match[2]] || match[3]);

0 commit comments

Comments
 (0)