Skip to content

Commit 1f3f892

Browse files
JS: Added support for keywords after a spread operator (#2148)
This PR fixes that keywords after a spread operator weren't highlighted. This is mainly for the `await` and `new` keywords.
1 parent a06aca0 commit 1f3f892

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

components/prism-javascript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
1212
lookbehind: true
1313
},
1414
{
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/,
15+
pattern: /(^|[^.]|\.\.\.\s*)\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/,
1616
lookbehind: true
1717
},
1818
],

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
852852
lookbehind: true
853853
},
854854
{
855-
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/,
855+
pattern: /(^|[^.]|\.\.\.\s*)\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/,
856856
lookbehind: true
857857
},
858858
],
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
async function bar() {
2+
return [...await foo()]
3+
}
4+
5+
console.log([...new Set(numbers)])
6+
7+
----------------------------------------------------
8+
9+
[
10+
["keyword", "async"],
11+
["keyword", "function"],
12+
["function", "bar"],
13+
["punctuation", "("],
14+
["punctuation", ")"],
15+
["punctuation", "{"],
16+
["keyword", "return"],
17+
["punctuation", "["],
18+
["operator", "..."],
19+
["keyword", "await"],
20+
["function", "foo"],
21+
["punctuation", "("],
22+
["punctuation", ")"],
23+
["punctuation", "]"],
24+
["punctuation", "}"],
25+
26+
"\r\n\r\nconsole",
27+
["punctuation", "."],
28+
["function", "log"],
29+
["punctuation", "("],
30+
["punctuation", "["],
31+
["operator", "..."],
32+
["keyword", "new"],
33+
["class-name", [
34+
"Set"
35+
]],
36+
["punctuation", "("],
37+
"numbers",
38+
["punctuation", ")"],
39+
["punctuation", "]"],
40+
["punctuation", ")"]
41+
]
42+
43+
----------------------------------------------------
44+
45+
Checks for the spread operator followed by a keyword.

0 commit comments

Comments
 (0)