diff --git a/src/generators/dom/visitors/Element/EventHandler.js b/src/generators/dom/visitors/Element/EventHandler.js index 2a51cdc1fff0..1099238b83cd 100644 --- a/src/generators/dom/visitors/Element/EventHandler.js +++ b/src/generators/dom/visitors/Element/EventHandler.js @@ -44,7 +44,7 @@ export default function visitEventHandler ( generator, block, state, node, attri // get a name for the event handler that is globally unique // if hoisted, locally unique otherwise const handlerName = shouldHoist ? - generator.alias( `${name}_handler` ) : + generator.getUniqueName( `${name}_handler` ) : block.getUniqueName( `${name}_handler` ); // create the handler body diff --git a/test/runtime/samples/event-handler-each-deconflicted/_config.js b/test/runtime/samples/event-handler-each-deconflicted/_config.js new file mode 100644 index 000000000000..0c11a15d3df4 --- /dev/null +++ b/test/runtime/samples/event-handler-each-deconflicted/_config.js @@ -0,0 +1,36 @@ +export default { + data: { + foo: [ 1 ], + bar: [ 2 ], + clicked: 'neither' + }, + + html: ` + + +

clicked: neither

+ `, + + test ( assert, component, target, window ) { + const buttons = target.querySelectorAll( 'button' ); + const event = new window.MouseEvent( 'click' ); + + buttons[0].dispatchEvent( event ); + assert.equal( component.get( 'clicked' ), 'foo' ); + assert.htmlEqual( target.innerHTML, ` + + +

clicked: foo

+ ` ); + + buttons[1].dispatchEvent( event ); + assert.equal( component.get( 'clicked' ), 'bar' ); + assert.htmlEqual( target.innerHTML, ` + + +

clicked: bar

+ ` ); + + component.destroy(); + } +}; diff --git a/test/runtime/samples/event-handler-each-deconflicted/main.html b/test/runtime/samples/event-handler-each-deconflicted/main.html new file mode 100644 index 000000000000..4dcc770e83ec --- /dev/null +++ b/test/runtime/samples/event-handler-each-deconflicted/main.html @@ -0,0 +1,9 @@ +{{#each foo as f}} + +{{/each}} + +{{#each bar as b}} + +{{/each}} + +

clicked: {{clicked}}

\ No newline at end of file