Skip to content

Commit

Permalink
JS: Added support for RegExp Match Indices (#2900)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored May 24, 2021
1 parent c81c331 commit 415651a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|ext

Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
lookbehind: true,
greedy: true,
inside: {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|ext

Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
lookbehind: true,
greedy: true,
inside: {
Expand Down
18 changes: 15 additions & 3 deletions tests/languages/javascript/regex_feature.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/foo bar/;
/foo/gimyus,
/foo/dgimyus,
/[\[\]]{2,4}(?:foo)*/;
/foo"test"bar/;
/foo\//;
Expand All @@ -23,54 +23,63 @@ yield /regex/;
["regex-delimiter", "/"]
]],
["punctuation", ";"],

["regex", [
["regex-delimiter", "/"],
["regex-source", "foo"],
["regex-delimiter", "/"],
["regex-flags", "gimyus"]
["regex-flags", "dgimyus"]
]],
["punctuation", ","],

["regex", [
["regex-delimiter", "/"],
["regex-source", "[\\[\\]]{2,4}(?:foo)*"],
["regex-delimiter", "/"]
]],
["punctuation", ";"],

["regex", [
["regex-delimiter", "/"],
["regex-source", "foo\"test\"bar"],
["regex-delimiter", "/"]
]],
["punctuation", ";"],

["regex", [
["regex-delimiter", "/"],
["regex-source", "foo\\/"],
["regex-delimiter", "/"]
]],
["punctuation", ";"],

["regex", [
["regex-delimiter", "/"],
["regex-source", "[]"],
["regex-delimiter", "/"]
]],
["punctuation", ";"],

["regex", [
["regex-delimiter", "/"],
["regex-source", "[\\]/]"],
["regex-delimiter", "/"]
]],
["punctuation", ";"],

["number", "1"],
["operator", "/"],
["number", "4"],
["operator", "+"],
["string", "\"/, not a regex\""],
["punctuation", ";"],

["regex", [
["regex-delimiter", "/"],
["regex-source", " '1' '2' '3' '4' '5' "],
["regex-delimiter", "/"]
]],

["punctuation", "["],
["regex", [
["regex-delimiter", "/"],
Expand All @@ -89,6 +98,7 @@ yield /regex/;
["regex-flags", "m"]
]],
["comment", "// comment"],

["keyword", "let"],
" b ",
["operator", "="],
Expand All @@ -105,13 +115,15 @@ yield /regex/;
["regex-source", "another one"],
["regex-delimiter", "/"]
]],

["keyword", "return"],
["regex", [
["regex-delimiter", "/"],
["regex-source", "regex"],
["regex-delimiter", "/"]
]],
["punctuation", ";"],

["keyword", "yield"],
["regex", [
["regex-delimiter", "/"],
Expand All @@ -123,4 +135,4 @@ yield /regex/;

----------------------------------------------------

Checks for regex.
Checks for regex.

0 comments on commit 415651a

Please sign in to comment.