Skip to content

Commit 6ebf46a

Browse files
committed
fix handler in-place
1 parent 298a339 commit 6ebf46a

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/generators/nodes/Element.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,16 @@ export default class Element extends Node {
516516
});
517517
`);
518518

519-
if (generator.options.dev) {
520-
block.builders.hydrate.addBlock(deindent`
521-
if (${handlerName}.teardown) {
522-
console.warn("Return 'destroy()' from custom event handlers. Returning 'teardown()' has been deprecated and will be unsupported in Svelte 2");
523-
}
524-
`);
525-
}
519+
520+
block.builders.hydrate.addBlock(deindent`
521+
if (${handlerName}.teardown) {
522+
${handlerName}.destroy = ${handlerName}.teardown;
523+
${generator.options.dev && `console.warn("Return 'destroy()' from custom event handlers. Returning 'teardown()' has been deprecated and will be unsupported in Svelte 2");`}
524+
}
525+
`);
526526

527527
block.builders.destroy.addLine(deindent`
528-
${handlerName}[${handlerName}.destroy ? 'destroy' : 'teardown']();
528+
${handlerName}.destroy();
529529
`);
530530
} else {
531531
const handler = deindent`

test/js/samples/event-handlers-custom/expected-bundle.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ function create_main_fragment(component, state) {
199199
var state = component.get();
200200
component.foo( state.bar );
201201
});
202+
203+
if (foo_handler.teardown) {
204+
foo_handler.destroy = foo_handler.teardown;
205+
}
202206
},
203207

204208
m: function mount(target, anchor) {
@@ -212,7 +216,7 @@ function create_main_fragment(component, state) {
212216
},
213217

214218
d: function destroy$$1() {
215-
foo_handler[foo_handler.destroy ? 'destroy' : 'teardown']();
219+
foo_handler.destroy();
216220
}
217221
};
218222
}

test/js/samples/event-handlers-custom/expected.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function create_main_fragment(component, state) {
2626
var state = component.get();
2727
component.foo( state.bar );
2828
});
29+
30+
if (foo_handler.teardown) {
31+
foo_handler.destroy = foo_handler.teardown;
32+
}
2933
},
3034

3135
m: function mount(target, anchor) {
@@ -39,7 +43,7 @@ function create_main_fragment(component, state) {
3943
},
4044

4145
d: function destroy() {
42-
foo_handler[foo_handler.destroy ? 'destroy' : 'teardown']();
46+
foo_handler.destroy();
4347
}
4448
};
4549
}

0 commit comments

Comments
 (0)