Speed up CSS math function check (#12215)

* perf(cssMathFnRE): Dynamically create regular rules

* Cleanup code

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
This commit is contained in:
Simon He 2023-10-17 08:18:17 +08:00 • committed by GitHub
parent 44fb67b98d
commit e9ca7ab453
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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