@@ -104,19 +104,28 @@ function get_delegated_event(node, context) {
104
104
return non_hoistable ;
105
105
}
106
106
107
- const element =
108
- parent . type === 'OnDirective'
109
- ? path . at ( - 2 )
110
- : parent . type === 'ExpressionTag' &&
111
- is_event_attribute ( /** @type {import('#compiler').Attribute } */ ( path . at ( - 2 ) ) )
112
- ? path . at ( - 3 )
113
- : null ;
114
-
115
- if ( element ) {
107
+ /** @type {import('#compiler').RegularElement | null } */
108
+ let element = null ;
109
+ /** @type {string | null } */
110
+ let event_name = null ;
111
+ if ( parent . type === 'OnDirective' ) {
112
+ element = /** @type {import('#compiler').RegularElement } */ ( path . at ( - 2 ) ) ;
113
+ event_name = parent . name ;
114
+ } else if (
115
+ parent . type === 'ExpressionTag' &&
116
+ is_event_attribute ( /** @type {import('#compiler').Attribute } */ ( path . at ( - 2 ) ) )
117
+ ) {
118
+ element = /** @type {import('#compiler').RegularElement } */ ( path . at ( - 3 ) ) ;
119
+ const attribute = /** @type {import('#compiler').Attribute } */ ( path . at ( - 2 ) ) ;
120
+ event_name = get_attribute_event_name ( attribute . name ) ;
121
+ }
122
+
123
+ if ( element && event_name ) {
116
124
if (
117
125
element . type !== 'RegularElement' ||
118
126
! determine_element_spread_and_delegatable ( element ) . metadata . can_delegate_events ||
119
- ( element . metadata . has_spread && node . type === 'Attribute' )
127
+ ( element . metadata . has_spread && node . type === 'Attribute' ) ||
128
+ ! DelegatedEvents . includes ( event_name )
120
129
) {
121
130
return non_hoistable ;
122
131
}
@@ -1036,10 +1045,7 @@ function determine_element_spread_and_delegatable(node) {
1036
1045
) {
1037
1046
let event_name = attribute . name ;
1038
1047
if ( attribute . type === 'Attribute' ) {
1039
- if ( is_capture_event ( event_name ) ) {
1040
- event_name = event_name . slice ( 0 , - 7 ) ;
1041
- }
1042
- event_name = event_name . slice ( 2 ) ;
1048
+ event_name = get_attribute_event_name ( event_name ) ;
1043
1049
}
1044
1050
events . set ( event_name , ( events . get ( event_name ) || 0 ) + 1 ) ;
1045
1051
if ( ! has_on && attribute . type === 'OnDirective' ) {
@@ -1066,6 +1072,17 @@ function determine_element_spread_and_delegatable(node) {
1066
1072
return node ;
1067
1073
}
1068
1074
1075
+ /**
1076
+ * @param {string } event_name
1077
+ */
1078
+ function get_attribute_event_name ( event_name ) {
1079
+ if ( is_capture_event ( event_name ) ) {
1080
+ event_name = event_name . slice ( 0 , - 7 ) ;
1081
+ }
1082
+ event_name = event_name . slice ( 2 ) ;
1083
+ return event_name ;
1084
+ }
1085
+
1069
1086
/**
1070
1087
* @param {string } name
1071
1088
* @returns boolean
0 commit comments