Skip to content

Commit 51b5fd5

Browse files
authored
Merge pull request #19 from yuezk/syntax-improve
Improve syntax highlighting
2 parents 3d138a7 + 260d11a commit 51b5fd5

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

after/syntax/javascript.vim

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ endif
2727
" <tag id="sample" />
2828
" s~~~~~~~~~~~~~~~~~e
2929
syntax region jsxTag
30-
\ start=+<\([^ /!?<>="':]\+\)\@=+
30+
\ start=+<\([^/!?<>="':]\+\)\@=+
3131
\ skip=+</[^ /!?<>"']\+>+
3232
\ end=+/\@<!>+
3333
\ end=+\(/>\)\@=+
@@ -45,9 +45,9 @@ syntax region jsxTag
4545
" s~~~~e
4646
" A big start regexp borrowed from https://git.io/vDyxc
4747
syntax region jsxRegion
48-
\ start=+\(\((\|{\|}\|\[\|\]\|,\|&&\|||\|?\|:\|=\|=>\|\Wreturn\|^return\|\Wdefault\|^\|>\)\_s*\)\@<=<\z([_\$a-zA-Z]\(\.\?[\$0-9a-zA-Z]\+\)*\)+
48+
\ start=+\(\((\|{\|}\|\[\|\]\|,\|&&\|||\|?\|:\|=\|=>\|\Wreturn\|^return\|\Wdefault\|^\|>\)\_s*\)\@<=<\_s*\z([_\$a-zA-Z]\(\.\?[\$0-9a-zA-Z]\+\)*\)+
4949
\ skip=+<!--\_.\{-}-->+
50-
\ end=+</\z1>+
50+
\ end=+</\_s*\z1>+
5151
\ end=+/>+
5252
\ fold
5353
\ contains=jsxRegion,jsxCloseString,jsxCloseTag,jsxTag,jsxComment,jsFuncBlock,
@@ -58,9 +58,9 @@ syntax region jsxRegion
5858
" </tag>
5959
" ~~~~~~
6060
syntax match jsxCloseTag
61-
\ +</[^ /!?<>"']\+>+
61+
\ +</\_s*[^/!?<>"']\+>+
6262
\ contained
63-
\ contains=jsxNamespace,jsxAttribPunct
63+
\ contains=jsxNamespace
6464

6565
syntax match jsxCloseString
6666
\ +/>+
@@ -76,20 +76,17 @@ syntax match jsxEntityPunct contained "[&.;]"
7676
" <tag key={this.props.key}>
7777
" ~~~
7878
syntax match jsxTagName
79-
\ +[<]\@<=[^ /!?<>"']\++
79+
\ +<\_s*\zs[^/!?<>"']\++
8080
\ contained
8181
\ display
8282

8383
" <tag key={this.props.key}>
8484
" ~~~
8585
syntax match jsxAttrib
86-
\ +[-'"<]\@<!\<[a-zA-Z:_][-.0-9a-zA-Z0-9:_]*\>\(['"]\@!\|$\)+
86+
\ +\(\(<\_s*\)\@<!\_s\)\@<=\<[a-zA-Z_][-0-9a-zA-Z_]*\>\(\_s\+\|\_s*[=/>]\)\@=+
8787
\ contained
88-
\ contains=jsxAttribPunct,jsxAttribHook
8988
\ display
9089

91-
syntax match jsxAttribPunct +[:.]+ contained display
92-
9390
" <tag id="sample">
9491
" ~
9592
" syntax match jsxEqual +=+ display

sample.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class Hoge extends React.Component {
3434
super(props);
3535
this.state = { };
3636
if (foo <= 300) {
37-
return <div style={{margin:0}}>
37+
return < div style={{margin:0}}>
3838
<div>hello, world</div>
3939
<table.row hello="world">
4040
</table.row>
41-
</div>
41+
</ div>
4242
}
4343
}
4444

@@ -92,7 +92,7 @@ class Hoge extends React.Component {
9292
<div>
9393
{(hoge => {
9494
if (hoge) {
95-
return <div />;
95+
return <div foo-bar foo/>;
9696
}
9797
})()}
9898
</div>
@@ -103,8 +103,10 @@ class Hoge extends React.Component {
103103
export const Hoge = () => (
104104
<div>
105105
<div
106+
hoge
106107
hoge={aaa}
107108
hoge={aaa}
109+
hoge
108110
></div>
109111
<div
110112
hoge={aaa}

0 commit comments

Comments
 (0)