Merge pull request #3934 from tanhauhau/tanhauhau/dynamic-event-handler-expression

fix dynamic event handler expression
pull/3942/head
Rich Harris 5 years ago committed by GitHub
commit 4b5f34ec7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -44,6 +44,8 @@ export default class EventHandler extends Node {
this.reassigned = component.var_lookup.get(info.expression.name).reassigned;
}
} else if (this.expression.dynamic_dependencies().length > 0) {
this.reassigned = true;
}
} else {
this.handler_name = component.get_unique_name(`${sanitize(this.name)}_handler`);

@ -0,0 +1,20 @@
export default {
html: `<button>bar</button>`,
async test({ assert, component, target, window }) {
const [button] = target.querySelectorAll(
'button'
);
const event = new window.MouseEvent('click');
await button.dispatchEvent(event);
assert.htmlEqual(target.innerHTML, `<button>foo</button>`);
await button.dispatchEvent(event);
assert.htmlEqual(target.innerHTML, `<button>bar</button>`);
await button.dispatchEvent(event);
assert.htmlEqual(target.innerHTML, `<button>foo</button>`);
},
};

@ -0,0 +1,12 @@
<script>
let name = 'bar';
function foo() {
name = 'foo';
}
function bar() {
name = 'bar';
}
</script>
<button on:click={name === 'bar' ? foo : bar}>{name}</button>
Loading…
Cancel
Save