dom-props.js
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* @flow */
import VNode from 'core/vdom/vnode'
import { renderAttr } from './attrs'
import { isDef, isUndef, extend } from 'shared/util'
import { propsToAttrMap, isRenderableAttr } from '../util'
export default function renderDOMProps (node: VNodeWithData): string {
let props = node.data.domProps
let res = ''
let parent = node.parent
while (isDef(parent)) {
if (parent.data && parent.data.domProps) {
props = extend(extend({}, props), parent.data.domProps)
}
parent = parent.parent
}
if (isUndef(props)) {
return res
}
const attrs = node.data.attrs
for (const key in props) {
if (key === 'innerHTML') {
setText(node, props[key], true)
} else if (key === 'textContent') {
setText(node, props[key], false)
} else if (key === 'value' && node.tag === 'textarea') {
setText(node, props[key], false)
} else {
// $flow-disable-line (WTF?)
const attr = propsToAttrMap[key] || key.toLowerCase()
if (isRenderableAttr(attr) &&
// avoid rendering double-bound props/attrs twice
!(isDef(attrs) && isDef(attrs[attr]))
) {
res += renderAttr(attr, props[key])
}
}
}
return res
}
function setText (node, text, raw) {
const child = new VNode(undefined, undefined, undefined, text)
child.raw = raw
node.children = [child]
}