Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RunDevelopment committed Jan 5, 2020
1 parent a06aca0 commit 1f3f892
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/prism-javascript.js
Expand Up @@ -12,7 +12,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
lookbehind: true
},
{
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/,
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/,
lookbehind: 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 @@ -852,7 +852,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
lookbehind: true
},
{
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/,
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/,
lookbehind: true
},
],
Expand Down
45 changes: 45 additions & 0 deletions tests/languages/javascript/spread_and_keyword_feature.test
@@ -0,0 +1,45 @@
async function bar() {
return [...await foo()]
}

console.log([...new Set(numbers)])

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

[
["keyword", "async"],
["keyword", "function"],
["function", "bar"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["keyword", "return"],
["punctuation", "["],
["operator", "..."],
["keyword", "await"],
["function", "foo"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "]"],
["punctuation", "}"],

"\r\n\r\nconsole",
["punctuation", "."],
["function", "log"],
["punctuation", "("],
["punctuation", "["],
["operator", "..."],
["keyword", "new"],
["class-name", [
"Set"
]],
["punctuation", "("],
"numbers",
["punctuation", ")"],
["punctuation", "]"],
["punctuation", ")"]
]

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

Checks for the spread operator followed by a keyword.

0 comments on commit 1f3f892

Please sign in to comment.