Skip to content

JavaScript Syntax Highlighting breaks in multi-line single-expression lambda method declarations inside a class #932

@benediktwerner

Description

@benediktwerner

Minimal example:

class A {
    f = () => 
        false &&
        (false) ||
        (this.f);
}

image

Notice that the second false, the || after it, and the this aren't highlighted correctly. I've only been able to replicate it inside a class. The same thing happens when using any other binary operator after the initial false. Just the second false alone is also enough to make it break but it only breaks with parentheses around the second false and the this.f. This also happens with more complex expressions, false here is just for demonstration.

The effect isn't limited to just this method. It completely messes up syntax highlighting further in the file. Here's a more complex real-world example that eventually leads to completely messed up highlighting:

image

(this image is just to demonstrate the messed-up highlighting, the problematic function is further up, see the link)

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.72.2
  • OS Version: Windows 10

Also happens in TypeScript. And as far as I can tell, this should be perfectly correct JS. Prettier formats it just fine and Chrome executes it as expected.

I've first observed this behavior a decent while ago, at least a few months but possibly even more than a year ago (and it might have existed before then, I'm not certain it wasn't already like this the first time I looked at the file linked above).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions