Skip to content

Commit

Permalink
JS: Improved regex detection (#2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Jul 18, 2020
1 parent 16fbe3e commit 4f55052
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/prism-javascript.js
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])\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
lookbehind: true,
greedy: true
},
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
Expand Up @@ -1468,7 +1468,7 @@ Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|ext

Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
lookbehind: true,
greedy: true
},
Expand Down
10 changes: 9 additions & 1 deletion tests/languages/javascript/regex_feature.test
Expand Up @@ -11,6 +11,8 @@

let a = /regex/m // comment
let b = condition ? /regex/ : /another one/
return /regex/;
yield /regex/;

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

Expand Down Expand Up @@ -38,7 +40,13 @@ let b = condition ? /regex/ : /another one/
["operator", "?"],
["regex", "/regex/"],
["operator", ":"],
["regex", "/another one/"]
["regex", "/another one/"],
["keyword", "return"],
["regex", "/regex/"],
["punctuation", ";"],
["keyword", "yield"],
["regex", "/regex/"],
["punctuation", ";"]
]

----------------------------------------------------
Expand Down

0 comments on commit 4f55052

Please sign in to comment.