From e9ca7ab4532ed9819e4f3d6eb22a0b6c91220a9b Mon Sep 17 00:00:00 2001 From: Simon He <57086651+Simon-He95@users.noreply.github.com> Date: Tue, 17 Oct 2023 08:18:17 +0800 Subject: [PATCH] Speed up CSS math function check (#12215) * perf(cssMathFnRE): Dynamically create regular rules * Cleanup code --------- Co-authored-by: Jordan Pittman --- src/util/dataTypes.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/dataTypes.js b/src/util/dataTypes.js index 6a7f067a0..6f66849d0 100644 --- a/src/util/dataTypes.js +++ b/src/util/dataTypes.js @@ -3,11 +3,12 @@ import { parseBoxShadowValue } from './parseBoxShadowValue' import { splitAtTopLevelOnly } from './splitAtTopLevelOnly' let cssFunctions = ['min', 'max', 'clamp', 'calc'] +let IS_CSS_FN = new RegExp(`^(${cssFunctions.join('|')})\\(.*\\)`) // Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types function isCSSFunction(value) { - return cssFunctions.some((fn) => new RegExp(`^${fn}\\(.*\\)`).test(value)) + return IS_CSS_FN.test(value) } // This is not a data type, but rather a function that can normalize the