Skip to content

Commit

Permalink
Merge pull request #3111 from sveltejs/gh-2923
Browse files Browse the repository at this point in the history
sanitize names of automatically-bubbled events
  • Loading branch information
Rich-Harris authored Jun 25, 2019
2 parents e924f4d + d10d491 commit 33b756c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compiler/compile/nodes/EventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Expression from './shared/Expression';
import Component from '../Component';
import deindent from '../utils/deindent';
import Block from '../render_dom/Block';
import { sanitize } from '../../utils/names';

export default class EventHandler extends Node {
type: 'EventHandler';
Expand Down Expand Up @@ -41,7 +42,7 @@ export default class EventHandler extends Node {
}
}
} else {
const name = component.get_unique_name(`${this.name}_handler`);
const name = component.get_unique_name(`${sanitize(this.name)}_handler`);

component.add_var({
name,
Expand Down
18 changes: 18 additions & 0 deletions test/runtime/samples/event-handler-shorthand-sanitized/_config.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button on:click-now>click me now</button>

0 comments on commit 33b756c

Please sign in to comment.