44} from '../../parsers/template'
55
66import {
7+ extend ,
78 extractContent ,
89 replace ,
910 remove ,
@@ -15,60 +16,46 @@ import {
1516// instance being stored as `$options._content` during
1617// the transclude phase.
1718
18- export default {
19+ // We are exporting two versions, one for named and one
20+ // for unnamed, because the unnamed slots must be compiled
21+ // AFTER all named slots have selected their content. So
22+ // we need to give them different priorities in the compilation
23+ // process. (See #1965)
1924
20- priority : 1750 ,
25+ export const slot = {
2126
22- params : [ 'name' ] ,
27+ priority : 1750 ,
2328
2429 bind ( ) {
2530 var host = this . vm
2631 var raw = host . $options . _content
27- var content
2832 if ( ! raw ) {
2933 this . fallback ( )
3034 return
3135 }
3236 var context = host . _context
33- var slotName = this . params . name
37+ var slotName = this . params && this . params . name
3438 if ( ! slotName ) {
35- // Default content
36- var self = this
37- var compileDefaultContent = function ( ) {
38- var content = extractFragment ( raw . childNodes , raw , true )
39- if ( content . hasChildNodes ( ) ) {
40- self . compile ( content , context , host )
41- } else {
42- self . fallback ( )
43- }
44- }
45- if ( ! host . _isCompiled ) {
46- // defer until the end of instance compilation,
47- // because the default outlet must wait until all
48- // other possible outlets with selectors have picked
49- // out their contents.
50- host . $once ( 'hook:compiled' , compileDefaultContent )
51- } else {
52- compileDefaultContent ( )
53- }
39+ // Default slot
40+ this . tryCompile ( extractFragment ( raw . childNodes , raw , true ) , context , host )
5441 } else {
42+ // Named slot
5543 var selector = '[slot="' + slotName + '"]'
5644 var nodes = raw . querySelectorAll ( selector )
5745 if ( nodes . length ) {
58- content = extractFragment ( nodes , raw )
59- if ( content . hasChildNodes ( ) ) {
60- this . compile ( content , context , host )
61- } else {
62- this . fallback ( )
63- }
46+ this . tryCompile ( extractFragment ( nodes , raw ) , context , host )
6447 } else {
6548 this . fallback ( )
6649 }
6750 }
6851 } ,
6952
70- fallback ( ) {
71- this . compile ( extractContent ( this . el , true ) , this . vm )
53+ tryCompile ( content , context , host ) {
54+ if ( content . hasChildNodes ( ) ) {
55+ this . compile ( content , context , host )
56+ } else {
57+ this . fallback ( )
58+ }
7259 } ,
7360
7461 compile ( content , context , host ) {
@@ -87,13 +74,22 @@ export default {
8774 }
8875 } ,
8976
77+ fallback ( ) {
78+ this . compile ( extractContent ( this . el , true ) , this . vm )
79+ } ,
80+
9081 unbind ( ) {
9182 if ( this . unlink ) {
9283 this . unlink ( )
9384 }
9485 }
9586}
9687
88+ export const namedSlot = extend ( extend ( { } , slot ) , {
89+ priority : slot . priority + 1 ,
90+ params : [ 'name' ]
91+ } )
92+
9793/**
9894 * Extract qualified content nodes from a node list.
9995 *
0 commit comments