@@ -5,7 +5,7 @@ import { parseHTML } from './html-parser'
5
5
import { parseText } from './text-parser'
6
6
import { parseFilters } from './filter-parser'
7
7
import { genAssignmentCode } from '../directives/model'
8
- import { extend , cached , no , camelize , hyphenate , hasOwn } from 'shared/util'
8
+ import { extend , cached , no , camelize , hyphenate } from 'shared/util'
9
9
import { isIE , isEdge , isServerRendering } from 'core/util/env'
10
10
11
11
import {
@@ -45,7 +45,6 @@ let postTransforms
45
45
let platformIsPreTag
46
46
let platformMustUseProp
47
47
let platformGetTagNamespace
48
- let maybeComponent
49
48
50
49
export function createASTElement (
51
50
tag : string ,
@@ -75,8 +74,6 @@ export function parse (
75
74
platformIsPreTag = options . isPreTag || no
76
75
platformMustUseProp = options . mustUseProp || no
77
76
platformGetTagNamespace = options . getTagNamespace || no
78
- const isReservedTag = options . isReservedTag || no
79
- maybeComponent = ( el : ASTElement ) => ! ! el . component || ! isReservedTag ( el . tag )
80
77
81
78
transforms = pluckModuleFunction ( options . modules , 'transformNode' )
82
79
preTransforms = pluckModuleFunction ( options . modules , 'preTransformNode' )
@@ -102,7 +99,7 @@ export function parse (
102
99
103
100
function closeElement ( element ) {
104
101
if ( ! inVPre && ! element . processed ) {
105
- element = processElement ( element , options )
102
+ element = processElement ( element , options , currentParent )
106
103
}
107
104
// tree management
108
105
if ( ! stack . length && element !== root ) {
@@ -156,7 +153,7 @@ export function parse (
156
153
{ start : el . start }
157
154
)
158
155
}
159
- if ( hasOwn ( el . attrsMap , 'v-for' ) ) {
156
+ if ( el . attrsMap . hasOwnProperty ( 'v-for' ) ) {
160
157
warnOnce (
161
158
'Cannot use v-for on stateful component root element because ' +
162
159
'it renders multiple elements.' ,
@@ -380,7 +377,8 @@ function processRawAttrs (el) {
380
377
381
378
export function processElement (
382
379
element : ASTElement ,
383
- options : CompilerOptions
380
+ options : CompilerOptions ,
381
+ parent : ASTElement | undefined
384
382
) {
385
383
processKey ( element )
386
384
@@ -393,7 +391,7 @@ export function processElement (
393
391
)
394
392
395
393
processRef ( element )
396
- processSlot ( element )
394
+ processSlot ( element , parent )
397
395
processComponent ( element )
398
396
for ( let i = 0 ; i < transforms . length ; i ++ ) {
399
397
element = transforms [ i ] ( element , options ) || element
@@ -584,86 +582,19 @@ function processSlot (el) {
584
582
)
585
583
}
586
584
el . slotScope = slotScope
587
- if ( process . env . NODE_ENV !== 'production' && nodeHas$Slot ( el ) ) {
588
- warn ( 'Unepxected mixed usage of `slot-scope` and `$slot`.' , el )
589
- }
590
- } else {
591
- // 2.6 $slot support
592
- // Context: https://github.com/vuejs/vue/issues/9180
593
- // Ideally, all slots should be compiled as functions (this is what we
594
- // are doing in 3.x), but for 2.x e want to preserve complete backwards
595
- // compatibility, and maintain the exact same compilation output for any
596
- // code that does not use the new syntax.
597
-
598
- // recursively check component children for presence of `$slot` in all
599
- // expressions until running into a nested child component.
600
- if ( maybeComponent ( el ) && childrenHas$Slot ( el ) ) {
601
- processScopedSlots ( el )
602
- }
603
585
}
604
586
const slotTarget = getBindingAttr ( el , 'slot' )
605
587
if ( slotTarget ) {
606
588
el . slotTarget = slotTarget === '""' ? '"default"' : slotTarget
607
589
// preserve slot as an attribute for native shadow DOM compat
608
590
// only for non-scoped slots.
609
- if ( el . tag !== 'template' && ! el . slotScope && ! nodeHas$Slot ( el ) ) {
591
+ if ( el . tag !== 'template' && ! el . slotScope ) {
610
592
addAttr ( el , 'slot' , slotTarget , getRawBindingAttr ( el , 'slot' ) )
611
593
}
612
594
}
613
595
}
614
596
}
615
597
616
- function childrenHas$Slot ( el ) : boolean {
617
- return el . children ? el . children . some ( nodeHas$Slot ) : false
618
- }
619
-
620
- const $slotRE = / ( ^ | [ ^ \w _ $ ] ) \$ s l o t ( $ | [ ^ \w _ $ ] ) /
621
- function nodeHas$Slot ( node ) : boolean {
622
- // caching
623
- if ( hasOwn ( node , 'has$Slot' ) ) {
624
- return ( node . has$Slot : any )
625
- }
626
- if ( node . type === 1 ) { // element
627
- for ( const key in node . attrsMap ) {
628
- if ( dirRE . test ( key ) && $slotRE . test ( node . attrsMap [ key ] ) ) {
629
- return ( node . has$Slot = true )
630
- }
631
- }
632
- return ( node . has$Slot = childrenHas$Slot ( node ) )
633
- } else if ( node . type === 2 ) { // expression
634
- // TODO more robust logic for checking $slot usage
635
- return ( node . has$Slot = $slotRE . test ( node . expression ) )
636
- }
637
- return false
638
- }
639
-
640
- function processScopedSlots ( el ) {
641
- // 1. group children by slot target
642
- const groups : any = { }
643
- for ( let i = 0 ; i < el . children . length ; i ++ ) {
644
- const child = el . children [ i ]
645
- const target = child . slotTarget || '"default"'
646
- if ( ! groups [ target ] ) {
647
- groups [ target ] = [ ]
648
- }
649
- groups [ target ] . push ( child )
650
- }
651
- // 2. for each slot group, check if the group contains $slot
652
- for ( const name in groups ) {
653
- const group = groups [ name ]
654
- if ( group . some ( nodeHas$Slot ) ) {
655
- // 3. if a group contains $slot, all nodes in that group gets assigned
656
- // as a scoped slot to el and removed from children
657
- el . plain = false
658
- const slots = el . scopedSlots || ( el . scopedSlots = { } )
659
- const slotContainer = slots [ name ] = createASTElement ( 'template' , [ ] , el )
660
- slotContainer . children = group
661
- slotContainer . slotScope = '$slot'
662
- el . children = el . children . filter ( c => group . indexOf ( c ) === - 1 )
663
- }
664
- }
665
- }
666
-
667
598
function processComponent ( el ) {
668
599
let binding
669
600
if ( ( binding = getBindingAttr ( el , 'is' ) ) ) {
0 commit comments