@@ -46,7 +46,7 @@ export default function visitElement ( generator, block, state, node ) {
46
46
block . builders . create . addLine ( `${ generator . helper ( 'setAttribute' ) } ( ${ name } , '${ generator . cssId } ', '' );` ) ;
47
47
}
48
48
49
- function visitAttributes ( ) {
49
+ function visitAttributesAndAddProps ( ) {
50
50
let intro ;
51
51
let outro ;
52
52
@@ -63,6 +63,37 @@ export default function visitElement ( generator, block, state, node ) {
63
63
} ) ;
64
64
65
65
if ( intro || outro ) addTransitions ( generator , block , childState , node , intro , outro ) ;
66
+
67
+ if ( childState . allUsedContexts . length || childState . usesComponent ) {
68
+ const initialProps = [ ] ;
69
+ const updates = [ ] ;
70
+
71
+ if ( childState . usesComponent ) {
72
+ initialProps . push ( `component: ${ block . component } ` ) ;
73
+ }
74
+
75
+ childState . allUsedContexts . forEach ( contextName => {
76
+ if ( contextName === 'state' ) return ;
77
+
78
+ const listName = block . listNames . get ( contextName ) ;
79
+ const indexName = block . indexNames . get ( contextName ) ;
80
+
81
+ initialProps . push ( `${ listName } : ${ listName } ,\n${ indexName } : ${ indexName } ` ) ;
82
+ updates . push ( `${ name } ._svelte.${ listName } = ${ listName } ;\n${ name } ._svelte.${ indexName } = ${ indexName } ;` ) ;
83
+ } ) ;
84
+
85
+ if ( initialProps . length ) {
86
+ block . builders . create . addBlock ( deindent `
87
+ ${ name } ._svelte = {
88
+ ${ initialProps . join ( ',\n' ) }
89
+ };
90
+ ` ) ;
91
+ }
92
+
93
+ if ( updates . length ) {
94
+ block . builders . update . addBlock ( updates . join ( '\n' ) ) ;
95
+ }
96
+ }
66
97
}
67
98
68
99
if ( ! state . parentNode ) {
@@ -74,7 +105,7 @@ export default function visitElement ( generator, block, state, node ) {
74
105
if ( node . name !== 'select' ) {
75
106
// <select> value attributes are an annoying special case — it must be handled
76
107
// *after* its children have been updated
77
- visitAttributes ( ) ;
108
+ visitAttributesAndAddProps ( ) ;
78
109
}
79
110
80
111
// special case – bound <option> without a value attribute
@@ -83,37 +114,6 @@ export default function visitElement ( generator, block, state, node ) {
83
114
node . initialUpdate = node . lateUpdate = statement ;
84
115
}
85
116
86
- if ( childState . allUsedContexts . length || childState . usesComponent ) {
87
- const initialProps = [ ] ;
88
- const updates = [ ] ;
89
-
90
- if ( childState . usesComponent ) {
91
- initialProps . push ( `component: ${ block . component } ` ) ;
92
- }
93
-
94
- childState . allUsedContexts . forEach ( contextName => {
95
- if ( contextName === 'state' ) return ;
96
-
97
- const listName = block . listNames . get ( contextName ) ;
98
- const indexName = block . indexNames . get ( contextName ) ;
99
-
100
- initialProps . push ( `${ listName } : ${ listName } ,\n${ indexName } : ${ indexName } ` ) ;
101
- updates . push ( `${ name } ._svelte.${ listName } = ${ listName } ;\n${ name } ._svelte.${ indexName } = ${ indexName } ;` ) ;
102
- } ) ;
103
-
104
- if ( initialProps . length ) {
105
- block . builders . create . addBlock ( deindent `
106
- ${ name } ._svelte = {
107
- ${ initialProps . join ( ',\n' ) }
108
- };
109
- ` ) ;
110
- }
111
-
112
- if ( updates . length ) {
113
- block . builders . update . addBlock ( updates . join ( '\n' ) ) ;
114
- }
115
- }
116
-
117
117
node . children . forEach ( child => {
118
118
visit ( generator , block , childState , child ) ;
119
119
} ) ;
@@ -123,7 +123,7 @@ export default function visitElement ( generator, block, state, node ) {
123
123
}
124
124
125
125
if ( node . name === 'select' ) {
126
- visitAttributes ( ) ;
126
+ visitAttributesAndAddProps ( ) ;
127
127
}
128
128
129
129
if ( node . initialUpdate ) {
0 commit comments