diff --git a/src/generators/dom/visitors/Element/EventHandler.ts b/src/generators/dom/visitors/Element/EventHandler.ts index b66f6b8c3d..eb96c4e636 100644 --- a/src/generators/dom/visitors/Element/EventHandler.ts +++ b/src/generators/dom/visitors/Element/EventHandler.ts @@ -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); diff --git a/test/runtime/samples/event-handler-hoisted/_config.js b/test/runtime/samples/event-handler-hoisted/_config.js new file mode 100644 index 0000000000..3a949e5fad --- /dev/null +++ b/test/runtime/samples/event-handler-hoisted/_config.js @@ -0,0 +1,18 @@ +export default { + data: { + foo: [1], + a: 42 + }, + + html: ` + + `, + + test (assert, component, target, window) { + const button = target.querySelector('button'); + const event = new window.MouseEvent('click'); + + button.dispatchEvent(event); + assert.equal(component.snapshot, 42); + } +}; diff --git a/test/runtime/samples/event-handler-hoisted/main.html b/test/runtime/samples/event-handler-hoisted/main.html new file mode 100644 index 0000000000..527218d170 --- /dev/null +++ b/test/runtime/samples/event-handler-hoisted/main.html @@ -0,0 +1,13 @@ +{{#each foo as bar}} + +{{/each}} + + \ No newline at end of file