Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
ChristianIvicevic opened this issue Oct 13, 2019 · 12 comments · Fixed by #2502
Closed
4 tasks done
Labels
bug help welcome Could use help from community language
Milestone

Comments

@ChristianIvicevic
Copy link

ChristianIvicevic commented Oct 13, 2019

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

@cdbax
Copy link
Contributor

cdbax commented Oct 13, 2019

This seems to be something to do with the parens enclosing that arrow function. Here's some minimal reproductions:

Working: https://jsfiddle.net/cdbax/tsvn1gpj/8/

Broken: https://jsfiddle.net/cdbax/tsvn1gpj/9/

@ChristianIvicevic ChristianIvicevic changed the title The highlighter is bailing on a very specific snippet containing a generic and a lambda arrow in Typescript The highlighter is bailing on a Typescript snippet containing a lambda which parameters are enclosed in parens Oct 13, 2019
@joshgoebel
Copy link
Member

You know you can put multiple examples in a single fiddle, right? 🙂

@joshgoebel joshgoebel added bug help welcome Could use help from community labels Oct 13, 2019
@cdbax
Copy link
Contributor

cdbax commented Oct 13, 2019

Ahehe 😅 sure I knew that:
https://jsfiddle.net/cdbax/tsvn1gpj/11/

@joshgoebel
Copy link
Member

Sure it’s not the number in brackets before it?

@ChristianIvicevic
Copy link
Author

Even the following snippet will break the highlighting:

const good = () => 0;
// comment

const bad = (() => 0);
// comment

@joshgoebel
Copy link
Member

Someone looking into this might want to look at Javascript which has this same type of structure, but I believe it works in that grammar.

@joshgoebel joshgoebel changed the title The highlighter is bailing on a Typescript snippet containing a lambda which parameters are enclosed in parens (typescript) snippet containing a lambda which parameters are enclosed in parens fails Oct 13, 2019
@mondeja
Copy link
Contributor

mondeja commented Apr 11, 2020

Just if someone try to fix this: Javascript and Typescript markups for enclosed lambda functions are broken, so both needs to be fixed. Javascript does not produce this error on the comment, but this is the rendered markup:
Captura de pantalla de 2020-04-11 15-29-38

Note the paren at params start against a properly render markup:
Captura de pantalla de 2020-04-11 15-32-02

See this for more.

@joshgoebel
Copy link
Member

Thanks, I also updated the original message here with more detail.

@joshgoebel
Copy link
Member

joshgoebel commented Apr 11, 2020

Actually you might be able to get away with just either/oring them since it's just a "preflight" check:

Ie:

  • _ =>
  • (*) =>
  • (*(*)*) =>
  • (*(*(*)*)*) =>

And when it goes to parse let the rule handle it.

@joshgoebel
Copy link
Member

@mondeja Does my last comment make sense or did you give up on this?

@mondeja
Copy link
Contributor

mondeja commented Apr 11, 2020

I have given up for now.

@joshgoebel
Copy link
Member

Thanks for trying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community language
Projects
None yet
4 participants