@@ -39,72 +39,27 @@ module.exports = {
39
39
40
40
const hasSrc = utils . hasAttribute ( element , 'src' )
41
41
const rootElements = [ ]
42
- let extraText = null
43
- let extraElement = null
44
- let vIf = false
42
+
45
43
for ( const child of element . children ) {
46
- if ( child . type === 'VElement' ) {
47
- if ( rootElements . length === 0 && ! hasSrc ) {
48
- rootElements . push ( child )
49
- vIf = utils . hasDirective ( child , 'if' )
50
- } else if ( vIf && utils . hasDirective ( child , 'else-if' ) ) {
51
- rootElements . push ( child )
52
- } else if ( vIf && utils . hasDirective ( child , 'else' ) ) {
53
- rootElements . push ( child )
54
- vIf = false
55
- } else {
56
- extraElement = child
57
- }
58
- } else if ( sourceCode . getText ( child ) . trim ( ) !== '' ) {
59
- extraText = child
44
+ if ( sourceCode . getText ( child ) . trim ( ) !== '' ) {
45
+ rootElements . push ( child )
60
46
}
61
47
}
62
48
63
- if ( hasSrc && ( extraText != null || extraElement != null ) ) {
64
- context . report ( {
65
- node : extraText || extraElement ,
66
- loc : ( extraText || extraElement ) . loc ,
67
- message : "The template root with 'src' attribute is required to be empty."
68
- } )
69
- } else if ( extraText != null ) {
70
- context . report ( {
71
- node : extraText ,
72
- loc : extraText . loc ,
73
- message : 'The template root requires an element rather than texts.'
74
- } )
75
- } else if ( extraElement != null ) {
76
- context . report ( {
77
- node : extraElement ,
78
- loc : extraElement . loc ,
79
- message : 'The template root requires exactly one element.'
80
- } )
49
+ if ( hasSrc && rootElements . length ) {
50
+ for ( const element of rootElements ) {
51
+ context . report ( {
52
+ node : element ,
53
+ loc : element . loc ,
54
+ message : "The template root with 'src' attribute is required to be empty."
55
+ } )
56
+ }
81
57
} else if ( rootElements . length === 0 && ! hasSrc ) {
82
58
context . report ( {
83
59
node : element ,
84
60
loc : element . loc ,
85
- message : 'The template root requires exactly one element.'
61
+ message : 'The template requires child element.'
86
62
} )
87
- } else {
88
- for ( const element of rootElements ) {
89
- const tag = element . startTag
90
- const name = element . name
91
-
92
- if ( name === 'template' || name === 'slot' ) {
93
- context . report ( {
94
- node : tag ,
95
- loc : tag . loc ,
96
- message : "The template root disallows '<{{name}}>' elements." ,
97
- data : { name }
98
- } )
99
- }
100
- if ( utils . hasDirective ( element , 'for' ) ) {
101
- context . report ( {
102
- node : tag ,
103
- loc : tag . loc ,
104
- message : "The template root disallows 'v-for' directives."
105
- } )
106
- }
107
- }
108
63
}
109
64
}
110
65
}
0 commit comments