Found some bug.
When I have tried to name custom method "delete" and then call it with on directive, I got error "Unexpected token".
Webpack svelte-loader logs "Error: ParseError: Expected a method call"
https://svelte.technology/repl?version=2.9.7&gist=2ee08584200c6094f1cfcedaaf933ca7
Likely due to delete is a reserved word for operator in JS. You would have the same error with any reserved word, try to rename to const for example.
@Romanior good assumption, but on the other hand it should not be like that, because svelte has compilation stage, where it get methods object as part of component definition.
There is no restriction in JS to make property with name delete.
Also I investigated compiled code for my alterantive name for delete method - deleteMessage. And all mentioning of deleteMessage were as part of some objects and I didn't find deleteMessage as function declaration either function expression, only as shorthand method definition of objects.
What's going on here is that Svelte is parsing the value of the on:whatever directive as a js expression, using Acorn. So, even though delete only ends up getting used as a method name (which is perfectly valid), when it's initially parsed it's an identifier as far as Acorn can tell (which is invalid).
It might be possible to fix this without a ton of work, by prepending the on:whatever value with dummy. or something, and then adjusting the manipulations we do to the AST afterwards.
In v3, this and other cases where you want props/methods whose names are keywords can now be handled by using some other name for the variable/function internally, and then aliasing it upon export - export { delete_ as delete };.
Closing this - As mentioned above, methods (and props) in components in v3 can be given reserved names by using export-as.
It would be awesome if the clever export-as usage could be in the docs somewhere (if it isn't already), it's perfect but I almost didn't find this issue. I'll try to find some time to submit a PR soon.
Thanks as always!
Opened #2559 for documenting this trick somewhere.
Most helpful comment
Likely due to
deleteis a reserved word for operator in JS. You would have the same error with any reserved word, try to rename toconstfor example.