Skip to content

(typescript) snippet containing a lambda which parameters are enclosed in parens fails #2189

@ChristianIvicevic

Description

@ChristianIvicevic

Editor: Adding a list of samples we should add tests for:

const array = [1, 2, 3].reduce<number[]>((acc, next) => [...acc, next], []);
return this.sides.every((length,width=(3+2+(4/5))) => length > 0 );
const bad = ((a, b) => [...a, b]);
const bad = (a => [...a, b]);
const bad = (_ => doSomething());
const good = () => 0;
const bad = (() => 0);
  • Nested parens in expressions
  • () surrounded arguments
  • flag argument with no ()
  • _ argument

Possibly relevant:
https://stackoverflow.com/questions/18703187/count-parentheses-with-regular-expression

Since to do this I think we really need to count parens in the regex that's matching => functions.


This is an issue I noticed downstream in VS Code itself and in the output of Asciidoctor which uses highlightjs. The snippet causing issues is this one:

const array = [1, 2, 3].reduce<number[]>((acc, next) => [...acc, next], []);
//                             ~~~~~~~~
// Type of the initial value, in our case making it an array of numbers.

And gets rendered in VS Code and Asciidoctor generated HTML as follows:

image

image

When removing the arrowhead of the lambda (even though syntactically incorrect) the formatting is correct once again (since the comment at the ends gets picked up as a comment):

image

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions