@@ -62,7 +62,6 @@ export function RegularElement(node, context) {
62
62
context . state . metadata . context . template_contains_script_tag = true ;
63
63
}
64
64
65
- const metadata = context . state . metadata ;
66
65
const child_metadata = {
67
66
...context . state . metadata ,
68
67
namespace : determine_namespace_for_children ( node , context . state . metadata . namespace )
@@ -79,6 +78,9 @@ export function RegularElement(node, context) {
79
78
/** @type {AST.StyleDirective[] } */
80
79
const style_directives = [ ] ;
81
80
81
+ /** @type {Array<AST.AnimateDirective | AST.BindDirective | AST.OnDirective | AST.TransitionDirective | AST.UseDirective } */
82
+ const other_directives = [ ] ;
83
+
82
84
/** @type {ExpressionStatement[] } */
83
85
const lets = [ ] ;
84
86
@@ -89,7 +91,7 @@ export function RegularElement(node, context) {
89
91
// custom element until the template is connected to the dom, which would
90
92
// cause problems when setting properties on the custom element.
91
93
// Therefore we need to use importNode instead, which doesn't have this caveat.
92
- metadata . context . template_needs_import_node = true ;
94
+ context . state . metadata . context . template_needs_import_node = true ;
93
95
}
94
96
95
97
/** @type {Map<string, AST.Attribute> } */
@@ -99,37 +101,62 @@ export function RegularElement(node, context) {
99
101
const bindings = new Map ( ) ;
100
102
101
103
let has_spread = false ;
104
+ let has_use = false ;
102
105
103
106
for ( const attribute of node . attributes ) {
104
- if ( attribute . type === 'SpreadAttribute' ) {
105
- has_spread = true ;
106
- } else if ( attribute . type === 'Attribute' ) {
107
- lookup . set ( attribute . name , attribute ) ;
108
- } else if ( attribute . type === 'BindDirective' ) {
109
- bindings . set ( attribute . name , attribute ) ;
110
- } else if ( attribute . type === 'LetDirective' ) {
111
- // visit let directives before everything else, to set state
112
- lets . push ( /** @type {ExpressionStatement } */ ( context . visit ( attribute ) ) ) ;
107
+ switch ( attribute . type ) {
108
+ case 'SpreadAttribute' :
109
+ attributes . push ( attribute ) ;
110
+ has_spread = true ;
111
+ break ;
112
+
113
+ case 'Attribute' :
114
+ attributes . push ( attribute ) ;
115
+ lookup . set ( attribute . name , attribute ) ;
116
+ break ;
117
+
118
+ case 'BindDirective' :
119
+ bindings . set ( attribute . name , attribute ) ;
120
+ other_directives . push ( attribute ) ;
121
+ break ;
122
+
123
+ case 'ClassDirective' :
124
+ class_directives . push ( attribute ) ;
125
+ break ;
126
+
127
+ case 'StyleDirective' :
128
+ style_directives . push ( attribute ) ;
129
+ break ;
130
+
131
+ case 'LetDirective' :
132
+ // visit let directives before everything else, to set state
133
+ lets . push ( /** @type {ExpressionStatement } */ ( context . visit ( attribute ) ) ) ;
134
+ break ;
135
+
136
+ case 'UseDirective' :
137
+ has_use = true ;
138
+ other_directives . push ( attribute ) ;
139
+ break ;
140
+
141
+ case 'OnDirective' :
142
+ other_directives . push ( attribute ) ;
143
+ break ;
144
+
145
+ case 'AnimateDirective' :
146
+ case 'TransitionDirective' :
147
+ other_directives . push ( attribute ) ;
148
+ break ;
113
149
}
114
150
}
115
151
116
- for ( const attribute of node . attributes ) {
117
- if ( attribute . type === 'Attribute' ) {
118
- attributes . push ( attribute ) ;
119
- } else if ( attribute . type === 'SpreadAttribute' ) {
120
- attributes . push ( attribute ) ;
121
- } else if ( attribute . type === 'ClassDirective' ) {
122
- class_directives . push ( attribute ) ;
123
- } else if ( attribute . type === 'StyleDirective' ) {
124
- style_directives . push ( attribute ) ;
125
- } else if ( attribute . type === 'OnDirective' ) {
152
+ for ( const attribute of other_directives ) {
153
+ if ( attribute . type === 'OnDirective' ) {
126
154
const handler = /** @type {Expression } */ ( context . visit ( attribute ) ) ;
127
- const has_action_directive = node . attributes . find ( ( a ) => a . type === 'UseDirective' ) ;
128
155
129
156
context . state . after_update . push (
130
- b . stmt ( has_action_directive ? b . call ( '$.effect' , b . thunk ( handler ) ) : handler )
157
+ b . stmt ( has_use ? b . call ( '$.effect' , b . thunk ( handler ) ) : handler )
131
158
) ;
132
- } else if ( attribute . type !== 'LetDirective' ) {
159
+ } else {
133
160
context . visit ( attribute ) ;
134
161
}
135
162
}
@@ -257,10 +284,7 @@ export function RegularElement(node, context) {
257
284
258
285
if (
259
286
is_load_error_element ( node . name ) &&
260
- ( has_spread ||
261
- lookup . has ( 'onload' ) ||
262
- lookup . has ( 'onerror' ) ||
263
- node . attributes . some ( ( attribute ) => attribute . type === 'UseDirective' ) )
287
+ ( has_spread || has_use || lookup . has ( 'onload' ) || lookup . has ( 'onerror' ) )
264
288
) {
265
289
context . state . after_update . push ( b . stmt ( b . call ( '$.replay_events' , node_id ) ) ) ;
266
290
}
0 commit comments