robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:8607192: runtime(typescriptreact): fix highlighting nested and escaped quotes in string props (vim/vim#14852)ffbd09ef6a

master
4.0 KiB161 linesraw
1" Vim syntax file
2" Language:     TypeScript with React (JSX)
3" Maintainer:   The Vim Project <https://github.com/vim/vim>
4" Last Change:  2024 May 26
5" Based On:     Herrington Darkholme's yats.vim
6" Changes:      See https://github.com/HerringtonDarkholme/yats.vim
7" Credits:      See yats.vim on github
8
9if !exists("main_syntax")
10  if exists("b:current_syntax")
11    finish
12  endif
13  let main_syntax = 'typescriptreact'
14endif
15
16let s:cpo_save = &cpo
17set cpo&vim
18
19syntax region tsxTag
20      \ start=+<\([^/!?<>="':]\+\)\@=+
21      \ skip=+</[^ /!?<>"']\+>+
22      \ end=+/\@<!>+
23      \ end=+\(/>\)\@=+
24      \ contained
25      \ contains=tsxTagName,tsxIntrinsicTagName,tsxAttrib,tsxEscJs,
26                \tsxCloseString,@tsxComment
27
28syntax match tsxTag /<>/ contained
29
30
31" <tag></tag>
32" s~~~~~~~~~e
33" and self close tag
34" <tag/>
35" s~~~~e
36" A big start regexp borrowed from https://git.io/vDyxc
37syntax region tsxRegion
38      \ start=+<\_s*\z([a-zA-Z1-9\$_-]\+\(\.\k\+\)*\)+
39      \ skip=+<!--\_.\{-}-->+
40      \ end=+</\_s*\z1>+
41      \ matchgroup=tsxCloseString end=+/>+
42      \ fold
43      \ contains=tsxRegion,tsxCloseString,tsxCloseTag,tsxTag,tsxCommentInvalid,tsxFragment,tsxEscJs,@Spell
44      \ keepend
45      \ extend
46
47" <>   </>
48" s~~~~~~e
49" A big start regexp borrowed from https://git.io/vDyxc
50syntax region tsxFragment
51      \ start=+\(\((\|{\|}\|\[\|,\|&&\|||\|?\|:\|=\|=>\|\Wreturn\|^return\|\Wdefault\|^\|>\)\_s*\)\@<=<>+
52      \ skip=+<!--\_.\{-}-->+
53      \ end=+</>+
54      \ fold
55      \ contains=tsxRegion,tsxCloseString,tsxCloseTag,tsxTag,tsxCommentInvalid,tsxFragment,tsxEscJs,@Spell
56      \ keepend
57      \ extend
58
59" </tag>
60" ~~~~~~
61syntax match tsxCloseTag
62      \ +</\_s*[^/!?<>"']\+>+
63      \ contained
64      \ contains=tsxTagName,tsxIntrinsicTagName
65
66syntax match tsxCloseTag +</>+ contained
67
68syntax match tsxCloseString
69      \ +/>+
70      \ contained
71
72" <!-- -->
73" ~~~~~~~~
74syntax match tsxCommentInvalid /<!--\_.\{-}-->/ display
75
76syntax region tsxBlockComment
77    \ contained
78    \ start="/\*"
79    \ end="\*/"
80
81syntax match tsxLineComment
82    \ "//.*$"
83    \ contained
84    \ display
85
86syntax cluster tsxComment contains=tsxBlockComment,tsxLineComment
87
88syntax match tsxEntity "&[^; \t]*;" contains=tsxEntityPunct
89syntax match tsxEntityPunct contained "[&.;]"
90
91" <tag key={this.props.key}>
92"  ~~~
93syntax match tsxTagName
94    \ +[</]\_s*[^/!?<>"'* ]\++hs=s+1
95    \ contained
96    \ nextgroup=tsxAttrib
97    \ skipwhite
98    \ display
99syntax match tsxIntrinsicTagName
100    \ +[</]\_s*[a-z1-9-]\++hs=s+1
101    \ contained
102    \ nextgroup=tsxAttrib
103    \ skipwhite
104    \ display
105
106" <tag key={this.props.key}>
107"      ~~~
108syntax match tsxAttrib
109    \ +[a-zA-Z_][-0-9a-zA-Z_]*+
110    \ nextgroup=tsxEqual skipwhite
111    \ contained
112    \ display
113
114" <tag id="sample">
115"        ~
116syntax match tsxEqual +=+ display contained
117  \ nextgroup=tsxString skipwhite
118
119" <tag id="sample">
120"         s~~~~~~e
121syntax region tsxString contained start=+"+ skip=+\\"+ end=+"+ contains=tsxEntity,@Spell display
122syntax region tsxString contained start=+'+ skip=+\\'+ end=+'+ contains=tsxEntity,@Spell display
123
124" <tag key={this.props.key}>
125"          s~~~~~~~~~~~~~~e
126syntax region tsxEscJs
127    \ contained
128    \ contains=@typescriptValue,@tsxComment,typescriptObjectSpread
129    \ matchgroup=typescriptBraces
130    \ start=+{+
131    \ end=+}+
132    \ extend
133
134
135"""""""""""""""""""""""""""""""""""""""""""""""""""
136" Source the part common with typescriptreact.vim
137source <sfile>:h/shared/typescriptcommon.vim
138
139
140syntax cluster typescriptExpression add=tsxRegion,tsxFragment
141
142hi def link tsxTag htmlTag
143hi def link tsxTagName Function
144hi def link tsxIntrinsicTagName htmlTagName
145hi def link tsxString String
146hi def link tsxNameSpace Function
147hi def link tsxCommentInvalid Error
148hi def link tsxBlockComment Comment
149hi def link tsxLineComment Comment
150hi def link tsxAttrib Type
151hi def link tsxEscJs tsxEscapeJs
152hi def link tsxCloseTag htmlTag
153hi def link tsxCloseString Identifier
154
155let b:current_syntax = "typescriptreact"
156if main_syntax == 'typescriptreact'
157  unlet main_syntax
158endif
159
160let &cpo = s:cpo_save
161unlet s:cpo_save