-
- Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the bug
Introduced in #3935 support of methods in use:obj.action
causes runtime exception if method is nested in multiple objects
<button use:ctx.button.behavior>Open</button>
Logs
ctx[0]['button.behavior'] is not a function
To Reproduce
https://svelte.dev/repl/b9576a0efc17479287e6bba62c1e9e85?version=3.31.0
Expected behavior
No exceptions, actions are applied to HTML node as usual
OR
compiler error that prevents usage of nested objects in action definition
Stacktraces
Seems like code causing the error is generated in /src/compiler/compile/render_dom/wrappers/shared/add_actions.ts:35
Information about your Svelte project:
- Firefox 84.0.1 x64
- Windows 10
- Svelte 3.31.0
- Node 15.4.0
- Snowpack + Rollup
Severity
Somewhat annoying, but not critical. There is a workaround for now, but I think this should be addressed at the compiler level, at least to prevent unexpected runtime crashes.
<script> let ctx = { // or just use flat objects without extra nesting, obviously 'button.behavior': (node) => { console.log(node); }, }; </script> <button use:ctx.button.behavior>Open </button>
UPD: after some fiddling, using flat objects and avoiding nesting is the best option for now, since different IDEs react differently when workaround above is present. VSCode highlights it as missing property, WebStorm - does not