Skip to content

Commit

Permalink
JS: Exclude function name from parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
RexSkz committed Jul 12, 2018
1 parent 9ef0c3e commit 7205979
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 54 deletions.
12 changes: 9 additions & 3 deletions components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ Prism.languages.insertBefore('javascript', 'keyword', {
},
'parameter': [
{
pattern: /(function)(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*(\([^()]*\))/,
pattern: /(function(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)\S[^()]*(?=\s*\))/,
lookbehind: true,
inside: Prism.languages.javascript
},
{
pattern: /(\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)(?=\s*=>)/,
pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=>)/,
inside: Prism.languages.javascript
},
{
pattern: /\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)(\([^()]*\))(?=\s*\{)/,
pattern: /(\()[^()]+(?=\)\s*=>)/,
lookbehind: true,
inside: Prism.languages.javascript
},
{
pattern: /(\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-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.

12 changes: 9 additions & 3 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,16 +742,22 @@ Prism.languages.insertBefore('javascript', 'keyword', {
},
'parameter': [
{
pattern: /(function)(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*(\([^()]*\))/,
pattern: /(function(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)\S[^()]*(?=\s*\))/,
lookbehind: true,
inside: Prism.languages.javascript
},
{
pattern: /(\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)(?=\s*=>)/,
pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=>)/,
inside: Prism.languages.javascript
},
{
pattern: /\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)(\([^()]*\))(?=\s*\{)/,
pattern: /(\()[^()]+(?=\)\s*=>)/,
lookbehind: true,
inside: Prism.languages.javascript
},
{
pattern: /(\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)\S[^()]*(?=\s*\)\s*\{)/,
lookbehind: true,
inside: Prism.languages.javascript
}
],
Expand Down
24 changes: 11 additions & 13 deletions tests/languages/javascript/class-method_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,36 @@ class Test {
["class-name", ["Test"]],
["punctuation", "{"],

["function", "foo"],
["punctuation", "("],
["parameter", [
["function", "foo"],
["punctuation", "("],
"x",
["punctuation", ","],
" y ",
["operator", "="],
["number", "0"],
["punctuation", ")"]
["number", "0"]
]],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "async"],
["function", "bar"],
["punctuation", "("],
["parameter", [
["function", "bar"],
["punctuation", "("],
"x",
["punctuation", ","],
" y ",
["operator", "="],
["number", "0"],
["punctuation", ")"]
["number", "0"]
]],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["parameter", [
["function", "_"],
["punctuation", "("],
["punctuation", ")"]
]],
["function", "_"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

Expand Down
40 changes: 19 additions & 21 deletions tests/languages/javascript/function-variable_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ fooBar = (x, y) => x
["function-variable", "foo"],
["operator", "="],
["keyword", "function"],
["punctuation", "("],
["parameter", [
["punctuation", "("],
" x",
"x",
["punctuation", ","],
" y",
["punctuation", ")"]
" y"
]],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["function-variable", "bar"],
["operator", "="],
["keyword", "async"],
["keyword", "function"],
["function", "baz"],
["punctuation", "("],
["parameter", [
["function", "baz"],
["punctuation", "("],
"x ",
["punctuation", ")"]
"x "
]],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["function-variable", "baz"],
["operator", "="],
["keyword", "async"],
["punctuation", "("],
["parameter", [
["punctuation", "("],
"x",
["punctuation", ")"]
"x"
]],
["punctuation", ")"],
["operator", "=>"], " x\r\n",

["function-variable", "fooBar"],
Expand All @@ -54,37 +54,35 @@ fooBar = (x, y) => x

["function-variable", "fooBar"],
["operator", "="],
["punctuation", "("],
["parameter", [
["punctuation", "("],
"x",
["punctuation", ","],
" y",
["punctuation", ")"]
" y"
]],
["punctuation", ")"],
["operator", "=>"], " x\r\n",

["function-variable", "ಠ_ಠ"],
["operator", "="],
["parameter", [
["punctuation", "("],
["punctuation", ")"]
]],
["punctuation", "("],
["punctuation", ")"],
["operator", "=>"],
["punctuation", "{"],
["punctuation", "}"],

["function-variable", "Ƞȡ_҇"],
["operator", "="],
["keyword", "async"],
["punctuation", "("],
["parameter", [
["punctuation", "("],
"ಠ",
["punctuation", ","],
" Ƞ ",
["operator", "="],
["number", "2"],
["punctuation", ")"]
["number", "2"]
]],
["punctuation", ")"],
["operator", "=>"],
["punctuation", "{"],
["punctuation", "}"]
Expand Down
3 changes: 2 additions & 1 deletion tests/languages/jsx/issue1294.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default () => (
[
["keyword", "export"],
["keyword", "default"],
["parameter", [["punctuation", "("], ["punctuation", ")"]]],
["punctuation", "("],
["punctuation", ")"],
["operator", "=>"], ["punctuation", "("],
["tag", [
["tag", [
Expand Down
6 changes: 3 additions & 3 deletions tests/languages/jsx/issue1335.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
["script", [
["script-punctuation", "="],
["punctuation", "{"],
["punctuation", "("],
["parameter", [
["punctuation", "("],
"e",
["punctuation", ")"]
"e"
]],
["punctuation", ")"],
["operator", "=>"],
["keyword", "this"],
["punctuation", "."],
Expand Down
6 changes: 2 additions & 4 deletions tests/languages/jsx/issue1421.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class Columns extends React.Component {
["keyword", "extends"],
["class-name", ["React", ["punctuation", "."], "Component"]],
["punctuation", "{"],
["parameter", [
["function", "render"],
["punctuation", "("], ["punctuation", ")"]
]],
["function", "render"],
["punctuation", "("], ["punctuation", ")"],
["punctuation", "{"],
["keyword", "return"], ["punctuation", "("],
["tag", [
Expand Down
8 changes: 3 additions & 5 deletions tests/languages/tsx/tag_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ class Test extends Component {
["keyword", "extends"],
["class-name", ["Component"]],
["punctuation", "{"],
["parameter", [
["function", "render"],
["punctuation", "("],
["punctuation", ")"]
]],
["function", "render"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["keyword","return"],
["tag", [
Expand Down

0 comments on commit 7205979

Please sign in to comment.