Fix parsing of theme() inside calc() when there are no spaces around operators (#11157)
* Refactor * Don’t resolve functions for anything not using theme or screen * Normalize math operators inside calc when handling functions * Inline postcss-value-parser * Treat all functions the same as calc * Remove workaround for calc + operators without spaces * Remove `postcss-value-parser` dependency * Update lockfile * Update sourcemaps * Update changelog * Update `value-parser` formatting * Stop prettier from complaining
This commit is contained in:
parent
cdca9cbcfe
commit
960cb40c6b
17 changed files with 893 additions and 145 deletions
|
|
@ -49,10 +49,22 @@ export function normalize(value, isRoot = true) {
|
|||
value = value.trim()
|
||||
}
|
||||
|
||||
// Add spaces around operators inside math functions like calc() that do not follow an operator
|
||||
// or '('.
|
||||
value = value.replace(/(calc|min|max|clamp)\(.+\)/g, (match) => {
|
||||
value = normalizeMathOperatorSpacing(value)
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Add spaces around operators inside math functions
|
||||
* like calc() that do not follow an operator or '('.
|
||||
*
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
function normalizeMathOperatorSpacing(value) {
|
||||
return value.replace(/(calc|min|max|clamp)\(.+\)/g, (match) => {
|
||||
let vars = []
|
||||
|
||||
return match
|
||||
.replace(/var\((--.+?)[,)]/g, (match, g1) => {
|
||||
vars.push(g1)
|
||||
|
|
@ -61,8 +73,6 @@ export function normalize(value, isRoot = true) {
|
|||
.replace(/(-?\d*\.?\d(?!\b-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ')
|
||||
.replace(placeholderRe, () => vars.shift())
|
||||
})
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
export function url(value) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue