fix(compiler-dom): properly stringify class/style bindings when hoisting static strings

This commit is contained in:
Evan You
2020-02-21 13:10:13 +01:00
parent 189a0a3b19
commit 1b9b235663
11 changed files with 57 additions and 58 deletions

View File

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