fix shorthand events

pull/1864/head
Rich Harris 7 years ago
parent aaf7acce77
commit 6786e1b0de

@ -124,12 +124,6 @@ export default class Component {
throw new Error(`No tag name specified`); // TODO better error throw new Error(`No tag name specified`); // TODO better error
} }
this.fragment = new Fragment(this, ast.html);
// this.walkTemplate();
if (!this.customElement) this.stylesheet.reify();
this.stylesheet.warnOnUnusedSelectors(options.onwarn);
if (!this.ast.js) { if (!this.ast.js) {
this.declarations = Array.from(this.expectedProperties); this.declarations = Array.from(this.expectedProperties);
addToSet(this.writable_declarations, this.expectedProperties); addToSet(this.writable_declarations, this.expectedProperties);
@ -139,6 +133,12 @@ export default class Component {
as: name as: name
})); }));
} }
this.fragment = new Fragment(this, ast.html);
// this.walkTemplate();
if (!this.customElement) this.stylesheet.reify();
this.stylesheet.warnOnUnusedSelectors(options.onwarn);
} }
addSourcemapLocations(node: Node) { addSourcemapLocations(node: Node) {

@ -4,6 +4,7 @@ import flattenReference from '../../utils/flattenReference';
import { createScopes } from '../../utils/annotateWithScopes'; import { createScopes } from '../../utils/annotateWithScopes';
import { walk } from 'estree-walker'; import { walk } from 'estree-walker';
import Component from '../Component'; import Component from '../Component';
import deindent from '../../utils/deindent';
export default class EventHandler extends Node { export default class EventHandler extends Node {
name: string; name: string;
@ -33,7 +34,17 @@ export default class EventHandler extends Node {
this.usesContext = this.expression.usesContext; this.usesContext = this.expression.usesContext;
} else { } else {
component.init_uses_self = true; component.init_uses_self = true;
this.snippet = `e => @bubble($$self, e)`
const name = component.getUniqueName(`${this.name}_handler`);
component.declarations.push(name);
component.partly_hoisted.push(deindent`
function ${name}(event) {
@bubble($$self, event);
}
`);
this.snippet = `ctx.${name}`;
} }
// TODO figure out what to do about custom events // TODO figure out what to do about custom events

@ -256,7 +256,7 @@ export default class InlineComponentWrapper extends Wrapper {
} }
const munged_handlers = this.node.handlers.map(handler => { const munged_handlers = this.node.handlers.map(handler => {
return `${name}.$on("${handler.name}", ${handler.snippet})`; return `${name}.$on("${handler.name}", ${handler.snippet});`;
}); });
if (this.node.name === 'svelte:component') { if (this.node.name === 'svelte:component') {

Loading…
Cancel
Save