@@ -16,30 +16,33 @@ export default function visitEventHandler(
16
16
const isCustomEvent = generator . events . has ( name ) ;
17
17
const shouldHoist = ! isCustomEvent && state . inEachBlock ;
18
18
19
- generator . addSourcemapLocations ( attribute . expression ) ;
20
-
21
- const flattened = flattenReference ( attribute . expression . callee ) ;
22
- if ( flattened . name !== 'event' && flattened . name !== 'this' ) {
23
- // allow event.stopPropagation(), this.select() etc
24
- // TODO verify that it's a valid callee (i.e. built-in or declared method)
25
- generator . code . prependRight (
26
- attribute . expression . start ,
27
- `${ block . alias ( 'component' ) } .`
28
- ) ;
29
- if ( shouldHoist ) state . usesComponent = true ; // this feels a bit hacky but it works!
30
- }
31
-
32
19
const context = shouldHoist ? null : state . parentNode ;
33
20
const usedContexts : string [ ] = [ ] ;
34
- attribute . expression . arguments . forEach ( ( arg : Node ) => {
35
- const { contexts } = block . contextualise ( arg , context , true ) ;
36
21
37
- contexts . forEach ( context => {
38
- if ( ! ~ usedContexts . indexOf ( context ) ) usedContexts . push ( context ) ;
39
- if ( ! ~ state . allUsedContexts . indexOf ( context ) )
40
- state . allUsedContexts . push ( context ) ;
22
+ if ( attribute . expression ) {
23
+ generator . addSourcemapLocations ( attribute . expression ) ;
24
+
25
+ const flattened = flattenReference ( attribute . expression . callee ) ;
26
+ if ( flattened . name !== 'event' && flattened . name !== 'this' ) {
27
+ // allow event.stopPropagation(), this.select() etc
28
+ // TODO verify that it's a valid callee (i.e. built-in or declared method)
29
+ generator . code . prependRight (
30
+ attribute . expression . start ,
31
+ `${ block . alias ( 'component' ) } .`
32
+ ) ;
33
+ if ( shouldHoist ) state . usesComponent = true ; // this feels a bit hacky but it works!
34
+ }
35
+
36
+ attribute . expression . arguments . forEach ( ( arg : Node ) => {
37
+ const { contexts } = block . contextualise ( arg , context , true ) ;
38
+
39
+ contexts . forEach ( context => {
40
+ if ( ! ~ usedContexts . indexOf ( context ) ) usedContexts . push ( context ) ;
41
+ if ( ! ~ state . allUsedContexts . indexOf ( context ) )
42
+ state . allUsedContexts . push ( context ) ;
43
+ } ) ;
41
44
} ) ;
42
- } ) ;
45
+ }
43
46
44
47
const _this = context || 'this' ;
45
48
const declarations = usedContexts . map ( name => {
@@ -66,7 +69,9 @@ export default function visitEventHandler(
66
69
${ state . usesComponent &&
67
70
`var ${ block . alias ( 'component' ) } = ${ _this } ._svelte.component;` }
68
71
${ declarations }
69
- [✂${ attribute . expression . start } -${ attribute . expression . end } ✂];
72
+ ${ attribute . expression ?
73
+ `[✂${ attribute . expression . start } -${ attribute . expression . end } ✂];` :
74
+ `${ block . alias ( 'component' ) } .fire('${ attribute . name } ', event);` }
70
75
` ;
71
76
72
77
if ( isCustomEvent ) {
0 commit comments