From 3b37c7d74959d56c770b72ae4618248a66530fa7 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Tue, 7 Nov 2017 11:12:11 -0600 Subject: [PATCH] =?UTF-8?q?Add=20parameter=20highlighting=20for=20ES2015?= =?UTF-8?q?=E2=80=99s=20arrow=20functions.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also: properly highlight constants like `null` and `false` when they are default values of parameters. --- Syntaxes/JavaScript.plist | 117 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 5 deletions(-) diff --git a/Syntaxes/JavaScript.plist b/Syntaxes/JavaScript.plist index dd46b1f..4542ff0 100644 --- a/Syntaxes/JavaScript.plist +++ b/Syntaxes/JavaScript.plist @@ -675,6 +675,104 @@ + + begin + (?x) + (?:([_$a-zA-Z][$\w]*)\s*(=)\s*)? # optional assignment to identifier + (?= # lookahead to: + (\( # open parenthesis + (?>(?>[^()]+)|\g<-1>)* # anything except parens (atomic) + \)) # close parenthesis + \s* # optional space + (=>) # arrow + ) + + beginCaptures + + 1 + + name + entity.name.function.js + + 2 + + name + keyword.operator.assignment.js + + + comment + + Arrow function. + https://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions + + end + (?<=\))\s*(=>) + name + meta.function.js + patterns + + + match + \G\( + name + punctuation.definition.parameters.begin.js + + + match + \)(?=\s*=>) + name + punctuation.definition.parameters.end.js + + + include + #function-params + + + + + captures + + 1 + + name + entity.name.function.js + + 2 + + name + keyword.operator.assignment.js + + 3 + + name + keyword.control.js + + 4 + + name + variable.parameter.function.js + + 5 + + name + storage.type.function.arrow.js + + + comment + + 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 + + match + (?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*(=>) # optional space and arrow + + name + meta.function.js + begin (?<=[\[=(?:+,!]|^|return|=>|&&|\|\|)\s*(?=/[^/*+?].*/) @@ -731,7 +829,7 @@ comment Matching as a capture group prevents false positives with other uses of : end - ([^:"'`\[\]{}()]*)(:) + ([^:"`\[\]{}()]*)(:) endCaptures 1 @@ -1008,10 +1106,8 @@ invalid.illegal.js - match - \b(false|Infinity|NaN|null|true|undefined)\b - name - constant.language.js + include + #constants match @@ -1239,6 +1335,13 @@ + constants + + match + \b(false|Infinity|NaN|null|true|undefined)\b + name + constant.language.js + function-call patterns @@ -1316,6 +1419,10 @@ include #numbers + + include + #constants + include #strings