-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Identify JavaScript function parameters #1446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5cf3b3d
9ef0c3e
7205979
4e7261e
685d0db
f90f138
d2f3c9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,25 @@ Prism.languages.insertBefore('javascript', 'keyword', { | |
| }, | ||
| // This must be declared before keyword because we use "function" inside the look-forward | ||
| 'function-variable': { | ||
| pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i, | ||
| pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:async\s*)?(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i, | ||
| alias: 'function' | ||
| }, | ||
| 'es5-function-parameter': { | ||
| pattern: /(function\s*)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*(\([^()]*\))/, | ||
|
||
| lookbehind: true, | ||
| inside: Prism.languages.javascript, | ||
| alias: 'parameter' | ||
| }, | ||
| 'es6-function-parameter': { | ||
| pattern: /(\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)(?=\s*=>)/, | ||
| inside: Prism.languages.javascript, | ||
| alias: 'parameter' | ||
| }, | ||
| 'es6-class-method-parameter': { | ||
| pattern: /\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)(\([^()]*\))(?=\s*\{)/, | ||
| inside: Prism.languages.javascript, | ||
| alias: 'parameter' | ||
| }, | ||
| 'constant': /\b[A-Z][A-Z\d_]*\b/ | ||
| }); | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| class Test { | ||
| foo(x, y = 0) {} | ||
| async bar(x, y = 0) {} | ||
| _ ( ) {} | ||
| } | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| [ | ||
| ["keyword", "class"], | ||
| ["class-name", ["Test"]], | ||
| ["punctuation", "{"], | ||
|
|
||
| ["es6-class-method-parameter", [ | ||
| ["function", "foo"], | ||
| ["punctuation", "("], | ||
| "x", | ||
| ["punctuation", ","], | ||
| " y ", | ||
| ["operator", "="], | ||
| ["number", "0"], | ||
| ["punctuation", ")"] | ||
| ]], | ||
| ["punctuation", "{"], | ||
| ["punctuation", "}"], | ||
|
|
||
| ["keyword", "async"], | ||
| ["es6-class-method-parameter", [ | ||
| ["function", "bar"], | ||
| ["punctuation", "("], | ||
| "x", | ||
| ["punctuation", ","], | ||
| " y ", | ||
| ["operator", "="], | ||
| ["number", "0"], | ||
| ["punctuation", ")"] | ||
| ]], | ||
| ["punctuation", "{"], | ||
| ["punctuation", "}"], | ||
|
|
||
| ["es6-class-method-parameter", [ | ||
| ["function", "_"], | ||
| ["punctuation", "("], | ||
| ["punctuation", ")"] | ||
| ]], | ||
| ["punctuation", "{"], | ||
| ["punctuation", "}"], | ||
|
|
||
| ["punctuation", "}"] | ||
| ] | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| Checks for class methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
async\s+?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use
async\s+, we couldn't match the variablefooinfoo = async(a, b) =>, where theasynchere is a reserve word instead of the function name.I found a better solution
async(?:(?:\s*(?=\())|\s+).