question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logical nullish/or (and other types of) assignment(s) doesn't work in Svelte

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
bluwycommented, Aug 14, 2021

I don’t think this is related to svelte-preprocess nor svelte-repl. Svelte should be able to parse logical assignments, and also track reactivity through it. Currently the former should only require an update to acorn, the latter however may need some changes to make sure it works.

1reaction
Conduitrycommented, Aug 14, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found