props.js
973 Bytes
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
/* @flow */
import { cached, camelize } from 'shared/util'
const normalize = cached(camelize)
function normalizeKeyName (str: string): string {
if (str.match(/^v\-/)) {
return str.replace(/(v-[a-z\-]+\:)([a-z\-]+)$/i, ($, directive, prop) => {
return directive + normalize(prop)
})
}
return normalize(str)
}
function transformNode (el: ASTElement) {
if (Array.isArray(el.attrsList)) {
el.attrsList.forEach(attr => {
if (attr.name && attr.name.match(/\-/)) {
const realName = normalizeKeyName(attr.name)
if (el.attrsMap) {
el.attrsMap[realName] = el.attrsMap[attr.name]
delete el.attrsMap[attr.name]
}
if (el.rawAttrsMap && el.rawAttrsMap[attr.name]) {
el.rawAttrsMap[realName] = el.rawAttrsMap[attr.name]
// $flow-disable-line
delete el.rawAttrsMap[attr.name]
}
attr.name = realName
}
})
}
}
export default {
transformNode
}