mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
alias #component in hoisted event handlers - fixes #699
This commit is contained in:
parent
b3dc57d18d
commit
2131b28630
@ -45,7 +45,7 @@ export default function visitEventHandler(
|
||||
const declarations = usedContexts.map(name => {
|
||||
if (name === 'state') {
|
||||
if (shouldHoist) state.usesComponent = true;
|
||||
return `var state = #component.get();`;
|
||||
return `var state = ${block.alias('component')}.get();`;
|
||||
}
|
||||
|
||||
const listName = block.listNames.get(name);
|
||||
|
18
test/runtime/samples/event-handler-hoisted/_config.js
Normal file
18
test/runtime/samples/event-handler-hoisted/_config.js
Normal file
@ -0,0 +1,18 @@
|
||||
export default {
|
||||
data: {
|
||||
foo: [1],
|
||||
a: 42
|
||||
},
|
||||
|
||||
html: `
|
||||
<button>click me</button>
|
||||
`,
|
||||
|
||||
test (assert, component, target, window) {
|
||||
const button = target.querySelector('button');
|
||||
const event = new window.MouseEvent('click');
|
||||
|
||||
button.dispatchEvent(event);
|
||||
assert.equal(component.snapshot, 42);
|
||||
}
|
||||
};
|
13
test/runtime/samples/event-handler-hoisted/main.html
Normal file
13
test/runtime/samples/event-handler-hoisted/main.html
Normal file
@ -0,0 +1,13 @@
|
||||
{{#each foo as bar}}
|
||||
<button on:click='baz(a)'>click me</button>
|
||||
{{/each}}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
methods: {
|
||||
baz(a) {
|
||||
this.snapshot = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user