sanitize names of automatically-bubbled events - fixes #2923

pull/3111/head
Rich Harris 6 years ago
parent 35001b36cc
commit d10d491579

@ -3,6 +3,7 @@ import Expression from './shared/Expression';
import Component from '../Component'; import Component from '../Component';
import deindent from '../utils/deindent'; import deindent from '../utils/deindent';
import Block from '../render_dom/Block'; import Block from '../render_dom/Block';
import { sanitize } from '../../utils/names';
export default class EventHandler extends Node { export default class EventHandler extends Node {
type: 'EventHandler'; type: 'EventHandler';
@ -41,7 +42,7 @@ export default class EventHandler extends Node {
} }
} }
} else { } else {
const name = component.get_unique_name(`${this.name}_handler`); const name = component.get_unique_name(`${sanitize(this.name)}_handler`);
component.add_var({ component.add_var({
name, name,

@ -0,0 +1,18 @@
export default {
html: `
<button>click me now</button>
`,
test({ assert, component, target, window }) {
const button = target.querySelector('button');
const event = new window.Event('click-now');
let clicked;
component.$on('click-now', () => {
clicked = true;
});
button.dispatchEvent(event);
assert.ok(clicked);
}
};

@ -0,0 +1 @@
<button on:click-now>click me now</button>
Loading…
Cancel
Save