From 67a3435bf670018ea0b561e018f28c966812cdf0 Mon Sep 17 00:00:00 2001 From: Lassi Pulkkinen Date: Tue, 2 Aug 2022 20:45:40 +0300 Subject: [PATCH 1/4] Better distinguish statements from expressions (#1249) Fixes incorrect highlighting of blocks as objects. --- syntax/javascript.vim | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 76c575ee..d482feb4 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -24,7 +24,8 @@ syntax sync fromstart " syntax case ignore syntax case match -syntax match jsNoise /[:,;]/ +syntax match jsNoise /[:;]/ +syntax match jsNoise /,/ skipwhite skipempty nextgroup=@jsExpression syntax match jsDot /\./ skipwhite skipempty nextgroup=jsObjectProp,jsFuncCall,jsPrototype,jsTaggedTemplate syntax match jsObjectProp contained /\<\K\k*/ syntax match jsFuncCall /\<\K\k*\ze\s*(/ @@ -33,7 +34,8 @@ syntax match jsParensError /[)}\]]/ " Program Keywords syntax keyword jsStorageClass const var let skipwhite skipempty nextgroup=jsDestructuringBlock,jsDestructuringArray,jsVariableDef syntax match jsVariableDef contained /\<\K\k*/ skipwhite skipempty nextgroup=jsFlowDefinition -syntax keyword jsOperatorKeyword delete instanceof typeof void new in of skipwhite skipempty nextgroup=@jsExpression +syntax keyword jsOperatorKeyword delete instanceof typeof void new in skipwhite skipempty nextgroup=@jsExpression +syntax keyword jsOf of skipwhite skipempty nextgroup=@jsExpression syntax match jsOperator "[-!|&+<>=%/*~^]" skipwhite skipempty nextgroup=@jsExpression syntax match jsOperator /::/ skipwhite skipempty nextgroup=@jsExpression syntax keyword jsBooleanTrue true @@ -99,7 +101,8 @@ syntax keyword jsStatement contained break continue skipwhite skipempty next syntax keyword jsConditional if skipwhite skipempty nextgroup=jsParenIfElse syntax keyword jsConditional else skipwhite skipempty nextgroup=jsCommentIfElse,jsIfElseBlock syntax keyword jsConditional switch skipwhite skipempty nextgroup=jsParenSwitch -syntax keyword jsRepeat while for skipwhite skipempty nextgroup=jsParenRepeat,jsForAwait +syntax keyword jsWhile while skipwhite skipempty nextgroup=jsParenWhile +syntax keyword jsFor for skipwhite skipempty nextgroup=jsParenFor,jsForAwait syntax keyword jsDo do skipwhite skipempty nextgroup=jsRepeatBlock syntax region jsSwitchCase contained matchgroup=jsLabel start=/\<\%(case\|default\)\>/ end=/:\@=/ contains=@jsExpression,jsLabel skipwhite skipempty nextgroup=jsSwitchColon keepend syntax keyword jsTry try skipwhite skipempty nextgroup=jsTryCatchBlock @@ -135,19 +138,20 @@ syntax keyword jsHtmlEvents onblur onclick oncontextmenu ondblclick onfocus " Code blocks syntax region jsBracket matchgroup=jsBrackets start=/\[/ end=/\]/ contains=@jsExpression,jsSpreadExpression extend fold syntax region jsParen matchgroup=jsParens start=/(/ end=/)/ contains=@jsExpression extend fold nextgroup=jsFlowDefinition -syntax region jsParenDecorator contained matchgroup=jsParensDecorator start=/(/ end=/)/ contains=@jsAll extend fold -syntax region jsParenIfElse contained matchgroup=jsParensIfElse start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentIfElse,jsIfElseBlock,jsReturn extend fold -syntax region jsParenRepeat contained matchgroup=jsParensRepeat start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentRepeat,jsRepeatBlock,jsReturn extend fold -syntax region jsParenSwitch contained matchgroup=jsParensSwitch start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold +syntax region jsParenDecorator contained matchgroup=jsParensDecorator start=/(/ end=/)/ contains=@jsExpression extend fold +syntax region jsParenIfElse contained matchgroup=jsParensIfElse start=/(/ end=/)/ contains=@jsExpression skipwhite skipempty nextgroup=jsCommentIfElse,jsIfElseBlock,jsReturn extend fold +syntax region jsParenWhile contained matchgroup=jsParensWhile start=/(/ end=/)/ contains=@jsExpression skipwhite skipempty nextgroup=jsCommentRepeat,jsRepeatBlock,jsReturn extend fold +syntax region jsParenFor contained matchgroup=jsParensFor start=/(/ end=/)/ contains=@jsExpression,jsStorageClass,jsOf skipwhite skipempty nextgroup=jsCommentRepeat,jsRepeatBlock,jsReturn extend fold +syntax region jsParenSwitch contained matchgroup=jsParensSwitch start=/(/ end=/)/ contains=@jsExpression skipwhite skipempty nextgroup=jsSwitchBlock extend fold syntax region jsParenCatch contained matchgroup=jsParensCatch start=/(/ end=/)/ skipwhite skipempty nextgroup=jsTryCatchBlock extend fold syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsDestructuringArray,jsRestExpression,jsFlowArgumentDef skipwhite skipempty nextgroup=jsCommentFunction,jsFuncBlock,jsFlowReturn extend fold syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsAsyncKeyword,jsNoise extend fold -syntax region jsFuncBlock contained matchgroup=jsFuncBraces start=/{/ end=/}/ contains=@jsAll,jsBlock extend fold -syntax region jsIfElseBlock contained matchgroup=jsIfElseBraces start=/{/ end=/}/ contains=@jsAll,jsBlock extend fold -syntax region jsTryCatchBlock contained matchgroup=jsTryCatchBraces start=/{/ end=/}/ contains=@jsAll,jsBlock skipwhite skipempty nextgroup=jsCatch,jsFinally extend fold -syntax region jsFinallyBlock contained matchgroup=jsFinallyBraces start=/{/ end=/}/ contains=@jsAll,jsBlock extend fold -syntax region jsSwitchBlock contained matchgroup=jsSwitchBraces start=/{/ end=/}/ contains=@jsAll,jsBlock,jsSwitchCase extend fold -syntax region jsRepeatBlock contained matchgroup=jsRepeatBraces start=/{/ end=/}/ contains=@jsAll,jsBlock extend fold +syntax region jsFuncBlock contained matchgroup=jsFuncBraces start=/{/ end=/}/ contains=@jsAll extend fold +syntax region jsIfElseBlock contained matchgroup=jsIfElseBraces start=/{/ end=/}/ contains=@jsAll extend fold +syntax region jsTryCatchBlock contained matchgroup=jsTryCatchBraces start=/{/ end=/}/ contains=@jsAll skipwhite skipempty nextgroup=jsCatch,jsFinally extend fold +syntax region jsFinallyBlock contained matchgroup=jsFinallyBraces start=/{/ end=/}/ contains=@jsAll extend fold +syntax region jsSwitchBlock contained matchgroup=jsSwitchBraces start=/{/ end=/}/ contains=@jsAll,jsSwitchCase extend fold +syntax region jsRepeatBlock contained matchgroup=jsRepeatBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsDestructuringBlock contained matchgroup=jsDestructuringBraces start=/{/ end=/}/ contains=jsDestructuringProperty,jsDestructuringAssignment,jsDestructuringNoise,jsDestructuringPropertyComputed,jsSpreadExpression,jsComment nextgroup=jsFlowDefinition extend fold syntax region jsDestructuringArray contained matchgroup=jsDestructuringBraces start=/\[/ end=/\]/ contains=jsDestructuringPropertyValue,jsDestructuringNoise,jsDestructuringProperty,jsSpreadExpression,jsDestructuringBlock,jsDestructuringArray,jsComment nextgroup=jsFlowDefinition extend fold syntax region jsObject contained matchgroup=jsObjectBraces start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectShorthandProp,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsDecorator,jsAsyncKeyword,jsTemplateString extend fold @@ -165,7 +169,7 @@ syntax match jsFuncName contained /\<\K\k*/ skipwhite skipempty ne syntax region jsFuncArgExpression contained matchgroup=jsFuncArgOperator start=/=/ end=/[,)]\@=/ contains=@jsExpression extend syntax match jsFuncArgCommas contained ',' syntax keyword jsArguments contained arguments -syntax keyword jsForAwait contained await skipwhite skipempty nextgroup=jsParenRepeat +syntax keyword jsForAwait contained await skipwhite skipempty nextgroup=jsParenFor " Matches a single keyword argument with no parens syntax match jsArrowFuncArgs /\<\K\k*\ze\s*=>/ skipwhite contains=jsFuncArgs skipwhite skipempty nextgroup=jsArrowFunction extend @@ -233,7 +237,7 @@ if exists("javascript_plugin_flow") endif syntax cluster jsExpression contains=jsBracket,jsParen,jsObject,jsTernaryIf,jsTaggedTemplate,jsTemplateString,jsString,jsRegexpString,jsNumber,jsFloat,jsOperator,jsOperatorKeyword,jsBooleanTrue,jsBooleanFalse,jsNull,jsFunction,jsArrowFunction,jsGlobalObjects,jsExceptions,jsFutureKeys,jsDomErrNo,jsDomNodeConsts,jsHtmlEvents,jsFuncCall,jsUndefined,jsNan,jsPrototype,jsBuiltins,jsNoise,jsClassDefinition,jsArrowFunction,jsArrowFuncArgs,jsParensError,jsComment,jsArguments,jsThis,jsSuper,jsDo,jsForAwait,jsAsyncKeyword,jsStatement,jsDot -syntax cluster jsAll contains=@jsExpression,jsStorageClass,jsConditional,jsRepeat,jsReturn,jsException,jsTry,jsNoise,jsBlockLabel +syntax cluster jsAll contains=@jsExpression,jsStorageClass,jsConditional,jsWhile,jsFor,jsReturn,jsException,jsTry,jsNoise,jsBlockLabel,jsBlock " Define the default highlighting. " For version 5.7 and earlier: only when not done already @@ -248,6 +252,8 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsComment Comment HiLink jsEnvComment PreProc HiLink jsParensIfElse jsParens + HiLink jsParensWhile jsParensRepeat + HiLink jsParensFor jsParensRepeat HiLink jsParensRepeat jsParens HiLink jsParensSwitch jsParens HiLink jsParensCatch jsParens @@ -273,6 +279,8 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsBranch Conditional HiLink jsLabel Label HiLink jsReturn Statement + HiLink jsWhile jsRepeat + HiLink jsFor jsRepeat HiLink jsRepeat Repeat HiLink jsDo Repeat HiLink jsStatement Statement From cf8872405b059428ffbabe0d5f624b496d92e338 Mon Sep 17 00:00:00 2001 From: JR Halchak Date: Mon, 15 Aug 2022 04:07:28 -0400 Subject: [PATCH 2/4] Add tilde ~ to jsDocParam for inner members (#1250) Added a tilde to the jsDocParam syntax match to support jsdoc3 namepaths style (i.e. when creating a typedef for an inner member). See https://jsdoc.app/tags-typedef.html Co-authored-by: Jonathan Halchak --- extras/jsdoc.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extras/jsdoc.vim b/extras/jsdoc.vim index 92c4b8b2..a7189d1b 100644 --- a/extras/jsdoc.vim +++ b/extras/jsdoc.vim @@ -18,7 +18,8 @@ syntax region jsDocTypeRecord contained start=/{/ end=/}/ contains=jsDocTypeRe syntax region jsDocTypeRecord contained start=/\[/ end=/\]/ contains=jsDocTypeRecord extend syntax region jsDocTypeNoParam contained start="{" end="}" oneline syntax match jsDocTypeNoParam contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" -syntax match jsDocParam contained "\%(#\|\$\|-\|'\|\"\|{.\{-}}\|\w\|\.\|:\|\/\|\[.\{-}]\|=\)\+" +syntax match jsDocParam contained "\%(#\|\$\|-\|'\|\"\|{.\{-}}\|\w\|\~\|\.\|:\|\/\|\[.\{-}]\|=\)\+" + syntax region jsDocSeeTag contained matchgroup=jsDocSeeTag start="{" end="}" contains=jsDocTags if version >= 508 || !exists("did_javascript_syn_inits") From c470ce1399a544fe587eab950f571c83cccfbbdc Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Mon, 15 Aug 2022 01:08:39 -0700 Subject: [PATCH 3/4] Allow newlines between function name and parens for function call (#1244) --- syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index d482feb4..02b0c78c 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -28,7 +28,7 @@ syntax match jsNoise /[:;]/ syntax match jsNoise /,/ skipwhite skipempty nextgroup=@jsExpression syntax match jsDot /\./ skipwhite skipempty nextgroup=jsObjectProp,jsFuncCall,jsPrototype,jsTaggedTemplate syntax match jsObjectProp contained /\<\K\k*/ -syntax match jsFuncCall /\<\K\k*\ze\s*(/ +syntax match jsFuncCall /\<\K\k*\ze[\s\n]*(/ syntax match jsParensError /[)}\]]/ " Program Keywords From b26c9edb3563e02f5c0b20580f7cf9743e95b157 Mon Sep 17 00:00:00 2001 From: Jay Kuri Date: Fri, 21 Mar 2025 11:26:47 -0600 Subject: [PATCH 4/4] Revise README to include a warning about foldmethod=syntax hanging during paste in some terminals (#1258) --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06419b2a..81accf8c 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,9 @@ augroup END Enables code folding for javascript based on our syntax file. -Please note this can have a dramatic effect on performance. +Please note this can have a dramatic effect on performance. In some terminals +this may cause hangs during pasting. If you are affected by this, using +a different foldmethod (such as indent) may provide a better experience. ## Concealing Characters