From 6e5523cb89d5209ab37fadec6703bf605606bb9c Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 30 Mar 2018 16:33:41 -0400 Subject: [PATCH] Revert "fix handler in-place" This reverts commit 6ebf46ad67070132237faef843f4f1fffe2e4e84. --- src/generators/nodes/Element.ts | 16 ++++++++-------- .../event-handlers-custom/expected-bundle.js | 6 +----- .../js/samples/event-handlers-custom/expected.js | 6 +----- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/generators/nodes/Element.ts b/src/generators/nodes/Element.ts index 555ea5ae4d..a43c725ff4 100644 --- a/src/generators/nodes/Element.ts +++ b/src/generators/nodes/Element.ts @@ -516,16 +516,16 @@ export default class Element extends Node { }); `); - - block.builders.hydrate.addBlock(deindent` - if (${handlerName}.teardown) { - ${handlerName}.destroy = ${handlerName}.teardown; - ${generator.options.dev && `console.warn("Return 'destroy()' from custom event handlers. Returning 'teardown()' has been deprecated and will be unsupported in Svelte 2");`} - } - `); + if (generator.options.dev) { + block.builders.hydrate.addBlock(deindent` + if (${handlerName}.teardown) { + console.warn("Return 'destroy()' from custom event handlers. Returning 'teardown()' has been deprecated and will be unsupported in Svelte 2"); + } + `); + } block.builders.destroy.addLine(deindent` - ${handlerName}.destroy(); + ${handlerName}[${handlerName}.destroy ? 'destroy' : 'teardown'](); `); } else { const handler = deindent` diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 7aea3cc47f..7c17164c74 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -199,10 +199,6 @@ function create_main_fragment(component, state) { var state = component.get(); component.foo( state.bar ); }); - - if (foo_handler.teardown) { - foo_handler.destroy = foo_handler.teardown; - } }, m: function mount(target, anchor) { @@ -216,7 +212,7 @@ function create_main_fragment(component, state) { }, d: function destroy$$1() { - foo_handler.destroy(); + foo_handler[foo_handler.destroy ? 'destroy' : 'teardown'](); } }; } diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index b20649d611..08f964c346 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -26,10 +26,6 @@ function create_main_fragment(component, state) { var state = component.get(); component.foo( state.bar ); }); - - if (foo_handler.teardown) { - foo_handler.destroy = foo_handler.teardown; - } }, m: function mount(target, anchor) { @@ -43,7 +39,7 @@ function create_main_fragment(component, state) { }, d: function destroy() { - foo_handler.destroy(); + foo_handler[foo_handler.destroy ? 'destroy' : 'teardown'](); } }; }