diff --git a/src/generators/nodes/Element.ts b/src/generators/nodes/Element.ts index 288a508758..555ea5ae4d 100644 --- a/src/generators/nodes/Element.ts +++ b/src/generators/nodes/Element.ts @@ -516,8 +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");`} + } + `); + block.builders.destroy.addLine(deindent` - ${handlerName}.teardown(); + ${handlerName}.destroy(); `); } 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 6d0dcd3bc8..7aea3cc47f 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -199,6 +199,10 @@ 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) { @@ -212,7 +216,7 @@ function create_main_fragment(component, state) { }, d: function destroy$$1() { - foo_handler.teardown(); + foo_handler.destroy(); } }; } diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index ee1d155e9d..b20649d611 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -26,6 +26,10 @@ 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) { @@ -39,7 +43,7 @@ function create_main_fragment(component, state) { }, d: function destroy() { - foo_handler.teardown(); + foo_handler.destroy(); } }; } diff --git a/test/runtime/samples/dev-warning-custom-event-destroy-not-teardown/_config.js b/test/runtime/samples/dev-warning-custom-event-destroy-not-teardown/_config.js new file mode 100644 index 0000000000..59c583ba1a --- /dev/null +++ b/test/runtime/samples/dev-warning-custom-event-destroy-not-teardown/_config.js @@ -0,0 +1,7 @@ +export default { + dev: true, + + warnings: [ + `Return 'destroy()' from custom event handlers. Returning 'teardown()' has been deprecated and will be unsupported in Svelte 2` + ] +}; \ No newline at end of file diff --git a/test/runtime/samples/dev-warning-custom-event-destroy-not-teardown/main.html b/test/runtime/samples/dev-warning-custom-event-destroy-not-teardown/main.html new file mode 100644 index 0000000000..1e83835f03 --- /dev/null +++ b/test/runtime/samples/dev-warning-custom-event-destroy-not-teardown/main.html @@ -0,0 +1,16 @@ + + + \ No newline at end of file