Skip to content

Commit 415651a

Browse files
authoredMay 24, 2021
JS: Added support for RegExp Match Indices (#2900)
1 parent c81c331 commit 415651a

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed
 

‎components/prism-javascript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|ext
2626

2727
Prism.languages.insertBefore('javascript', 'keyword', {
2828
'regex': {
29-
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
29+
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
3030
lookbehind: true,
3131
greedy: true,
3232
inside: {

‎components/prism-javascript.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎prism.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|ext
15361536

15371537
Prism.languages.insertBefore('javascript', 'keyword', {
15381538
'regex': {
1539-
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
1539+
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
15401540
lookbehind: true,
15411541
greedy: true,
15421542
inside: {

‎tests/languages/javascript/regex_feature.test

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/foo bar/;
2-
/foo/gimyus,
2+
/foo/dgimyus,
33
/[\[\]]{2,4}(?:foo)*/;
44
/foo"test"bar/;
55
/foo\//;
@@ -23,54 +23,63 @@ yield /regex/;
2323
["regex-delimiter", "/"]
2424
]],
2525
["punctuation", ";"],
26+
2627
["regex", [
2728
["regex-delimiter", "/"],
2829
["regex-source", "foo"],
2930
["regex-delimiter", "/"],
30-
["regex-flags", "gimyus"]
31+
["regex-flags", "dgimyus"]
3132
]],
3233
["punctuation", ","],
34+
3335
["regex", [
3436
["regex-delimiter", "/"],
3537
["regex-source", "[\\[\\]]{2,4}(?:foo)*"],
3638
["regex-delimiter", "/"]
3739
]],
3840
["punctuation", ";"],
41+
3942
["regex", [
4043
["regex-delimiter", "/"],
4144
["regex-source", "foo\"test\"bar"],
4245
["regex-delimiter", "/"]
4346
]],
4447
["punctuation", ";"],
48+
4549
["regex", [
4650
["regex-delimiter", "/"],
4751
["regex-source", "foo\\/"],
4852
["regex-delimiter", "/"]
4953
]],
5054
["punctuation", ";"],
55+
5156
["regex", [
5257
["regex-delimiter", "/"],
5358
["regex-source", "[]"],
5459
["regex-delimiter", "/"]
5560
]],
5661
["punctuation", ";"],
62+
5763
["regex", [
5864
["regex-delimiter", "/"],
5965
["regex-source", "[\\]/]"],
6066
["regex-delimiter", "/"]
6167
]],
6268
["punctuation", ";"],
69+
6370
["number", "1"],
6471
["operator", "/"],
6572
["number", "4"],
6673
["operator", "+"],
6774
["string", "\"/, not a regex\""],
6875
["punctuation", ";"],
76+
6977
["regex", [
7078
["regex-delimiter", "/"],
7179
["regex-source", " '1' '2' '3' '4' '5' "],
7280
["regex-delimiter", "/"]
7381
]],
82+
7483
["punctuation", "["],
7584
["regex", [
7685
["regex-delimiter", "/"],
@@ -89,6 +98,7 @@ yield /regex/;
8998
["regex-flags", "m"]
9099
]],
91100
["comment", "// comment"],
101+
92102
["keyword", "let"],
93103
" b ",
94104
["operator", "="],
@@ -105,13 +115,15 @@ yield /regex/;
105115
["regex-source", "another one"],
106116
["regex-delimiter", "/"]
107117
]],
118+
108119
["keyword", "return"],
109120
["regex", [
110121
["regex-delimiter", "/"],
111122
["regex-source", "regex"],
112123
["regex-delimiter", "/"]
113124
]],
114125
["punctuation", ";"],
126+
115127
["keyword", "yield"],
116128
["regex", [
117129
["regex-delimiter", "/"],
@@ -123,4 +135,4 @@ yield /regex/;
123135

124136
----------------------------------------------------
125137

126-
Checks for regex.
138+
Checks for regex.

0 commit comments

Comments
 (0)
Please sign in to comment.