|
1 | 1 | /* @flow */
|
2 | 2 |
|
3 |
| -import { isDef, isUndef, isObject } from 'shared/util' |
| 3 | +import { isDef, isObject } from 'shared/util' |
4 | 4 |
|
5 | 5 | export function genClassForVnode (vnode: VNode): string {
|
6 | 6 | let data = vnode.data
|
@@ -48,31 +48,38 @@ export function concat (a: ?string, b: ?string): string {
|
48 | 48 | }
|
49 | 49 |
|
50 | 50 | export function stringifyClass (value: any): string {
|
51 |
| - if (isUndef(value)) { |
52 |
| - return '' |
| 51 | + if (Array.isArray(value)) { |
| 52 | + return stringifyArray(value) |
| 53 | + } |
| 54 | + if (isObject(value)) { |
| 55 | + return stringifyObject(value) |
53 | 56 | }
|
54 | 57 | if (typeof value === 'string') {
|
55 | 58 | return value
|
56 | 59 | }
|
| 60 | + /* istanbul ignore next */ |
| 61 | + return '' |
| 62 | +} |
| 63 | + |
| 64 | +function stringifyArray (value: Array<any>): string { |
57 | 65 | let res = ''
|
58 |
| - if (Array.isArray(value)) { |
59 |
| - let stringified |
60 |
| - for (let i = 0, l = value.length; i < l; i++) { |
61 |
| - if (isDef(value[i])) { |
62 |
| - if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') { |
63 |
| - res += stringified + ' ' |
64 |
| - } |
65 |
| - } |
| 66 | + let stringified |
| 67 | + for (let i = 0, l = value.length; i < l; i++) { |
| 68 | + if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') { |
| 69 | + if (res) res += ' ' |
| 70 | + res += stringified |
66 | 71 | }
|
67 |
| - return res.slice(0, -1) |
68 | 72 | }
|
69 |
| - if (isObject(value)) { |
70 |
| - for (const key in value) { |
| 73 | + return res |
| 74 | +} |
| 75 | + |
| 76 | +function stringifyObject (value: Object): string { |
| 77 | + let res = '' |
| 78 | + for (const key in value) { |
| 79 | + if (value[key]) { |
71 | 80 | if (res) res += ' '
|
72 |
| - if (value[key]) res += key |
| 81 | + res += key |
73 | 82 | }
|
74 |
| - return res |
75 | 83 | }
|
76 |
| - /* istanbul ignore next */ |
77 | 84 | return res
|
78 | 85 | }
|
0 commit comments