Skip to content

Commit

Permalink
fix up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Oct 6, 2021
1 parent 869a9db commit af1a4bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
33 changes: 20 additions & 13 deletions src/languages/javascript.js
Expand Up @@ -28,11 +28,11 @@ export default function(hljs) {
begin: '<>',
end: '</>'
};
// to avoid some special cases inside isTrulyOpeningTag
const XML_SELF_CLOSING = /<[A-Za-z0-9\\._:-]+\s*\/>/;
const XML_TAG = {
begin: /<[A-Za-z0-9\\._:-]+/,
end: /\/[A-Za-z0-9\\._:-]+>|\/>/,
// to avoid special cases inside isTrulyOpeningTag
simpleSelfClosing: /<[A-Za-z0-9\\._:-]+\s*\/>/,
/**
* @param {RegExpMatchArray} match
* @param {CallbackResponse} response
Expand Down Expand Up @@ -68,11 +68,12 @@ export default function(hljs) {
// `<From extends string>`
// technically this could be HTML, but it smells like a type
let m;
const afterMatch = match.input.substr(afterMatchIndex)
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+/)) {
if ((m = afterMatch.match(/^\s+extends\s+/))) {
if (m.index === 0) {
response.ignoreMatch();
// eslint-disable-next-line no-useless-return
return;
}
}
Expand Down Expand Up @@ -247,31 +248,37 @@ export default function(hljs) {
// ES6 classes
const CLASS_OR_EXTENDS = {
variants: [
// class Car extends vehicle
{
match: [
/class/,
/\s+/,
IDENT_RE
IDENT_RE,
/\s+/,
/extends/,
/\s+/,
regex.concat(IDENT_RE, "(", regex.concat(/\./, IDENT_RE), ")*")
],
scope: {
1: "keyword",
3: "title.class"
3: "title.class",
5: "keyword",
7: "title.class.inherited"
}
},
// class Car
{
match: [
/class/,
/\s+/,
/extends/,
/\s+/,
regex.concat(IDENT_RE, "(", regex.concat(/\./, IDENT_RE), ")*")
IDENT_RE
],
scope: {
1: "keyword",
3: "keyword",
5: "title.class.inherited"
3: "title.class"
}
}
},

]
};

Expand Down Expand Up @@ -477,7 +484,7 @@ export default function(hljs) {
{ // JSX
variants: [
{ begin: FRAGMENT.begin, end: FRAGMENT.end },
{ match: XML_TAG.simpleSelfClosing },
{ match: XML_SELF_CLOSING },
{
begin: XML_TAG.begin,
// we carefully check the opening tag to see if it truly
Expand Down
6 changes: 3 additions & 3 deletions test/markup/javascript/jsx.expect.txt
Expand Up @@ -27,15 +27,15 @@
<span class="hljs-keyword">var</span> x = <span class="hljs-number">5</span>;

<span class="hljs-comment">// this is NOT JSX and should not trigger the rule</span>
interface <span class="hljs-title class_">Prefixer</span>&lt;<span class="hljs-title class_">Something</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_ inherited__">string</span>&gt; {
interface <span class="hljs-title class_">Prefixer</span>&lt;<span class="hljs-title class_">Something</span> <span class="hljs-keyword">extends</span> string&gt; {
(): <span class="hljs-string">`other__<span class="hljs-subst">${Something}</span>`</span>;

<span class="hljs-attr">parse</span>: &lt;<span class="hljs-title class_">From</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_ inherited__">string</span>&gt;<span class="hljs-function">(<span class="hljs-params">
<span class="hljs-attr">parse</span>: &lt;<span class="hljs-title class_">From</span> <span class="hljs-keyword">extends</span> string&gt;<span class="hljs-function">(<span class="hljs-params">
value: From
</span>) =&gt;</span> number;
}

<span class="hljs-keyword">const</span> cloneWith = &lt;T, A <span class="hljs-keyword">extends</span> <span class="hljs-title class_ inherited__">keyof</span> T, V&gt;(
<span class="hljs-keyword">const</span> cloneWith = &lt;T, A <span class="hljs-keyword">extends</span> keyof T, V&gt;(
<span class="hljs-attr">i</span>: T,
<span class="hljs-attr">a</span>: A,
<span class="hljs-attr">value</span>: V
Expand Down

0 comments on commit af1a4bd

Please sign in to comment.