Packages icon indicating copy to clipboard operation
Packages copied to clipboard

[JavaScript] Newlines in arrow function arguments break function name highlighting.

Open willstott101 opened this issue 4 years ago • 3 comments

What happened?

Expected (github highlighting)

const a = () => {};
const a = (
  ) => {};

Actual (ST4 - I believe I have correctly installed the master branch of this repo) image

That's a pretty contrived minimal example, it's much more common when deconstructing objects in arguments (React functional components often do this in our org).

Edit (example with arg deconstruction):

const MyFunc = ({
  a,
  b,
  c,
  d,
  e
}) => {
  // Do stuff with exploded args
};

Huh, it seems github's highlighting also fails on deconstruction...

Edit (example with many args):

const MyFunc = (
  a,
  b,
  c,
  d,
  e
) => {
  // Do stuff with lots of args
};

Huh, it seems github's highlighting also fails with lots of args...

willstott101 avatar Dec 03 '21 12:12 willstott101

I tried to fix this in https://github.com/willstott101/Packages/compare/master...willstott101:arrow-fn-param-newline but I have failed. My best guess is that arrow_func_lookahead isn't actually responsible for this? But I can't find anything else that might work too

willstott101 avatar Dec 07 '21 21:12 willstott101

See #2267.

Currently, function assignment detection is done with a dumb lookahead. This is fundamentally not a reliable method. One of these days, I need to rip out the whole thing and redo it from scratch using branches. It hasn't been a priority for me because I see the function name highlighting as a bonus rather than a key part of the syntax, but a lot of people seem to care about it, so I suppose I should get around to it soon.

Thom1729 avatar Dec 08 '21 02:12 Thom1729