Skip to content

Commit f2d8e1c

Browse files
JS: Keyword fix (#1808)
This fixes false positives with properties which have the same name as keywords.
1 parent dedb475 commit f2d8e1c

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

components/prism-javascript.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
1111
pattern: /((?:^|})\s*)(?:catch|finally)\b/,
1212
lookbehind: true
1313
},
14-
/\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/
14+
{
15+
pattern: /(^|[^.])\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
16+
lookbehind: true
17+
},
1518
],
1619
'number': /\b(?:(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+)n?|\d+n|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
1720
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)

components/prism-javascript.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prism.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,10 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
774774
pattern: /((?:^|})\s*)(?:catch|finally)\b/,
775775
lookbehind: true
776776
},
777-
/\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/
777+
{
778+
pattern: /(^|[^.])\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
779+
lookbehind: true
780+
},
778781
],
779782
'number': /\b(?:(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+)n?|\d+n|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
780783
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Array.from();
2+
foo.var.new;
3+
4+
----------------------------------------------------
5+
6+
[
7+
"Array",
8+
["punctuation", "."],
9+
["function", "from"],
10+
["punctuation", "("],
11+
["punctuation", ")"],
12+
["punctuation", ";"],
13+
"\nfoo",
14+
["punctuation", "."],
15+
"var",
16+
["punctuation", "."],
17+
"new",
18+
["punctuation", ";"]
19+
]
20+
21+
----------------------------------------------------
22+
23+
Checks for properties which have the same name as keywords. See #1807.

0 commit comments

Comments
 (0)