only overwrite this in event handlers for custom events - fixes #1390

pull/1392/head
Rich Harris 7 years ago
parent afb6d07991
commit 49a09ef847

@ -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