@@ -63,6 +63,13 @@ export function parse (
6363 let inPre = false
6464 let warned = false
6565
66+ function warnOnce ( msg ) {
67+ if ( ! warned ) {
68+ warned = true
69+ warn ( msg )
70+ }
71+ }
72+
6673 function endPre ( element ) {
6774 // check pre state
6875 if ( element . pre ) {
@@ -146,17 +153,15 @@ export function parse (
146153 }
147154
148155 function checkRootConstraints ( el ) {
149- if ( process . env . NODE_ENV !== 'production' && ! warned ) {
156+ if ( process . env . NODE_ENV !== 'production' ) {
150157 if ( el . tag === 'slot' || el . tag === 'template' ) {
151- warned = true
152- warn (
158+ warnOnce (
153159 `Cannot use <${ el . tag } > as component root element because it may ` +
154160 'contain multiple nodes.'
155161 )
156162 }
157163 if ( el . attrsMap . hasOwnProperty ( 'v-for' ) ) {
158- warned = true
159- warn (
164+ warnOnce (
160165 'Cannot use v-for on stateful component root element because ' +
161166 'it renders multiple elements.'
162167 )
@@ -176,9 +181,8 @@ export function parse (
176181 exp : element . elseif ,
177182 block : element
178183 } )
179- } else if ( process . env . NODE_ENV !== 'production' && ! warned ) {
180- warned = true
181- warn (
184+ } else if ( process . env . NODE_ENV !== 'production' ) {
185+ warnOnce (
182186 `Component template should contain exactly one root element. ` +
183187 `If you are using v-if on multiple elements, ` +
184188 `use v-else-if to chain them instead.`
@@ -224,11 +228,16 @@ export function parse (
224228
225229 chars ( text : string ) {
226230 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+ }
232241 }
233242 return
234243 }
0 commit comments