forked from pangloss/vim-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.vim
More file actions
968 lines (830 loc) · 26.6 KB
/
Copy pathjavascript.vim
File metadata and controls
968 lines (830 loc) · 26.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
" Vim syntax file
" Language: JavaScript
" Author: Darrick Wiebe
" Maintainer: João Vieira <vieira@yubo.be>
" URL: https://github.com/pangloss/vim-javascript
if !exists("main_syntax")
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
let main_syntax = 'javascript'
endif
" Dollar sign is permitted anywhere in an identifier
if (v:version > 704 || v:version == 704 && has('patch1142')) && main_syntax == 'javascript'
syntax iskeyword @,48-57,_,192-255,$
else
setlocal iskeyword+=$
endif
syntax sync fromstart
" TODO: Figure out what type of casing I need
" syntax case ignore
syntax case match
syntax match jsNoise /[:,;]/
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 jsParensError /[)}\]]/
" Program Keywords
syntax keyword jsStorageClass const var let
\ skipwhite skipempty
\ nextgroup=jsDestructuringBlock,jsDestructuringArray,jsVariableDef
syntax match jsVariableDef contained /\<\K\k*/
\ skipwhite skipempty
\ nextgroup=tsDefinition
syntax keyword jsOperatorKeyword delete instanceof typeof void new in of
\ skipwhite skipempty
\ nextgroup=@jsExpression
syntax match jsOperator "[-!|&+<>=%/*~^]"
\ skipwhite skipempty
\ nextgroup=@jsExpression
syntax match jsOperator /::/
\ skipwhite skipempty
\ nextgroup=@jsExpression
syntax keyword jsBooleanTrue true
syntax keyword jsBooleanFalse false
" Modules
syntax keyword jsImport import
\ skipwhite skipempty
\ nextgroup=jsModuleAsterisk,jsModuleKeyword,jsModuleGroup,tsImportType
syntax keyword jsExport export
\ skipwhite skipempty
\ nextgroup=@jsAll,jsModuleGroup,jsExportDefault,jsModuleAsterisk,jsModuleKeyword,tsTypeStatement,tsInterfaceDefinition,tsEnumKeyword,tsDeclareKeyword
syntax match jsModuleKeyword contained /\<\K\k*/
\ skipwhite skipempty
\ nextgroup=jsModuleAs,jsFrom,jsModuleComma
syntax keyword jsExportDefault contained default
\ skipwhite skipempty
\ nextgroup=@jsExpression
syntax keyword jsExportDefaultGroup contained default
\ skipwhite skipempty
\ nextgroup=jsModuleAs,jsFrom,jsModuleComma
syntax match jsModuleAsterisk contained /\*/
\ skipwhite skipempty
\ nextgroup=jsModuleKeyword,jsModuleAs,jsFrom
syntax keyword jsModuleAs contained as
\ skipwhite skipempty
\ nextgroup=jsModuleKeyword,jsExportDefaultGroup
syntax keyword jsFrom contained from
\ skipwhite skipempty
\ nextgroup=jsString
syntax match jsModuleComma contained /,/
\ skipwhite skipempty
\ nextgroup=jsModuleKeyword,jsModuleAsterisk,jsModuleGroup,tsTypeKeyword
" Strings, Templates, Numbers
syntax region jsString start=+\z(["']\)+ skip=+\\\%(\z1\|$\)+ end=+\z1+ end=+$+
\ contains=jsSpecial extend
syntax region jsTemplateString start=+`+ skip=+\\`+ end=+`+
\ contains=jsTemplateExpression,jsSpecial extend
syntax match jsTaggedTemplate /\<\K\k*\ze`/
\ nextgroup=jsTemplateString
syntax keyword jsNumber Infinity
syntax match jsNumber /\c\<\%(\%(\d\|\d_\d\)\+\%(e[+-]\=\%(\d\|\d_\d\)\+\)\=\)n\=\>/
syntax match jsNumber /\c\<\%(0b\%([01]\|[01]_[01]\)\+\)\n\=\>/
syntax match jsNumber /\c\<\%(0o\%(\o\|\o_\o\)\+\)n\=\>/
syntax match jsNumber /\c\<\%(0x\%(\x\|\x_\x\)\+\)n\=\>/
syntax match jsFloat /\c\<\%(\%(\%(\d\|\d_\d\)\+\)\=\.\%(\%(\d\|\d_\d\)\+\)\=\)\%(e[+-]\=\%(\d\|\d_\d\)\+\)\=\>/
" Regular Expressions
syntax match jsSpecial contained "\v\\%(x\x\x|u%(\x{4}|\{\x{4,5}})|c\u|.)"
syntax region jsTemplateExpression contained
\ matchgroup=jsTemplateBraces
\ start=+${+ end=+}+
\ contains=@jsExpression keepend
syntax region jsRegexpCharClass contained
\ start=+\[+
\ skip=+\\.+
\ end=+\]+
\ contains=jsSpecial extend
syntax match jsRegexpBoundary contained "\v\c[$^]|\\b"
syntax match jsRegexpBackRef contained "\v\\[1-9]\d*"
syntax match jsRegexpQuantifier contained "\v[^\\]%([?*+]|\{\d+%(,\d*)?})\??"lc=1
syntax match jsRegexpOr contained "|"
syntax match jsRegexpMod contained "\v\(\?[:=!>]"lc=1
syntax region jsRegexpGroup contained
\ start="[^\\]("lc=1
\ skip="\\.\|\[\(\\.\|[^]]\+\)\]"
\ end=")"
\ contains=jsRegexpCharClass,@jsRegexpSpecial keepend
syntax region jsRegexpString
\ start=+\%(\%(\<return\|\<typeof\|\_[^)\]'"[:blank:][:alnum:]_$]\)\s*\)\@<=/\ze[^*/]+
\ skip=+\\.\|\[[^]]\{1,}\]+
\ end=+/[gimyus]\{,6}+
\ contains=jsRegexpCharClass,jsRegexpGroup,@jsRegexpSpecial
\ oneline keepend extend
syntax cluster jsRegexpSpecial
\ contains=jsSpecial,jsRegexpBoundary,jsRegexpBackRef,jsRegexpQuantifier,jsRegexpOr,jsRegexpMod
" Objects
syntax match jsObjectShorthandProp contained /\<\k*\ze\s*/
\ skipwhite skipempty
\ nextgroup=jsObjectSeparator
syntax match jsObjectKey contained /\<\k*\ze\s*:/
\ contains=jsFunctionKey
\ skipwhite skipempty
\ nextgroup=jsObjectValue
syntax region jsObjectKeyString contained
\ start=+\z(["']\)+
\ skip=+\\\%(\z1\|$\)+
\ end=+\z1\|$+
\ contains=jsSpecial skipwhite skipempty nextgroup=jsObjectValue
syntax region jsObjectKeyComputed contained
\ matchgroup=jsBrackets
\ start=/\[/
\ end=/]/
\ contains=@jsExpression
\ skipwhite skipempty
\ nextgroup=jsObjectValue,jsFuncArgs extend
syntax match jsObjectSeparator contained /,/
syntax region jsObjectValue contained
\ matchgroup=jsObjectColon
\ start=/:/
\ end=/[,}]\@=/
\ contains=@jsExpression extend
syntax match jsObjectFuncName contained /\<\K\k*\ze\_s*(/
\ skipwhite skipempty
\ nextgroup=jsFuncArgs
syntax match jsFunctionKey contained /\<\K\k*\ze\s*:\s*function\>/
syntax match jsObjectMethodType contained /\<[gs]et\ze\s\+\K\k*/
\ skipwhite skipempty
\ nextgroup=jsObjectFuncName
syntax region jsObjectStringKey contained
\ start=+\z(["']\)+
\ skip=+\\\%(\z1\|$\)+
\ end=+\z1\|$+
\ contains=jsSpecial extend
\ skipwhite skipempty
\ nextgroup=jsFuncArgs,jsObjectValue
syntax keyword jsNull null
syntax keyword jsUndefined undefined
syntax keyword jsNan NaN
syntax keyword jsPrototype prototype
syntax keyword jsThis this globalThis
syntax keyword jsSuper super contained
syntax keyword jsReturn return contained
\ skipwhite
\ nextgroup=@jsExpression
" Statement Keywords
syntax match jsBlockLabel /\<\K\k*\s*::\@!/
\ contains=jsNoise
\ skipwhite skipempty
\ nextgroup=jsBlock
syntax match jsBlockLabelKey contained /\<\K\k*\ze\s*\_[;]/
syntax keyword jsStatement contained with yield debugger
syntax keyword jsStatement contained break continue
\ skipwhite skipempty
\ nextgroup=jsBlockLabelKey
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 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
syntax keyword jsFinally contained finally
\ skipwhite skipempty
\ nextgroup=jsFinallyBlock
syntax keyword jsCatch contained catch
\ skipwhite skipempty
\ nextgroup=jsParenCatch,jsTryCatchBlock
syntax keyword jsException throw
syntax keyword jsAsyncKeyword async await
syntax match jsSwitchColon contained /::\@!/
\ skipwhite skipempty
\ nextgroup=jsSwitchBlock
" Keywords
syntax keyword jsGlobalObjects
\ Array
\ ArrayBuffer
\ AsyncFunction
\ Atomics
\ BigInt
\ BigInt64Array
\ BigUint64Array
\ Boolean
\ Buffer
\ Collator
\ DataView
\ Date
\ DateTimeFormat
\ FinalizationRegistry
\ Float32Array
\ Float64Array
\ Function
\ Generator
\ GeneratorFunction
\ Int16Array
\ Int32Array
\ Int8Array
\ Intl
\ Iterator
\ JSON
\ Map
\ Math
\ Number
\ Object
\ Promise
\ Proxy
\ Reflect
\ RegExp
\ Set
\ SharedArrayBuffer
\ String
\ Symbol
\ TypedArray
\ Uint16Array
\ Uint32Array
\ Uint8Array
\ Uint8ClampedArray
\ WeakMap
\ WeakRef
\ WeakSet
\ WebAssembly
\ console
\ document
\ fetch
\ window
syntax keyword jsGlobalNodeObjects
\ module
\ exports
\ global
\ process
\ __dirname
\ __filename
syntax match jsGlobalNodeObjects /\<require\>/
\ containedin=jsFuncCall
syntax keyword jsExceptions
\ Error
\ EvalError
\ RangeError
\ ReferenceError
\ SyntaxError
\ TypeError
\ URIError
\ AggregateError
\ InternalError
\ SystemError
\ AssertionError
syntax keyword jsBuiltins
\ decodeURI
\ decodeURIComponent
\ encodeURI
\ encodeURIComponent
\ eval
\ isFinite
\ isNaN
\ parseFloat
\ parseInt
" DISCUSS: Should we really be matching stuff like this?
" DOM2 Objects
syntax keyword jsGlobalObjects
\ DOMImplementation
\ DocumentFragment
\ Document
\ Node
\ NodeList
\ NamedNodeMap
\ CharacterData
\ Attr
\ Element
\ Text
\ Comment
\ CDATASection
\ DocumentType
\ Notation
\ Entity
\ EntityReference
\ ProcessingInstruction
syntax keyword jsExceptions DOMException
" DISCUSS: Should we really be special matching on these props?
" HTML events and internal variables
syntax keyword jsHtmlEvents
\ onblur
\ onclick
\ oncontextmenu
\ ondblclick
\ onfocus
\ onkeydown
\ onkeypress
\ onkeyup
\ onmousedown
\ onmousemove
\ onmouseout
\ onmouseover
\ onmouseup
\ onresize
" 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=tsDefinition
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 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,tsArgumentDef
\ skipwhite skipempty
\ nextgroup=jsCommentFunction,jsFuncBlock,tsReturn
\ extend fold
syntax region jsClassBlock contained
\ matchgroup=jsClassBraces
\ start=/{/
\ end=/}/
\ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsAsyncKeyword,jsModifier,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 jsDestructuringBlock contained
\ matchgroup=jsDestructuringBraces
\ start=/{/
\ end=/}/
\ contains=jsDestructuringProperty,jsDestructuringAssignment,jsDestructuringNoise,jsDestructuringPropertyComputed,jsSpreadExpression,jsComment
\ nextgroup=tsDefinition
\ extend fold
syntax region jsDestructuringArray contained
\ matchgroup=jsDestructuringBraces
\ start=/\[/
\ end=/\]/
\ contains=jsDestructuringPropertyValue,jsDestructuringNoise,jsDestructuringProperty,jsSpreadExpression,jsDestructuringBlock,jsDestructuringArray,jsComment
\ nextgroup=tsDefinition
\ 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
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,tsTypeKeyword
\ skipwhite skipempty
\ nextgroup=jsFrom
\ fold
syntax region jsSpreadExpression contained
\ matchgroup=jsSpreadOperator
\ start=/\.\.\./
\ end=/[,}\]]\@=/
\ contains=@jsExpression
syntax region jsRestExpression contained
\ matchgroup=jsRestOperator
\ start=/\.\.\./
\ end=/[,)]\@=/
syntax region jsTernaryIf
\ matchgroup=jsTernaryIfOperator
\ start=/?:\@!/
\ end=/\%(:\|}\@=\)/
\ contains=@jsExpression
\ extend skipwhite skipempty
\ nextgroup=@jsExpression
" These must occur here or they will be override by jsTernaryIf
syntax match jsOperator /?\.\ze\_D/
syntax match jsOperator /??/
\ skipwhite skipempty
\ nextgroup=@jsExpression
syntax match jsFuncArgPartApp contained /\%([(,]\s*\)\@<=?\%(\s*[,)]\)\@=/
\ containedin=jsFuncArgs
syntax match jsGenerator contained /\*/
\ skipwhite skipempty
\ nextgroup=jsFuncName,jsFuncArgs,tsFunctionGroup
syntax match jsFuncName contained /\<\K\k*/
\ skipwhite skipempty
\ nextgroup=jsFuncArgs,tsFunctionGroup
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
" Matches a single keyword argument with no parens
syntax match jsArrowFuncArgs /\<\K\k*\ze\s*=>/
\ contains=jsFuncArgs
\ skipwhite skipempty
\ nextgroup=jsArrowFunction extend
" Matches a series of arguments surrounded in parens
syntax match jsArrowFuncArgs /([^()]*)\ze\s*=>/
\ contains=jsFuncArgs
\ skipempty skipwhite
\ nextgroup=jsArrowFunction extend
syntax match jsFunction /\<function\>/
\ skipwhite skipempty
\ nextgroup=jsGenerator,jsFuncName,jsFuncArgs,tsFunctionGroup skipwhite
syntax match jsArrowFunction /=>/
\ skipwhite skipempty
\ nextgroup=jsFuncBlock,jsCommentFunction,tsType
syntax match jsArrowFunction /()\ze\s*=>/
\ skipwhite skipempty
\ nextgroup=jsArrowFunction
syntax match jsArrowFunction /_\ze\s*=>/
\ skipwhite skipempty
\ nextgroup=jsArrowFunction
" Classes
syntax match jsModifier contained /\#/
syntax keyword jsClassKeyword contained class
syntax keyword jsExtendsKeyword contained extends
\ skipwhite skipempty
\ nextgroup=@jsExpression
syntax match jsClassNoise contained /\./
syntax match jsClassFuncName contained /\<\K\k*\ze\s*[(<]/
\ skipwhite skipempty
\ nextgroup=jsFuncArgs,tsClassFunctionGroup
syntax match jsClassMethodType contained
\ /\<\%([gs]et\|static\)\ze\s\+\%(\#\)\=\K\k*/
\ skipwhite skipempty
\ nextgroup=jsAsyncKeyword,jsClassFuncName,jsClassProperty
syntax region jsClassDefinition start=/\<class\>/ end=/\(\<extends\>\s\+\)\@<!{\@=/
\ contains=jsClassKeyword,tsImplementsKeyword,jsExtendsKeyword,jsClassNoise,@jsExpression,tsClassGroup
\ skipwhite skipempty
\ nextgroup=jsCommentClass,jsClassBlock,tsClassGroup
syntax match jsClassProperty contained /\<\K\k*\ze\s*[=;]/
\ skipwhite skipempty
\ nextgroup=jsClassValue,tsClassDef
syntax region jsClassValue contained
\ start=/=/
\ end=/\_[;}]\@=/
\ contains=@jsExpression
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
\ extend skipwhite skipempty
\ nextgroup=jsFuncArgs
" Destructuring
syntax match jsDestructuringPropertyValue contained /\k\+/
syntax match jsDestructuringProperty contained /\k\+\ze\s*=/
\ skipwhite skipempty
\ nextgroup=jsDestructuringValue
syntax match jsDestructuringAssignment contained /\k\+\ze\s*:/
\ skipwhite skipempty
\ nextgroup=jsDestructuringValueAssignment
syntax region jsDestructuringValue contained
\ start=/=/
\ end=/[,}\]]\@=/
\ contains=@jsExpression extend
syntax region jsDestructuringValueAssignment contained
\ start=/:/
\ end=/[,}=]\@=/
\ contains=jsDestructuringPropertyValue,jsDestructuringBlock,jsNoise,jsDestructuringNoise
\ skipwhite skipempty
\ nextgroup=jsDestructuringValue extend
syntax match jsDestructuringNoise contained /[,[\]]/
syntax region jsDestructuringPropertyComputed contained
\ matchgroup=jsDestructuringBraces
\ start=/\[/
\ end=/]/
\ contains=@jsExpression
\ skipwhite skipempty
\ nextgroup=jsDestructuringValue,jsDestructuringValueAssignment,jsDestructuringNoise extend fold
" Comments
syntax keyword jsCommentTodo contained TODO FIXME XXX TBD NOTE
syntax region jsEnvComment start=/\%^#!/ end=/$/ display
syntax region jsComment
\ start=+//+
\ end=/$/
\ contains=jsCommentTodo,@Spell
\ extend keepend
syntax region jsComment
\ start=+/\*+
\ end=+\*/+
\ contains=jsCommentTodo,@Spell
\ fold extend keepend
" Specialized Comments - These are special comment regexes that are used in
" odd places that maintain the proper nextgroup functionality. It sucks we
" can't make jsComment a skippable type of group for nextgroup
syntax region jsCommentFunction contained
\ start=+//+
\ end=/$/
\ contains=jsCommentTodo,@Spell
\ skipwhite skipempty
\ nextgroup=jsFuncBlock,tsReturn
\ extend keepend
syntax region jsCommentFunction contained
\ start=+/\*+
\ end=+\*/+
\ contains=jsCommentTodo,@Spell
\ skipwhite skipempty
\ nextgroup=jsFuncBlock,tsReturn
\ fold extend keepend
syntax region jsCommentClass contained
\ start=+//+
\ end=/$/
\ contains=jsCommentTodo,@Spell
\ skipwhite skipempty
\ nextgroup=jsClassBlock,tsClassGroup
\ extend keepend
syntax region jsCommentClass contained
\ start=+/\*+
\ end=+\*/+
\ contains=jsCommentTodo,@Spell
\ skipwhite skipempty
\ nextgroup=jsClassBlock,tsClassGroup
\ fold extend keepend
syntax region jsCommentIfElse contained
\ start=+//+
\ end=/$/
\ contains=jsCommentTodo,@Spell
\ skipwhite skipempty
\ nextgroup=jsIfElseBlock
\ extend keepend
syntax region jsCommentIfElse contained
\ start=+/\*+
\ end=+\*/+
\ contains=jsCommentTodo,@Spell
\ skipwhite skipempty
\ nextgroup=jsIfElseBlock
\ fold extend keepend
syntax region jsCommentRepeat contained
\ start=+//+
\ end=/$/
\ contains=jsCommentTodo,@Spell
\ skipwhite skipempty
\ nextgroup=jsRepeatBlock
\ extend keepend
syntax region jsCommentRepeat contained
\ start=+/\*+
\ end=+\*/+
\ contains=jsCommentTodo,@Spell
\ skipwhite skipempty
\ nextgroup=jsRepeatBlock
\ fold extend keepend
" Decorators
syntax match jsDecorator /^\s*@/
\ nextgroup=jsDecoratorFunction
syntax match jsDecoratorFunction
\ contained /\h[a-zA-Z0-9_.]*/
\ nextgroup=jsParenDecorator
if exists("javascript_plugin_jsdoc")
runtime extras/jsdoc.vim
" NGDoc requires JSDoc
if exists("javascript_plugin_ngdoc")
runtime extras/ngdoc.vim
endif
endif
if exists("javascript_plugin_typescript")
runtime extras/typescript.vim
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,tsInterfaceDefinition,jsArrowFunction,jsArrowFuncArgs,jsParensError,jsComment,jsArguments,jsThis,jsSuper,jsDo,jsForAwait,jsAsyncKeyword,jsStatement,jsDot,tsAssertion,jsFuncArgPartApp
syntax cluster jsAll contains=@jsExpression,jsStorageClass,jsConditional,jsRepeat,jsReturn,jsException,jsTry,jsNoise,jsBlockLabel,jsModifier,tsAssertion
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_javascript_syn_inits")
if version < 508
let did_javascript_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink jsComment Comment
HiLink jsEnvComment PreProc
HiLink jsParensIfElse jsParens
HiLink jsParensRepeat jsParens
HiLink jsParensSwitch jsParens
HiLink jsParensCatch jsParens
HiLink jsCommentTodo Todo
HiLink jsString String
HiLink jsObjectKeyString String
HiLink jsTemplateString String
HiLink jsObjectStringKey String
HiLink jsClassStringKey String
HiLink jsTaggedTemplate StorageClass
HiLink jsTernaryIfOperator Operator
HiLink jsRegexpString String
HiLink jsRegexpBoundary SpecialChar
HiLink jsRegexpQuantifier SpecialChar
HiLink jsRegexpOr Conditional
HiLink jsRegexpMod SpecialChar
HiLink jsRegexpBackRef SpecialChar
HiLink jsRegexpGroup jsRegexpString
HiLink jsRegexpCharClass Character
HiLink jsCharacter Character
HiLink jsPrototype Special
HiLink jsConditional Conditional
HiLink jsBranch Conditional
HiLink jsLabel Label
HiLink jsReturn Statement
HiLink jsRepeat Repeat
HiLink jsDo Repeat
HiLink jsStatement Statement
HiLink jsException Exception
HiLink jsTry Exception
HiLink jsFinally Exception
HiLink jsCatch Exception
HiLink jsAsyncKeyword Keyword
HiLink jsForAwait Keyword
HiLink jsArrowFunction Type
HiLink jsFunction Type
HiLink jsGenerator jsFunction
HiLink jsArrowFuncArgs jsFuncArgs
HiLink jsFuncName Function
HiLink jsFuncCall Function
HiLink jsClassFuncName jsFuncName
HiLink jsObjectFuncName Function
HiLink jsArguments Special
HiLink jsFuncArgPartApp Special
HiLink jsError Error
HiLink jsParensError Error
HiLink jsOperatorKeyword jsOperator
HiLink jsOperator Operator
HiLink jsModifier PreProc
HiLink jsOf Operator
HiLink jsStorageClass StorageClass
HiLink jsClassKeyword Keyword
HiLink jsExtendsKeyword Keyword
HiLink jsThis Special
HiLink jsSuper Constant
HiLink jsNan Number
HiLink jsNull Type
HiLink jsUndefined Type
HiLink jsNumber Number
HiLink jsFloat Float
HiLink jsBooleanTrue Boolean
HiLink jsBooleanFalse Boolean
HiLink jsObjectColon jsNoise
HiLink jsNoise Noise
HiLink jsDot Noise
HiLink jsBrackets Noise
HiLink jsParens Noise
HiLink jsBraces Noise
HiLink jsFuncBraces Noise
HiLink jsFuncParens Noise
HiLink jsClassBraces Noise
HiLink jsClassNoise Noise
HiLink jsIfElseBraces Noise
HiLink jsTryCatchBraces Noise
HiLink jsModuleBraces Noise
HiLink jsObjectBraces Noise
HiLink jsObjectSeparator Noise
HiLink jsFinallyBraces Noise
HiLink jsRepeatBraces Noise
HiLink jsSwitchBraces Noise
HiLink jsSpecial Special
HiLink jsTemplateBraces Noise
HiLink jsGlobalObjects Constant
HiLink jsGlobalNodeObjects Constant
HiLink jsExceptions Constant
HiLink jsBuiltins Constant
HiLink jsImport Include
HiLink jsExport Include
HiLink jsExportDefault StorageClass
HiLink jsExportDefaultGroup jsExportDefault
HiLink jsModuleAs Include
HiLink jsModuleComma jsNoise
HiLink jsModuleAsterisk Noise
HiLink jsFrom Include
HiLink jsDecorator Special
HiLink jsDecoratorFunction Function
HiLink jsParensDecorator jsParens
HiLink jsFuncArgOperator jsFuncArgs
HiLink jsClassProperty jsObjectKey
HiLink jsObjectShorthandProp jsObjectKey
HiLink jsSpreadOperator Operator
HiLink jsRestOperator Operator
HiLink jsRestExpression jsFuncArgs
HiLink jsSwitchColon Noise
HiLink jsClassMethodType Type
HiLink jsObjectMethodType Type
HiLink jsClassDefinition jsFuncName
HiLink jsBlockLabel Identifier
HiLink jsBlockLabelKey jsBlockLabel
HiLink jsDestructuringBraces Noise
HiLink jsDestructuringProperty jsFuncArgs
HiLink jsDestructuringAssignment jsObjectKey
HiLink jsDestructuringNoise Noise
HiLink jsCommentFunction jsComment
HiLink jsCommentClass jsComment
HiLink jsCommentIfElse jsComment
HiLink jsCommentRepeat jsComment
HiLink jsDomErrNo Constant
HiLink jsDomNodeConsts Constant
HiLink jsHtmlEvents Special
delcommand HiLink
endif
" Define the htmlJavaScript for HTML syntax html.vim
syntax cluster htmlJavaScript contains=@jsAll,jsImport,jsExport
syntax cluster javaScriptExpression contains=@jsAll
" Vim's default html.vim highlights all javascript as 'Special'
hi! def link javaScript NONE
let b:current_syntax = "javascript"
if main_syntax == 'javascript'
unlet main_syntax
endif