@@ -13,22 +13,25 @@ export default function visitEventHandler(
13
13
local
14
14
) {
15
15
// TODO verify that it's a valid callee (i.e. built-in or declared method)
16
- generator . addSourcemapLocations ( attribute . expression ) ;
17
- generator . code . prependRight (
18
- attribute . expression . start ,
19
- `${ block . alias ( 'component' ) } .`
20
- ) ;
21
-
22
16
const usedContexts : string [ ] = [ ] ;
23
- attribute . expression . arguments . forEach ( ( arg : Node ) => {
24
- const { contexts } = block . contextualise ( arg , null , true ) ;
25
17
26
- contexts . forEach ( context => {
27
- if ( ! ~ usedContexts . indexOf ( context ) ) usedContexts . push ( context ) ;
28
- if ( ! ~ local . allUsedContexts . indexOf ( context ) )
29
- local . allUsedContexts . push ( context ) ;
18
+ if ( attribute . expression ) {
19
+ generator . addSourcemapLocations ( attribute . expression ) ;
20
+ generator . code . prependRight (
21
+ attribute . expression . start ,
22
+ `${ block . alias ( 'component' ) } .`
23
+ ) ;
24
+
25
+ attribute . expression . arguments . forEach ( ( arg : Node ) => {
26
+ const { contexts } = block . contextualise ( arg , null , true ) ;
27
+
28
+ contexts . forEach ( context => {
29
+ if ( ! ~ usedContexts . indexOf ( context ) ) usedContexts . push ( context ) ;
30
+ if ( ! ~ local . allUsedContexts . indexOf ( context ) )
31
+ local . allUsedContexts . push ( context ) ;
32
+ } ) ;
30
33
} ) ;
31
- } ) ;
34
+ }
32
35
33
36
// TODO hoist event handlers? can do `this.__component.method(...)`
34
37
const declarations = usedContexts . map ( name => {
@@ -42,7 +45,9 @@ export default function visitEventHandler(
42
45
43
46
const handlerBody =
44
47
( declarations . length ? declarations . join ( '\n' ) + '\n\n' : '' ) +
45
- `[✂${ attribute . expression . start } -${ attribute . expression . end } ✂];` ;
48
+ ( attribute . expression ?
49
+ `[✂${ attribute . expression . start } -${ attribute . expression . end } ✂];` :
50
+ `${ block . alias ( 'component' ) } .fire('${ attribute . name } ', event);` ) ;
46
51
47
52
local . create . addBlock ( deindent `
48
53
${ local . name } .on( '${ attribute . name } ', function ( event ) {
0 commit comments