-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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(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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, why is From and string there highlighted diff in your snap? Grr, it's HTML...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
<blah
is followed by>
or space it MIGHT be HTML/JSX and we should search for a closing tagChecklist
CHANGES.md