svelte: Logical nullish/or (and other types of) assignment(s) doesn't work in Svelte
Describe 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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (16 by maintainers)
I don’t think this is related to
svelte-preprocessnorsvelte-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.
@benbender You’re right. Looks like Svelte’s acorn version is up-to-date and should support logical assignments. If this only happens in the REPL and not locally, it should be an issue for svelte-repl then, and I see you’ve opened an issue there: https://github.com/sveltejs/svelte-repl/issues/171
Though re that issue, I don’t think acorn needs to be updated to have this work, I’m guessing that it’s rollup that should be updated instead since acorn is only used in svelte-repl for converting cjs to esm, and Svelte components are already esm.
The REPL is plain Svelte, so I don’t think there is a “real” bug either. It doesn’t (sadly and f.e.) doesn’t even support typescript at all… If you want to request additional features from the REPL, the repo to go is here: https://github.com/sveltejs/svelte-repl
@Mlocik97 Afaik this is expected. See https://github.com/sveltejs/svelte-preprocess#modern-javascript-syntax