@@ -63,6 +63,13 @@ export function parse (
63
63
let inPre = false
64
64
let warned = false
65
65
66
+ function warnOnce ( msg ) {
67
+ if ( ! warned ) {
68
+ warned = true
69
+ warn ( msg )
70
+ }
71
+ }
72
+
66
73
function endPre ( element ) {
67
74
// check pre state
68
75
if ( element . pre ) {
@@ -146,17 +153,15 @@ export function parse (
146
153
}
147
154
148
155
function checkRootConstraints ( el ) {
149
- if ( process . env . NODE_ENV !== 'production' && ! warned ) {
156
+ if ( process . env . NODE_ENV !== 'production' ) {
150
157
if ( el . tag === 'slot' || el . tag === 'template' ) {
151
- warned = true
152
- warn (
158
+ warnOnce (
153
159
`Cannot use <${ el . tag } > as component root element because it may ` +
154
160
'contain multiple nodes.'
155
161
)
156
162
}
157
163
if ( el . attrsMap . hasOwnProperty ( 'v-for' ) ) {
158
- warned = true
159
- warn (
164
+ warnOnce (
160
165
'Cannot use v-for on stateful component root element because ' +
161
166
'it renders multiple elements.'
162
167
)
@@ -176,9 +181,8 @@ export function parse (
176
181
exp : element . elseif ,
177
182
block : element
178
183
} )
179
- } else if ( process . env . NODE_ENV !== 'production' && ! warned ) {
180
- warned = true
181
- warn (
184
+ } else if ( process . env . NODE_ENV !== 'production' ) {
185
+ warnOnce (
182
186
`Component template should contain exactly one root element. ` +
183
187
`If you are using v-if on multiple elements, ` +
184
188
`use v-else-if to chain them instead.`
@@ -224,11 +228,16 @@ export function parse (
224
228
225
229
chars ( text : string ) {
226
230
if ( ! currentParent ) {
227
- if ( process . env . NODE_ENV !== 'production' && ! warned && text === template ) {
228
- warned = true
229
- warn (
230
- 'Component template requires a root element, rather than just text.'
231
- )
231
+ if ( process . env . NODE_ENV !== 'production' ) {
232
+ if ( text === template ) {
233
+ warnOnce (
234
+ 'Component template requires a root element, rather than just text.'
235
+ )
236
+ } else if ( ( text = text . trim ( ) ) ) {
237
+ warnOnce (
238
+ `text "${ text } " outside root element will be ignored.`
239
+ )
240
+ }
232
241
}
233
242
return
234
243
}
0 commit comments