From 352bb3d354a1c6e5d1209bc527d23e483e211443 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 11 Apr 2017 09:38:34 -0400 Subject: [PATCH] =?UTF-8?q?ensure=20hoisted=20event=20handler=20names=20ar?= =?UTF-8?q?e=20globally=20unique=20=E2=80=94=20fixes=20#466?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dom/visitors/Element/EventHandler.js | 2 +- .../_config.js | 36 +++++++++++++++++++ .../event-handler-each-deconflicted/main.html | 9 +++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/event-handler-each-deconflicted/_config.js create mode 100644 test/runtime/samples/event-handler-each-deconflicted/main.html diff --git a/src/generators/dom/visitors/Element/EventHandler.js b/src/generators/dom/visitors/Element/EventHandler.js index 2a51cdc1ff..1099238b83 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 0000000000..0c11a15d3d --- /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 0000000000..4dcc770e83 --- /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