File tree 3 files changed +98
-30
lines changed
3 files changed +98
-30
lines changed Original file line number Diff line number Diff line change 1
1
import config from '../config'
2
2
import { noop } from 'shared/util'
3
3
4
- let warn = noop
5
- let tip = noop
6
- let formatComponentName
4
+ export let warn = noop
5
+ export let tip = noop
6
+ export let formatComponentName
7
7
8
8
if ( process . env . NODE_ENV !== 'production' ) {
9
9
const hasConsole = typeof console !== 'undefined'
@@ -52,8 +52,18 @@ if (process.env.NODE_ENV !== 'production') {
52
52
)
53
53
}
54
54
55
+ const repeat = ( str , n ) => {
56
+ let res = ''
57
+ while ( n ) {
58
+ if ( n % 2 === 1 ) res += str
59
+ if ( n > 1 ) str += str
60
+ n >>= 1
61
+ }
62
+ return res
63
+ }
64
+
55
65
const generateComponentTrace = vm => {
56
- if ( vm . _isVue && vm . $parent && String . prototype . repeat ) {
66
+ if ( vm . _isVue && vm . $parent ) {
57
67
const tree = [ ]
58
68
let currentRecursiveSequence = 0
59
69
while ( vm ) {
@@ -73,7 +83,7 @@ if (process.env.NODE_ENV !== 'production') {
73
83
}
74
84
return '\n\nfound in\n\n' + tree
75
85
. map ( ( vm , i ) => `${
76
- i === 0 ? '---> ' : ' ' . repeat ( 5 + i * 2 )
86
+ i === 0 ? '---> ' : repeat ( ' ' , 5 + i * 2 )
77
87
} ${
78
88
Array . isArray ( vm )
79
89
? `${ formatComponentName ( vm [ 0 ] ) } ... (${ vm [ 1 ] } recursive calls)`
@@ -85,5 +95,3 @@ if (process.env.NODE_ENV !== 'production') {
85
95
}
86
96
}
87
97
}
88
-
89
- export { warn , tip , formatComponentName }
Original file line number Diff line number Diff line change
1
+ import Vue from 'vue'
2
+ import { formatComponentName } from 'core/util/debug'
3
+
4
+ describe ( 'Debug utilities' , ( ) => {
5
+ it ( 'properly format component names' , ( ) => {
6
+ const vm = new Vue ( )
7
+ expect ( formatComponentName ( vm ) ) . toBe ( '<Root>' )
8
+
9
+ vm . $root = null
10
+ vm . $options . name = 'hello-there'
11
+ expect ( formatComponentName ( vm ) ) . toBe ( '<HelloThere>' )
12
+
13
+ vm . $options . name = null
14
+ vm . $options . _componentTag = 'foo-bar-1'
15
+ expect ( formatComponentName ( vm ) ) . toBe ( '<FooBar1>' )
16
+
17
+ vm . $options . _componentTag = null
18
+ vm . $options . __file = '/foo/bar/baz/SomeThing.vue'
19
+ expect ( formatComponentName ( vm ) ) . toBe ( `<SomeThing> at ${ vm . $options . __file } ` )
20
+ expect ( formatComponentName ( vm , false ) ) . toBe ( '<SomeThing>' )
21
+
22
+ vm . $options . __file = 'C:\\foo\\bar\\baz\\windows_file.vue'
23
+ expect ( formatComponentName ( vm ) ) . toBe ( `<WindowsFile> at ${ vm . $options . __file } ` )
24
+ expect ( formatComponentName ( vm , false ) ) . toBe ( '<WindowsFile>' )
25
+ } )
26
+
27
+ it ( 'generate correct component hierarchy trace' , ( ) => {
28
+ const one = {
29
+ name : 'one' ,
30
+ render : h => h ( two )
31
+ }
32
+ const two = {
33
+ name : 'two' ,
34
+ render : h => h ( three )
35
+ }
36
+ const three = {
37
+ name : 'three'
38
+ }
39
+ new Vue ( {
40
+ render : h => h ( one )
41
+ } ) . $mount ( )
42
+
43
+ expect (
44
+ `Failed to mount component: template or render function not defined.
45
+
46
+ found in
47
+
48
+ ---> <Three>
49
+ <Two>
50
+ <One>
51
+ <Root>`
52
+ ) . toHaveBeenWarned ( )
53
+ } )
54
+
55
+ it ( 'generate correct component hierarchy trace (recursive)' , ( ) => {
56
+ let i = 0
57
+ const one = {
58
+ name : 'one' ,
59
+ render : h => i ++ < 5 ? h ( one ) : h ( two )
60
+ }
61
+ const two = {
62
+ name : 'two' ,
63
+ render : h => h ( three )
64
+ }
65
+ const three = {
66
+ name : 'three'
67
+ }
68
+ new Vue ( {
69
+ render : h => h ( one )
70
+ } ) . $mount ( )
71
+
72
+ expect (
73
+ `Failed to mount component: template or render function not defined.
74
+
75
+ found in
76
+
77
+ ---> <Three>
78
+ <Two>
79
+ <One>... (5 recursive calls)
80
+ <Root>`
81
+ ) . toHaveBeenWarned ( )
82
+ } )
83
+ } )
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
- import { formatComponentName } from 'core/util/debug'
3
2
4
3
const components = createErrorTestComponents ( )
5
4
@@ -124,28 +123,6 @@ describe('Error handling', () => {
124
123
} )
125
124
} )
126
125
} )
127
-
128
- it ( 'properly format component names' , ( ) => {
129
- const vm = new Vue ( )
130
- expect ( formatComponentName ( vm ) ) . toBe ( '<Root>' )
131
-
132
- vm . $root = null
133
- vm . $options . name = 'hello-there'
134
- expect ( formatComponentName ( vm ) ) . toBe ( '<HelloThere>' )
135
-
136
- vm . $options . name = null
137
- vm . $options . _componentTag = 'foo-bar-1'
138
- expect ( formatComponentName ( vm ) ) . toBe ( '<FooBar1>' )
139
-
140
- vm . $options . _componentTag = null
141
- vm . $options . __file = '/foo/bar/baz/SomeThing.vue'
142
- expect ( formatComponentName ( vm ) ) . toBe ( `<SomeThing> at ${ vm . $options . __file } ` )
143
- expect ( formatComponentName ( vm , false ) ) . toBe ( '<SomeThing>' )
144
-
145
- vm . $options . __file = 'C:\\foo\\bar\\baz\\windows_file.vue'
146
- expect ( formatComponentName ( vm ) ) . toBe ( `<WindowsFile> at ${ vm . $options . __file } ` )
147
- expect ( formatComponentName ( vm , false ) ) . toBe ( '<WindowsFile>' )
148
- } )
149
126
} )
150
127
151
128
function createErrorTestComponents ( ) {
You can’t perform that action at this time.
0 commit comments