From af1a4bd1d477683123d56afe369c383faefd65ab Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 6 Oct 2021 18:43:45 -0400 Subject: [PATCH] fix up tests --- src/languages/javascript.js | 33 ++++++++++++++++----------- test/markup/javascript/jsx.expect.txt | 6 ++--- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/languages/javascript.js b/src/languages/javascript.js index 629fdea1f4..982414c9db 100644 --- a/src/languages/javascript.js +++ b/src/languages/javascript.js @@ -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 @@ -68,11 +68,12 @@ export default function(hljs) { // `` // 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; } } @@ -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" } - } + }, + ] }; @@ -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 diff --git a/test/markup/javascript/jsx.expect.txt b/test/markup/javascript/jsx.expect.txt index 202e137e66..c10ef1add8 100644 --- a/test/markup/javascript/jsx.expect.txt +++ b/test/markup/javascript/jsx.expect.txt @@ -27,15 +27,15 @@ var x = 5; // this is NOT JSX and should not trigger the rule -interface Prefixer<Something extends string> { +interface Prefixer<Something extends string> { (): `other__${Something}`; - parse: <From extends string>( + parse: <From extends string>( value: From ) => number; } -const cloneWith = <T, A extends keyof T, V>( +const cloneWith = <T, A extends keyof T, V>( i: T, a: A, value: V