Skip to content

Commit

Permalink
Use nagetive lookahead
Browse files Browse the repository at this point in the history
  • Loading branch information
RexSkz committed Feb 12, 2019
1 parent 67e2ba2 commit 99631a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Prism.languages.insertBefore('javascript', 'keyword', {
},
'parameter': [
{
pattern: /(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)\S(?:[^()]|\([^()]*\))*(?=\s*\))/,
pattern: /(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\))/,
lookbehind: true,
inside: Prism.languages.javascript
},
Expand All @@ -43,12 +43,12 @@ Prism.languages.insertBefore('javascript', 'keyword', {
inside: Prism.languages.javascript
},
{
pattern: /(\(\s*)\S(?:[^()]|\([^()]*\))*(?=\s*\)\s*=>)/,
pattern: /(\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*=>)/,
lookbehind: true,
inside: Prism.languages.javascript
},
{
pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|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|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)\S(?:[^()]|\([^()]*\))*(?=\s*\)\s*\{)/,
pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|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|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*\{)/,
lookbehind: true,
inside: Prism.languages.javascript
}
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.

6 changes: 3 additions & 3 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ Prism.languages.insertBefore('javascript', 'keyword', {
},
'parameter': [
{
pattern: /(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)\S(?:[^()]|\([^()]*\))*(?=\s*\))/,
pattern: /(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\))/,
lookbehind: true,
inside: Prism.languages.javascript
},
Expand All @@ -752,12 +752,12 @@ Prism.languages.insertBefore('javascript', 'keyword', {
inside: Prism.languages.javascript
},
{
pattern: /(\(\s*)\S(?:[^()]|\([^()]*\))*(?=\s*\)\s*=>)/,
pattern: /(\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*=>)/,
lookbehind: true,
inside: Prism.languages.javascript
},
{
pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|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|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)\S(?:[^()]|\([^()]*\))*(?=\s*\)\s*\{)/,
pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|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|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*\{)/,
lookbehind: true,
inside: Prism.languages.javascript
}
Expand Down
13 changes: 11 additions & 2 deletions tests/languages/javascript/function-variable_feature.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
foo = function ( ) {}
foo = function ( x, y) {}
{foo: function () {}}
bar = async function baz (x ) {}
Expand All @@ -14,6 +15,14 @@ a = function () {}, b = () => {}
----------------------------------------------------

[
["function-variable", "foo"],
["operator", "="],
["keyword", "function"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["function-variable", "foo"],
["operator", "="],
["keyword", "function"],
Expand Down Expand Up @@ -44,7 +53,7 @@ a = function () {}, b = () => {}
["function", "baz"],
["punctuation", "("],
["parameter", [
"x "
"x"
]],
["punctuation", ")"],
["punctuation", "{"],
Expand Down Expand Up @@ -73,7 +82,7 @@ a = function () {}, b = () => {}
["parameter", [
"x",
["punctuation", ","],
" y "
" y"
]],
["punctuation", ")"],
["operator", "=>"], " x\r\n",
Expand Down

0 comments on commit 99631a6

Please sign in to comment.