Logical nullish/or (and other types of) assignment(s) doesn't work in Svelte
See original GitHub issueDescribe the bug
Logical nullish assignment (as well as Logical OR assignment and other types of Logical assignments) doesn’t work in Svelte
Reproduction
https://svelte.dev/repl/e5054000ffb442ad85c4d7bbc821d8f5?version=3.42.1
Logs
unexpected token '??='
SyntaxError: Unexpected token '??='
at new Function (<anonymous>)
at instantiateModule (/mnt/sda1/Programovanie/test/node_modules/vite/dist/node/chunks/dep-c1a9de64.js:73464:9)
System Info
System:
OS: Linux 5.11 Ubuntu 20.04.2 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
Memory: 216.20 MB / 15.46 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Browsers:
Chrome: 92.0.4515.131
Firefox: 91.0
Severity
annoyance
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
Docs • Svelte
Assignments to $ -prefixed variables require that the variable be a writable store, and will result in a call to the store's .set...
Read more >Nullish coalescing operator · Issue #67 · sveltejs/eslint-plugin ...
Svelte itself doesn't support the nullish coalescing operator yet, but it will soon, at which point this should just work, assuming you have...
Read more >Nullish coalescing assignment (??=) - JavaScript | MDN
No assignment is performed if the left-hand side is not nullish, due to short-circuiting of the nullish coalescing operator.
Read more >Simple caching in Javascript using the new Logical nullish ...
I am saying that as someone who enjoys using all these new operators but curious to what are the limits.
Read more >Joshua's Docs - Svelte JS - Cheatsheet and Misc Notes
Various different ways: useEffect() hook; Relying on re-renders caused by state change; Using setState callback; Using class lifecycle hooks ( ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t think this is related to
svelte-preprocess
norsvelte-repl
. Svelte should be able to parse logical assignments, and also track reactivity through it. Currently the former should only require an update toacorn
, the latter however may need some changes to make sure it works.Oh, right, I had thought this was already working in Svelte. What you’re seeing in the REPL is just that its version of Rollup needs upgrading to support that syntax. There may be a PR for that already. In any case, this works in Svelte itself, and if you’re having issues with something unrelated, please pursue the usual avenues for support.