|
1 | 1 | export function createComponentDebugMixin() { |
2 | 2 | return { |
3 | 3 | mounted() { |
4 | | - if (process.env.NODE_ENV === 'development') { |
5 | | - const component = this.$options.__file || this.$options.__name || 'Anonymous'; |
| 4 | + if (process.env.NODE_ENV !== 'development') { |
| 5 | + return; |
| 6 | + } |
6 | 7 |
|
7 | | - const startComment = document.createComment(` Start component: ${component} `); |
8 | | - this.$el.parentNode?.insertBefore(startComment, this.$el); |
| 8 | + const component = this.$options.__file || this.$options.__name || 'Anonymous'; |
9 | 9 |
|
10 | | - const endComment = document.createComment(` End component: ${component} `); |
11 | | - this.$el.parentNode?.insertBefore(endComment, this.$el.nextSibling); |
12 | | - } |
| 10 | + const startComment = document.createComment(` Start component: ${component} `); |
| 11 | + this.$el.parentNode?.insertBefore(startComment, this.$el); |
| 12 | + |
| 13 | + const endComment = document.createComment(` End component: ${component} `); |
| 14 | + this.$el.parentNode?.insertBefore(endComment, this.$el.nextSibling); |
13 | 15 | }, |
14 | 16 | beforeUnmount() { |
15 | | - if (process.env.NODE_ENV === 'development') { |
16 | | - // Clean up comments when components are destroyed. |
17 | | - const component = this.$options.__file || this.$options.__name || 'Anonymous'; |
18 | | - const parent = this.$el.parentNode; |
| 17 | + if (process.env.NODE_ENV !== 'development') { |
| 18 | + return; |
| 19 | + } |
| 20 | + |
| 21 | + // Clean up comments when components are destroyed. |
| 22 | + const component = this.$options.__file || this.$options.__name || 'Anonymous'; |
| 23 | + const parent = this.$el.parentNode; |
19 | 24 |
|
20 | | - if (parent) { |
21 | | - let node = this.$el.previousSibling; |
22 | | - while (node && node.nodeType === Node.COMMENT_NODE) { |
23 | | - if (node.nodeValue === ` Start component: ${component} `) { |
24 | | - parent.removeChild(node); |
25 | | - break; |
26 | | - } |
27 | | - node = node.previousSibling; |
| 25 | + if (parent) { |
| 26 | + let node = this.$el.previousSibling; |
| 27 | + while (node && node.nodeType === Node.COMMENT_NODE) { |
| 28 | + if (node.nodeValue === ` Start component: ${component} `) { |
| 29 | + parent.removeChild(node); |
| 30 | + break; |
28 | 31 | } |
| 32 | + node = node.previousSibling; |
| 33 | + } |
29 | 34 |
|
30 | | - node = this.$el.nextSibling; |
31 | | - while (node && node.nodeType === Node.COMMENT_NODE) { |
32 | | - if (node.nodeValue === ` End component: ${component} `) { |
33 | | - parent.removeChild(node); |
34 | | - break; |
35 | | - } |
36 | | - node = node.nextSibling; |
| 35 | + node = this.$el.nextSibling; |
| 36 | + while (node && node.nodeType === Node.COMMENT_NODE) { |
| 37 | + if (node.nodeValue === ` End component: ${component} `) { |
| 38 | + parent.removeChild(node); |
| 39 | + break; |
37 | 40 | } |
| 41 | + node = node.nextSibling; |
38 | 42 | } |
39 | 43 | } |
40 | 44 | }, |
|
0 commit comments