diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 25e4132e..37e2b668 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -31,7 +31,7 @@ syntax match jsFuncCall /\<\K\k*\ze\s*(/ syntax match jsParensError /[)}\]]/ " Program Keywords -syntax keyword jsStorageClass const var let skipwhite skipempty nextgroup=jsDestructuringBlock,jsDestructuringArray,jsVariableDef +syntax keyword jsStorageClass const var let skipwhite skipempty nextgroup=jsDestructuringBlock,jsDestructuringArray,jsVariableDef,jsFuncAssignment 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 match jsOperator "[-!|&+<>=%/*~^]" skipwhite skipempty nextgroup=@jsExpression @@ -141,7 +141,7 @@ syntax region jsParenRepeat contained matchgroup=jsParensRepeat s syntax region jsParenSwitch contained matchgroup=jsParensSwitch start=/(/ end=/)/ contains=@jsAll 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 jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsAsyncKeyword,jsNoise,jsFuncAssignment,@jsExpression 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 @@ -150,7 +150,7 @@ syntax region jsSwitchBlock contained matchgroup=jsSwitchBraces s syntax region jsRepeatBlock contained matchgroup=jsRepeatBraces start=/{/ end=/}/ contains=@jsAll,jsBlock 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,jsNoise,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 extend fold +syntax region jsObject contained matchgroup=jsObjectBraces start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectShorthandProp,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsDecorator,jsAsyncKeyword,jsPropFuncAssignment,@jsExpression extend fold syntax region jsBlock matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll,jsSpreadExpression extend fold syntax region jsModuleGroup contained matchgroup=jsModuleBraces start=/{/ end=/}/ contains=jsModuleKeyword,jsModuleComma,jsModuleAs,jsComment,jsFlowTypeKeyword skipwhite skipempty nextgroup=jsFrom fold syntax region jsSpreadExpression contained matchgroup=jsSpreadOperator start=/\.\.\./ end=/[,}\]]\@=/ contains=@jsExpression @@ -171,9 +171,8 @@ syntax match jsArrowFuncArgs /\<\K\k*\ze\s*=>/ skipwhite contains=jsFuncArgs syntax match jsArrowFuncArgs /([^()]*)\ze\s*=>/ contains=jsFuncArgs skipempty skipwhite nextgroup=jsArrowFunction extend exe 'syntax match jsFunction /\/ skipwhite skipempty nextgroup=jsGenerator,jsFuncName,jsFuncArgs,jsFlowFunctionGroup skipwhite '.(exists('g:javascript_conceal_function') ? 'conceal cchar='.g:javascript_conceal_function : '') -exe 'syntax match jsArrowFunction /=>/ skipwhite skipempty nextgroup=jsFuncBlock,jsCommentFunction '.(exists('g:javascript_conceal_arrow_function') ? 'conceal cchar='.g:javascript_conceal_arrow_function : '') -exe 'syntax match jsArrowFunction /()\ze\s*=>/ skipwhite skipempty nextgroup=jsArrowFunction '.(exists('g:javascript_conceal_noarg_arrow_function') ? 'conceal cchar='.g:javascript_conceal_noarg_arrow_function : '') -exe 'syntax match jsArrowFunction /_\ze\s*=>/ skipwhite skipempty nextgroup=jsArrowFunction '.(exists('g:javascript_conceal_underscore_arrow_function') ? 'conceal cchar='.g:javascript_conceal_underscore_arrow_function : '') +exe 'syntax match jsArrowFunction /=>/ skipwhite skipempty nextgroup=@jsExpression '.(exists('g:javascript_conceal_arrow_function') ? 'conceal cchar='.g:javascript_conceal_arrow_function : '') +exe 'syntax match jsArrowFunction /=>\%(\s*{\)\@=/ skipwhite skipempty nextgroup=jsFuncBlock,jsCommentFunction '.(exists('g:javascript_conceal_arrow_function') ? 'conceal cchar='.g:javascript_conceal_arrow_function : '') " Classes syntax keyword jsClassKeyword contained class @@ -187,6 +186,11 @@ syntax region jsClassValue contained start=/=/ end=/\_[;}]\@=/ cont syntax region jsClassPropertyComputed contained matchgroup=jsBrackets start=/\[/ end=/]/ contains=@jsExpression skipwhite skipempty nextgroup=jsFuncArgs,jsClassValue extend syntax region jsClassStringKey contained start=+\z(["']\)+ skip=+\\\%(\z1\|$\)+ end=+\z1\|$+ contains=jsSpecial,@Spell extend skipwhite skipempty nextgroup=jsFuncArgs +syntax match jsFuncAssignment contained /\<\K\k*\>\(\s*=\s*\%(async\s*\)\?(.*)\s*\%(=>\)\@=\)\@=/ skipwhite +syntax match jsFuncAssignment contained /\<\K\k*\>\(\s*=\s*\%(async\s*\)\?\k\+\s*\%(=>\)\@=\)\@=/ skipwhite +syntax match jsPropFuncAssignment contained /\<\K\k*\>\(\s*:\s*\%(async\s*\)\?(.*)\s*\%(=>\)\@=\)\@=/ skipwhite +syntax match jsPropFuncAssignment contained /\<\K\k*\>\(\s*:\s*\%(async\s*\)\?\k\+\s*\%(=>\)\@=\)\@=/ skipwhite + " Destructuring syntax match jsDestructuringPropertyValue contained /\k\+/ syntax match jsDestructuringProperty contained /\k\+\ze\s*=/ skipwhite skipempty nextgroup=jsDestructuringValue @@ -285,7 +289,8 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsGenerator jsFunction HiLink jsArrowFuncArgs jsFuncArgs HiLink jsFuncName Function - HiLink jsFuncCall Function + HiLink jsFuncAssignment Function + HiLink jsPropFuncAssignment Function HiLink jsClassFuncName jsFuncName HiLink jsObjectFuncName Function HiLink jsArguments Special diff --git a/test.js b/test.js new file mode 100644 index 00000000..f4092926 --- /dev/null +++ b/test.js @@ -0,0 +1,72 @@ +class C { + no = 123; + no = 'asdf'; + yes() {}; + async yes() {}; + yes = () => {}; + yes = x => {}; + yes = (a,b) => {}; + yes = async () => {}; + yes = async x => {}; + yes = async (a,b) => {}; + yes = () => someFn(); + yes = x => someFn(x); + yes = (a,b) => someFn({ a, b }); + yes = _ => new Promise((res, rej) => {}); + yes = a => b => c; + yes = (a,b) => c => someFn({ a, b, c }); +} + +const no = 123; +const no = 'asdf'; +function yes() {}; +async function yes() {}; +const yes = () => {}; +const yes = x => {}; +const yes = (a,b) => {}; +const yes = async () => {}; +const yes = async x => {}; +const yes = async (a,b) => {}; +const yes = () => someFn(); +const yes = x => someFn(x); +const yes = (a,b) => someFn({ a, b }); +const yes = _ => new Promise((res, rej) => {}); +const yes = a => b => c; +const yes = (a,b) => c => someFn({ a, b, c }); + +const obj = { + no: 123, + no: 'asdf', + yes() {}, + async yes() {}, + yes: () => {}, + yes: x => {}, + yes: (a,b) => {}, + yes: async () => {}, + yes: async x => {}, + yes: async (a,b) => {}, + yes: () => someFn(), + yes: x => someFn(x), + yes: (a,b) => someFn({ a, b }), + yes: _ => new Promise((res, rej):> {}), + yes: a => b => c, + yes: (a,b) => c => someFn({ a, b, c }), + no: { + no: 123, + no: 'asdf', + yes() {}, + async yes() {}, + yes: () => {}, + yes: x => {}, + yes: (a,b) => {}, + yes: async () => {}, + yes: async x => {}, + yes: async (a,b) => {}, + yes: () => someFn(), + yes: x => someFn(x), + yes: (a,b) => someFn({ a, b }), + yes: _ => new Promise((res, rej):> {}), + yes: a => b => c, + yes: (a,b) => c => someFn({ a, b, c }), + } +}