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

Fix Typescript markup for comment after enclosed lambda. #2489

Closed
wants to merge 1 commit into from
Closed

Conversation

mondeja
Copy link
Contributor

@mondeja mondeja commented Apr 11, 2020

This resolves #2189. Function params can't contains self.

@@ -0,0 +1,2 @@
<span class="hljs-keyword">const</span> bad = <span class="hljs-function">(<span class="hljs-params">(a, b</span>) =&gt;</span> [...a, b]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct output, please compare to https://github.com/highlightjs/highlight.js/blob/master/test/markup/typescript/functions.expect.txt (wrt: params wrapping)

The () aren't being wrapped or paired properly. The proper fix here is likely more complex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would also need some tests for nested parenthesis inside arguments, which is likely what the self was trying to catch in the first place.

return this.sides.every((length,width=(3+2+(4/5))) => length > 0 );

They have to be properly paired so the first ) we see doesn't end the params.

Copy link
Contributor Author

@mondeja mondeja Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but Javascript has the same problem. At least this change produces the same output that JS language produces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a perfect world I think simple cases would look something like:

const bad = ((a, b) => [...a, b]);
const bad = (a => [...a, b]);
bad = (<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> [...a, b]);
bad = (<span class="hljs-function"><span class="hljs-params">a</span> =&gt;</span> [...a, b]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but Javascript has the same problem. At least this change produces the same output that JS language produces.

Then it would seem they are both broken, just in different ways. Fixing some of these requires really digging in deep and understanding what is happening, why the rules are there, the different possible issues (like in this case nested parens), etc. My bet is this is one of the harder ones, but I"m not certain.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you were trying to follow my last comment (thanks) but now that I've looked a little closer I don't think the fix here is just "do what JS does".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

------------v
const bad = ((a, b) => [...a, b]);

The problem here is that first ( is matched as the start of a function when it is not, it's just an expression. That's what someone needs to tackle here - this misdetection.

@joshgoebel
Copy link
Member

If you're curious I believe this actually resolves the issue:

#2502

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(typescript) snippet containing a lambda which parameters are enclosed in parens fails
2 participants