See the reproduction here:
Variables are not properly highlighted as defined.
See the reproduction here:
Variables are not properly highlighted as defined.
This oneās an upstream bug that is present in CodeMirror. Unfortunately, because arrow functions are very context-dependent (because (foo, bar='default')
is a valid javascript expression and we only know that itās a parameter list after encountering =>
, and CodeMirrorās syntax highlighting system is very context-independent, Iām not sure that thereās a clean fix before CodeMirror 6.
Why does it work with a number then?
I havenāt tested this (so take this with a grain of salt), but I suspect this line in CodeMirrorās JS mode is causing the arrow-function detection to fail. It looks like it was added in response to this issue.
EDIT: As evidence for this, note that using backticks around your default string argument causes syntax highlighting to work again. Try pasting the following into a notebook:
test4 = (foo, bar = `string`) => [foo, bar]
Reported to CodeMirror:
This was fixed in codemirror/CodeMirror@4c30e11
. It looks like that commit hasnāt yet been published to npm yet, but you should be able to install from the master
branch on GitHub to get the fix.
Tom backported the CodeMirror fix, so this ought to be highlighting correctly now.
Thanks, Tom!
Awesome. Thank you!