Skip to content

Commit 36f34b2

Browse files
committed
Improved function declaration destructuring
This should vastly improve how destructuring is handled in function declarations. It is still far from perfect, and a major problem right now is how to support multiple lines in lambda functions
1 parent d8c18d9 commit 36f34b2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

syntax/javascript.vim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,16 @@ exe 'syntax match jsArrowFunction /=>/ skipwhite nextgroup=jsFuncBlock contains=
218218

219219
syntax match jsGenerator contained '\*' nextgroup=jsFuncName,jsFuncArgs skipwhite
220220
syntax match jsFuncName contained /\<[a-zA-Z_$][0-9a-zA-Z_$]*/ nextgroup=jsFuncArgs skipwhite
221-
syntax region jsFuncArgs contained matchgroup=jsFuncParens start='(' end=')' contains=jsFuncArgCommas,jsFuncArgRest,jsAssignmentExpr,jsComment,jsLineComment nextgroup=jsFuncBlock keepend skipwhite skipempty
221+
syntax region jsFuncArgs contained matchgroup=jsFuncParens start='(' end=')' contains=jsFuncArgCommas,jsFuncArgRest,jsComment,jsLineComment,jsStringS,jsStringD,jsNumber,jsFuncArgDestructuring nextgroup=jsFuncBlock keepend skipwhite skipempty
222222
syntax match jsFuncArgCommas contained ','
223223
syntax match jsFuncArgRest contained /\%(\.\.\.[a-zA-Z_$][0-9a-zA-Z_$]*\))/ contains=jsFuncArgRestDots
224224
syntax match jsFuncArgRestDots contained /\.\.\./
225+
syntax match jsFuncArgDestructuring contained /\({\|}\|=\|:\|(\|)\)/ extend
225226

226227
" Matches a single keyword argument with no parens
227-
syntax match jsArrowFuncArgs /\(\k\)\+\s\+\(=>\)\@=/ skipwhite contains=jsFuncArgs extend
228+
syntax match jsArrowFuncArgs /\(\k\)\+\s*\(=>\)\@=/ skipwhite contains=jsFuncArgs nextgroup=jsArrowFunction
228229
" Matches a series of arguments surrounded in parens
229-
syntax match jsArrowFuncArgs /(\(\k\|,\|\s\|\n\|\.\)*)\s\+\(=>\)\@=/ skipwhite contains=jsFuncArgs extend
230+
syntax match jsArrowFuncArgs /(\%(.\)*)\s*\(=>\)\@=/ skipempty skipwhite contains=jsFuncArgs nextgroup=jsArrowFunction
230231

231232
syntax keyword jsClassKeywords extends class contained
232233
syntax match jsClassNoise /\./ contained
@@ -323,6 +324,7 @@ if version >= 508 || !exists("did_javascript_syn_inits")
323324
HiLink jsModuleWords Include
324325
HiLink jsDecorator Special
325326
HiLink jsFuncArgRestDots Noise
327+
HiLink jsFuncArgDestructuring Noise
326328

327329
HiLink jsDomErrNo Constant
328330
HiLink jsDomNodeConsts Constant

0 commit comments

Comments
 (0)