Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/languages/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ export default function(hljs) {
excludeBegin: true, excludeEnd: true,
keywords: KEYWORDS,
contains: [
'self',
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE
]
Expand Down
Original file line number Diff line number Diff line change
@@ -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

@joshgoebel joshgoebel Apr 11, 2020

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

@joshgoebel joshgoebel Apr 11, 2020

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

@joshgoebel joshgoebel Apr 11, 2020

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.

<span class="hljs-comment">// https://github.com/highlightjs/highlight.js/issues/2189</span>
2 changes: 2 additions & 0 deletions test/markup/typescript/comment-after-enclosed-lambda.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const bad = ((a, b) => [...a, b]);
// https://github.com/highlightjs/highlight.js/issues/2189