Skip to content
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

Add parameter highlighting for ES2015’s arrow functions. #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 112 additions & 5 deletions Syntaxes/JavaScript.plist
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,104 @@
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(?x)
(?:([_$a-zA-Z][$\w]*)\s*(=)\s*)? # optional assignment to identifier
(?= # lookahead to:
(\( # open parenthesis
(?&gt;(?&gt;[^()]+)|\g&lt;-1&gt;)* # anything except parens (atomic)
\)) # close parenthesis
\s* # optional space
(=&gt;) # arrow
)
</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>entity.name.function.js</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.js</string>
</dict>
</dict>
<key>comment</key>
<string>
Arrow function.
https://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions
</string>
<key>end</key>
<string>(?&lt;=\))\s*(=&gt;)</string>
<key>name</key>
<string>meta.function.js</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\G\(</string>
<key>name</key>
<string>punctuation.definition.parameters.begin.js</string>
</dict>
<dict>
<key>match</key>
<string>\)(?=\s*=&gt;)</string>
<key>name</key>
<string>punctuation.definition.parameters.end.js</string>
</dict>
<dict>
<key>include</key>
<string>#function-params</string>
</dict>
</array>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>entity.name.function.js</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.js</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>keyword.control.js</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>variable.parameter.function.js</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>storage.type.function.arrow.js</string>
</dict>
</dict>
<key>comment</key>
<string>
Arrow function, but without parentheses delimiting the parameters. Only valid when there is exactly one parameter without a default value.
https://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions
</string>
<key>match</key>
<string>(?x)
(?:([_$a-zA-Z][$\w]*)\s*(=)\s*)? # optional assignment to identifier
(?:(async)\s+)? # optional "async" annotation
\b([_$a-zA-Z][$\w]*) # single parameter name
\s*(=&gt;) # optional space and arrow
</string>
<key>name</key>
<string>meta.function.js</string>
</dict>
<dict>
<key>begin</key>
<string>(?&lt;=[\[=(?:+,!]|^|return|=&gt;|&amp;&amp;|\|\|)\s*(?=/[^/*+?].*/)</string>
Expand Down Expand Up @@ -731,7 +829,7 @@
<key>comment</key>
<string>Matching as a capture group prevents false positives with other uses of :</string>
<key>end</key>
<string>([^:"'`\[\]{}()]*)(:)</string>
<string>([^:"`\[\]{}()]*)(:)</string>
<key>endCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -1008,10 +1106,8 @@
<string>invalid.illegal.js</string>
</dict>
<dict>
<key>match</key>
<string>\b(false|Infinity|NaN|null|true|undefined)\b</string>
<key>name</key>
<string>constant.language.js</string>
<key>include</key>
<string>#constants</string>
</dict>
<dict>
<key>match</key>
Expand Down Expand Up @@ -1239,6 +1335,13 @@
</dict>
</array>
</dict>
<key>constants</key>
<dict>
<key>match</key>
<string>\b(false|Infinity|NaN|null|true|undefined)\b</string>
<key>name</key>
<string>constant.language.js</string>
</dict>
<key>function-call</key>
<dict>
<key>patterns</key>
Expand Down Expand Up @@ -1316,6 +1419,10 @@
<key>include</key>
<string>#numbers</string>
</dict>
<dict>
<key>include</key>
<string>#constants</string>
</dict>
<dict>
<key>include</key>
<string>#strings</string>
Expand Down