fix(js/ts) fix detecting types as JSX#3278
Conversation
|
I feel like this is ugly, but it does pass all test cases... ultimately this problem isn't really solvable (AFAIK) since we aren't a full contextual parser so I opted to do the simple thing that seems to fix the immediate reported issue. |
src/languages/javascript.js
Outdated
| let m; | ||
| const afterMatch = match.input.substr(afterMatchIndex) | ||
| // NOTE: This is ugh, but added specifically for https://github.com/highlightjs/highlight.js/issues/3276 | ||
| if (m = afterMatch.match(/^\s+extends\s+/)) { |
There was a problem hiding this comment.
| if (m = afterMatch.match(/^\s+extends\s+/)) { | |
| if ((m = afterMatch.match(/^\s+extends\s+/))) { |
This is just personal preference and I don't know if we have more of these in the codebase, but I usually surround assignments in if statements with an extra set of () so that it signifies it's not a type for ==.
There was a problem hiding this comment.
Ugh, why is From and string there highlighted diff in your snap? Grr, it's HTML...
There was a problem hiding this comment.
Ugh, and if we don't flag it as HTML then we fall into the class "X extends Y" rule, which isn't really correct either... this may need more thought.
af1a4bd to
e549661
Compare

Resolves #3276.
Changes
<....>block appears not to be JSX/HTML it's falls back to simply being ignored (by the JSX rule)Prior there was no fallback so if the common cases didn't classify the block it would DEFAULT to being HTML... where-as we really shouldn't consider something HTML unless it not only LOOKS like HTML but we can also find a closing tag.
I'm not sure the first conditional is needed at all now and think perhaps:
<blahis followed by>or space it MIGHT be HTML/JSX and we should search for a closing tagChecklist
CHANGES.md