fix(compiler-dom): properly stringify class/style bindings when hoisting static strings
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { isArray, isString, isObject } from './'
|
||||
import { isArray, isString, isObject, hyphenate } from './'
|
||||
import { isNoUnitNumericStyleProp } from './domAttrConfig'
|
||||
|
||||
export function normalizeStyle(
|
||||
value: unknown
|
||||
@@ -19,6 +20,27 @@ export function normalizeStyle(
|
||||
}
|
||||
}
|
||||
|
||||
export function stringifyStyle(
|
||||
styles: Record<string, string | number> | undefined
|
||||
): string {
|
||||
let ret = ''
|
||||
if (!styles) {
|
||||
return ret
|
||||
}
|
||||
for (const key in styles) {
|
||||
const value = styles[key]
|
||||
const normalizedKey = key.indexOf(`--`) === 0 ? key : hyphenate(key)
|
||||
if (
|
||||
isString(value) ||
|
||||
(typeof value === 'number' && isNoUnitNumericStyleProp(normalizedKey))
|
||||
) {
|
||||
// only render valid values
|
||||
ret += `${normalizedKey}:${value};`
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function normalizeClass(value: unknown): string {
|
||||
let res = ''
|
||||
if (isString(value)) {
|
||||
|
||||
Reference in New Issue
Block a user