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
41
src/value-parser/stringify.js
Normal file
41
src/value-parser/stringify.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
function stringifyNode(node, custom) {
|
||||
var type = node.type
|
||||
var value = node.value
|
||||
var buf
|
||||
var customResult
|
||||
|
||||
if (custom && (customResult = custom(node)) !== undefined) {
|
||||
return customResult
|
||||
} else if (type === 'word' || type === 'space') {
|
||||
return value
|
||||
} else if (type === 'string') {
|
||||
buf = node.quote || ''
|
||||
return buf + value + (node.unclosed ? '' : buf)
|
||||
} else if (type === 'comment') {
|
||||
return '/*' + value + (node.unclosed ? '' : '*/')
|
||||
} else if (type === 'div') {
|
||||
return (node.before || '') + value + (node.after || '')
|
||||
} else if (Array.isArray(node.nodes)) {
|
||||
buf = stringify(node.nodes, custom)
|
||||
if (type !== 'function') {
|
||||
return buf
|
||||
}
|
||||
return value + '(' + (node.before || '') + buf + (node.after || '') + (node.unclosed ? '' : ')')
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
function stringify(nodes, custom) {
|
||||
var result, i
|
||||
|
||||
if (Array.isArray(nodes)) {
|
||||
result = ''
|
||||
for (i = nodes.length - 1; ~i; i -= 1) {
|
||||
result = stringifyNode(nodes[i], custom) + result
|
||||
}
|
||||
return result
|
||||
}
|
||||
return stringifyNode(nodes, custom)
|
||||
}
|
||||
|
||||
module.exports = stringify
|
||||
Loading…
Add table
Add a link
Reference in a new issue