1" Vim syntax file 2" Language: JavaScript 3" Maintainer: Claudio Fleiner <[email protected]> 4" Updaters: Scott Shattuck (ss) <[email protected]> 5" URL: http://www.fleiner.com/vim/syntax/javascript.vim 6" Changes: (ss) added keywords, reserved words, and other identifiers 7" (ss) repaired several quoting and grouping glitches 8" (ss) fixed regex parsing issue with multiple qualifiers [gi] 9" (ss) additional factoring of keywords, globals, and members 10" Last Change: 2021 Mar 30 11" 2013 Jun 12: adjusted javaScriptRegexpString (Kevin Locke) 12" 2018 Apr 14: adjusted javaScriptRegexpString (LongJohnCoder) 13 14" tuning parameters: 15" unlet javaScript_fold 16 17if !exists("main_syntax") 18 " quit when a syntax file was already loaded 19 if exists("b:current_syntax") 20 finish 21 endif 22 let main_syntax = 'javascript' 23elseif exists("b:current_syntax") && b:current_syntax == "javascript" 24 finish 25endif 26 27let s:cpo_save = &cpo 28set cpo&vim 29 30 31syn keyword javaScriptCommentTodo TODO FIXME XXX TBD contained 32syn match javaScriptLineComment "\/\/.*" contains=@Spell,javaScriptCommentTodo 33syn match javaScriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)" 34syn region javaScriptComment start="/\*" end="\*/" contains=@Spell,javaScriptCommentTodo 35syn match javaScriptSpecial "\\\d\d\d\|\\." 36syn region javaScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=javaScriptSpecial,@htmlPreproc 37syn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=javaScriptSpecial,@htmlPreproc 38syn region javaScriptStringT start=+`+ skip=+\\\\\|\\`+ end=+`+ contains=javaScriptSpecial,javaScriptEmbed,@htmlPreproc 39 40syn region javaScriptEmbed start=+${+ end=+}+ contains=@javaScriptEmbededExpr 41 42syn match javaScriptSpecialCharacter "'\\.'" 43syn match javaScriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>" 44syn match javaScriptNumber "-\=\<\d\+\%(_\d\+\)*\>" 45syn region javaScriptRegexpString start=+[,(=+]\s*/[^/*]+ms=e-1,me=e-1 skip=+\\\\\|\\/+ end=+/[gimuys]\{0,2\}\s*$+ end=+/[gimuys]\{0,2\}\s*[+;.,)\]}]+me=e-1 end=+/[gimuys]\{0,2\}\s\+\/+me=e-1 contains=@htmlPreproc,javaScriptComment oneline 46 47syn keyword javaScriptConditional if else switch 48syn keyword javaScriptRepeat while for do in 49syn keyword javaScriptBranch break continue 50syn keyword javaScriptOperator new delete instanceof typeof 51syn keyword javaScriptType Array Boolean Date Function Number Object String RegExp 52syn keyword javaScriptStatement return with await 53syn keyword javaScriptBoolean true false 54syn keyword javaScriptNull null undefined 55syn keyword javaScriptIdentifier arguments this var let 56syn keyword javaScriptLabel case default 57syn keyword javaScriptException try catch finally throw 58syn keyword javaScriptMessage alert confirm prompt status 59syn keyword javaScriptGlobal self window top parent 60syn keyword javaScriptMember document event location 61syn keyword javaScriptDeprecated escape unescape 62syn keyword javaScriptReserved abstract boolean byte char class const debugger double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile async 63 64syn cluster javaScriptEmbededExpr contains=javaScriptBoolean,javaScriptNull,javaScriptIdentifier,javaScriptStringD,javaScriptStringS,javaScriptStringT 65 66if exists("javaScript_fold") 67 syn match javaScriptFunction "\<function\>" 68 syn region javaScriptFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend 69 70 syn sync match javaScriptSync grouphere javaScriptFunctionFold "\<function\>" 71 syn sync match javaScriptSync grouphere NONE "^}" 72 73 setlocal foldmethod=syntax 74 setlocal foldtext=getline(v:foldstart) 75else 76 syn keyword javaScriptFunction function 77 syn match javaScriptBraces "[{}\[\]]" 78 syn match javaScriptParens "[()]" 79endif 80 81if main_syntax == "javascript" 82 syn sync fromstart 83 syn sync maxlines=100 84 85 syn sync ccomment javaScriptComment 86endif 87 88" Define the default highlighting. 89" Only when an item doesn't have highlighting yet 90hi def link javaScriptComment Comment 91hi def link javaScriptLineComment Comment 92hi def link javaScriptCommentTodo Todo 93hi def link javaScriptSpecial Special 94hi def link javaScriptStringS String 95hi def link javaScriptStringD String 96hi def link javaScriptStringT String 97hi def link javaScriptCharacter Character 98hi def link javaScriptSpecialCharacter javaScriptSpecial 99hi def link javaScriptNumber javaScriptValue 100hi def link javaScriptConditional Conditional 101hi def link javaScriptRepeat Repeat 102hi def link javaScriptBranch Conditional 103hi def link javaScriptOperator Operator 104hi def link javaScriptType Type 105hi def link javaScriptStatement Statement 106hi def link javaScriptFunction Function 107hi def link javaScriptBraces Function 108hi def link javaScriptError Error 109hi def link javaScrParenError javaScriptError 110hi def link javaScriptNull Keyword 111hi def link javaScriptBoolean Boolean 112hi def link javaScriptRegexpString String 113 114hi def link javaScriptIdentifier Identifier 115hi def link javaScriptLabel Label 116hi def link javaScriptException Exception 117hi def link javaScriptMessage Keyword 118hi def link javaScriptGlobal Keyword 119hi def link javaScriptMember Keyword 120hi def link javaScriptDeprecated Exception 121hi def link javaScriptReserved Keyword 122hi def link javaScriptDebug Debug 123hi def link javaScriptConstant Label 124hi def link javaScriptEmbed Special 125 126 127 128let b:current_syntax = "javascript" 129if main_syntax == 'javascript' 130 unlet main_syntax 131endif 132let &cpo = s:cpo_save 133unlet s:cpo_save 134 135" vim: ts=8 136