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,11 +1,9 @@
import { escapeHtml } from '@vue/shared'
import { escapeHtml, stringifyStyle } from '@vue/shared'
import {
normalizeClass,
normalizeStyle,
propsToAttrMap,
hyphenate,
isString,
isNoUnitNumericStyleProp,
isOn,
isSSRSafeAttrName,
isBooleanAttr,
@@ -93,17 +91,5 @@ export function ssrRenderStyle(raw: unknown): string {
return escapeHtml(raw)
}
const styles = normalizeStyle(raw)
let 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 escapeHtml(ret)
return escapeHtml(stringifyStyle(styles))
}