Skip to content

Commit 7b978de

Browse files
committed
Small fix for invalid ternary detection
This was done mostly to help with crazy flow annotations since the ternary region would cause cascading syntax breakage. Also, a statement like `?:` is a syntax error. I considered adding 0 or more whitespace check as well, but I found in practice this actually becomes annoying if you you are someone who sets up ternary boundaries first and then fills them in after, since it won't detect the ternary right away.
1 parent 9648f31 commit 7b978de

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

syntax/javascript.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ syntax region jsBlock matchgroup=jsBraces s
155155
syntax region jsModuleGroup contained matchgroup=jsModuleBraces start=/{/ end=/}/ contains=jsModuleKeyword,jsModuleComma,jsModuleAs,jsComment,jsFlowTypeKeyword skipwhite skipempty nextgroup=jsFrom fold
156156
syntax region jsSpreadExpression contained matchgroup=jsSpreadOperator start=/\.\.\./ end=/[,}\]]\@=/ contains=@jsExpression
157157
syntax region jsRestExpression contained matchgroup=jsRestOperator start=/\.\.\./ end=/[,)]\@=/
158-
syntax region jsTernaryIf matchgroup=jsTernaryIfOperator start=/?/ end=/\%(:\|}\@=\)/ contains=@jsExpression extend skipwhite skipempty nextgroup=@jsExpression
158+
syntax region jsTernaryIf matchgroup=jsTernaryIfOperator start=/?:\@!/ end=/\%(:\|}\@=\)/ contains=@jsExpression extend skipwhite skipempty nextgroup=@jsExpression
159159
syntax match jsOperator /?\.\ze\_D/
160160

161161
syntax match jsGenerator contained /\*/ skipwhite skipempty nextgroup=jsFuncName,jsFuncArgs,jsFlowFunctionGroup

0 commit comments

Comments
 (0)