|
|
@ -13,13 +13,15 @@ export default function visitEventHandler(
|
|
|
|
local
|
|
|
|
local
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
// TODO verify that it's a valid callee (i.e. built-in or declared method)
|
|
|
|
// TODO verify that it's a valid callee (i.e. built-in or declared method)
|
|
|
|
|
|
|
|
const usedContexts: string[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (attribute.expression) {
|
|
|
|
generator.addSourcemapLocations(attribute.expression);
|
|
|
|
generator.addSourcemapLocations(attribute.expression);
|
|
|
|
generator.code.prependRight(
|
|
|
|
generator.code.prependRight(
|
|
|
|
attribute.expression.start,
|
|
|
|
attribute.expression.start,
|
|
|
|
`${block.alias('component')}.`
|
|
|
|
`${block.alias('component')}.`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const usedContexts: string[] = [];
|
|
|
|
|
|
|
|
attribute.expression.arguments.forEach((arg: Node) => {
|
|
|
|
attribute.expression.arguments.forEach((arg: Node) => {
|
|
|
|
const { contexts } = block.contextualise(arg, null, true);
|
|
|
|
const { contexts } = block.contextualise(arg, null, true);
|
|
|
|
|
|
|
|
|
|
|
@ -29,6 +31,7 @@ export default function visitEventHandler(
|
|
|
|
local.allUsedContexts.push(context);
|
|
|
|
local.allUsedContexts.push(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO hoist event handlers? can do `this.__component.method(...)`
|
|
|
|
// TODO hoist event handlers? can do `this.__component.method(...)`
|
|
|
|
const declarations = usedContexts.map(name => {
|
|
|
|
const declarations = usedContexts.map(name => {
|
|
|
@ -42,7 +45,9 @@ export default function visitEventHandler(
|
|
|
|
|
|
|
|
|
|
|
|
const handlerBody =
|
|
|
|
const handlerBody =
|
|
|
|
(declarations.length ? declarations.join('\n') + '\n\n' : '') +
|
|
|
|
(declarations.length ? declarations.join('\n') + '\n\n' : '') +
|
|
|
|
`[✂${attribute.expression.start}-${attribute.expression.end}✂];`;
|
|
|
|
(attribute.expression ?
|
|
|
|
|
|
|
|
`[✂${attribute.expression.start}-${attribute.expression.end}✂];` :
|
|
|
|
|
|
|
|
`${block.alias('component')}.fire('${attribute.name}', event);`);
|
|
|
|
|
|
|
|
|
|
|
|
local.create.addBlock(deindent`
|
|
|
|
local.create.addBlock(deindent`
|
|
|
|
${local.name}.on( '${attribute.name}', function ( event ) {
|
|
|
|
${local.name}.on( '${attribute.name}', function ( event ) {
|
|
|
|