Merge pull request #1392 from sveltejs/gh-1390

only overwrite this in event handlers for custom events
pull/1400/merge
Rich Harris 7 years ago committed by GitHub
commit 5f471e5e32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -77,16 +77,18 @@ export default class EventHandler extends Node {
}
}
this.args.forEach(arg => {
arg.overwriteThis(this.parent.var);
});
if (this.isCustomEvent && this.callee && this.callee.name === 'this') {
const node = this.callee.nodes[0];
compiler.code.overwrite(node.start, node.end, this.parent.var, {
storeName: true,
contentOnly: true
if (this.isCustomEvent) {
this.args.forEach(arg => {
arg.overwriteThis(this.parent.var);
});
if (this.callee && this.callee.name === 'this') {
const node = this.callee.nodes[0];
compiler.code.overwrite(node.start, node.end, this.parent.var, {
storeName: true,
contentOnly: true
});
}
}
}
}

@ -0,0 +1,28 @@
export default {
data: {
items: ['foo', 'bar', 'baz'],
},
html: `
<button>foo</button>
<button>bar</button>
<button>baz</button>
`,
test(assert, component, target, window) {
const buttons = target.querySelectorAll('button');
const event = new window.MouseEvent('click');
const clicked = [];
component.on('clicked', event => {
clicked.push(event.node);
});
buttons[1].dispatchEvent(event);
assert.equal(clicked.length, 1);
assert.equal(clicked[0].nodeName, 'BUTTON');
assert.equal(clicked[0].textContent, 'bar');
}
};

@ -0,0 +1,3 @@
{#each items as item}
<button on:click='fire("clicked", { node: this })'>{item}</button>
{/each}
Loading…
Cancel
Save