@@ -34,6 +34,7 @@ let preTransforms
34
34
let transforms
35
35
let postTransforms
36
36
let delimiters
37
+ let seenSlots : any
37
38
38
39
/**
39
40
* Convert HTML string to AST.
@@ -50,6 +51,7 @@ export function parse (
50
51
transforms = pluckModuleFunction ( options . modules , 'transformNode' )
51
52
postTransforms = pluckModuleFunction ( options . modules , 'postTransformNode' )
52
53
delimiters = options . delimiters
54
+ seenSlots = Object . create ( null )
53
55
const stack = [ ]
54
56
const preserveWhitespace = options . preserveWhitespace !== false
55
57
let root
@@ -265,14 +267,7 @@ function processRef (el) {
265
267
const ref = getBindingAttr ( el , 'ref' )
266
268
if ( ref ) {
267
269
el . ref = ref
268
- let parent = el
269
- while ( parent ) {
270
- if ( parent . for !== undefined ) {
271
- el . refInFor = true
272
- break
273
- }
274
- parent = parent . parent
275
- }
270
+ el . refInFor = checkInFor ( el )
276
271
}
277
272
}
278
273
@@ -331,7 +326,25 @@ function processOnce (el) {
331
326
332
327
function processSlot ( el ) {
333
328
if ( el . tag === 'slot' ) {
329
+ if ( process . env . NODE_ENV !== 'production' ) {
330
+ if ( ! el . attrsMap [ ':name' ] && ! el . attrsMap [ 'v-bind:name' ] && checkInFor ( el ) ) {
331
+ warn (
332
+ 'Static <slot> found inside v-for: they will not render correctly. ' +
333
+ 'Render the list in parent scope and use a single <slot> instead.'
334
+ )
335
+ }
336
+ }
334
337
el . slotName = getBindingAttr ( el , 'name' )
338
+ if ( process . env . NODE_ENV !== 'production' ) {
339
+ const name = el . slotName
340
+ if ( seenSlots [ name ] ) {
341
+ warn (
342
+ `Duplicate ${ name ? `<slot> with name ${ name } ` : `default <slot>` } ` +
343
+ `found in the same template.`
344
+ )
345
+ }
346
+ seenSlots [ name ] = true
347
+ }
335
348
} else {
336
349
const slotTarget = getBindingAttr ( el , 'slot' )
337
350
if ( slotTarget ) {
@@ -405,6 +418,17 @@ function processAttrs (el) {
405
418
}
406
419
}
407
420
421
+ function checkInFor ( el : ASTElement ) : boolean {
422
+ let parent = el
423
+ while ( parent ) {
424
+ if ( parent . for !== undefined ) {
425
+ return true
426
+ }
427
+ parent = parent . parent
428
+ }
429
+ return false
430
+ }
431
+
408
432
function parseModifiers ( name : string ) : Object | void {
409
433
const match = name . match ( modifierRE )
410
434
if ( match ) {
0 commit comments