|
|
|
@ -16,6 +16,10 @@ export default function visitEventHandler(
|
|
|
|
|
const isCustomEvent = generator.events.has(name);
|
|
|
|
|
const shouldHoist = !isCustomEvent && state.inEachBlock;
|
|
|
|
|
|
|
|
|
|
const context = shouldHoist ? null : state.parentNode;
|
|
|
|
|
const usedContexts: string[] = [];
|
|
|
|
|
|
|
|
|
|
if (attribute.expression) {
|
|
|
|
|
generator.addSourcemapLocations(attribute.expression);
|
|
|
|
|
|
|
|
|
|
const flattened = flattenReference(attribute.expression.callee);
|
|
|
|
@ -29,8 +33,6 @@ export default function visitEventHandler(
|
|
|
|
|
if (shouldHoist) state.usesComponent = true; // this feels a bit hacky but it works!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const context = shouldHoist ? null : state.parentNode;
|
|
|
|
|
const usedContexts: string[] = [];
|
|
|
|
|
attribute.expression.arguments.forEach((arg: Node) => {
|
|
|
|
|
const { contexts } = block.contextualise(arg, context, true);
|
|
|
|
|
|
|
|
|
@ -40,6 +42,7 @@ export default function visitEventHandler(
|
|
|
|
|
state.allUsedContexts.push(context);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const _this = context || 'this';
|
|
|
|
|
const declarations = usedContexts.map(name => {
|
|
|
|
@ -66,7 +69,9 @@ export default function visitEventHandler(
|
|
|
|
|
${state.usesComponent &&
|
|
|
|
|
`var ${block.alias('component')} = ${_this}._svelte.component;`}
|
|
|
|
|
${declarations}
|
|
|
|
|
[✂${attribute.expression.start}-${attribute.expression.end}✂];
|
|
|
|
|
${attribute.expression ?
|
|
|
|
|
`[✂${attribute.expression.start}-${attribute.expression.end}✂];` :
|
|
|
|
|
`${block.alias('component')}.fire('${attribute.name}', event);`}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
if (isCustomEvent) {
|
|
|
|
|