Skip to content

Commit 006c32e

Browse files
authored
Merge pull request #16 from yuezk/syntax-improve
Refactor jsxRegion start regex.
2 parents 4caf3b7 + 9356f4b commit 006c32e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

after/syntax/javascript.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ syntax region jsxTag
4343
" and self close tag
4444
" <tag/>
4545
" s~~~~e
46+
" A big start regexp borrowed from https://git.io/vDyxc
4647
syntax region jsxRegion
47-
\ start=+<\z([^ /!?<>="':]\+\)+
48+
\ start=+\(\((\|{\|}\|\[\|\]\|,\|&&\|||\|?\|:\|=\|=>\|\Wreturn\|^return\|\Wdefault\|^\|>\)\_s*\)\@<=<\z([_\$a-zA-Z]\(\.\?[\$0-9a-zA-Z]\+\)*\)+
4849
\ skip=+<!--\_.\{-}-->+
4950
\ end=+</\z1>+
5051
\ end=+/>+

sample.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ class App extends Component {
33
// NOTCE: no `;` after.
44
const arr = <div></div>
55

6-
// Codes highlight incorrectly
76
var foo = 'foo';
87
if (foo === 'foo') {
98
console.log('hello');
@@ -12,8 +11,21 @@ class App extends Component {
1211
var el = a < 0
1312
? <div></div>
1413
: <a></a>
15-
14+
var a = (a>b)<a
1615
var b = el || <div>hello, world</div>
16+
var c = a<foo
17+
var d = a<foo
18+
var e = a>c
19+
20+
if (a<b && a<d || a>c){
21+
return <a></a>
22+
}
23+
24+
if (a < b ) {
25+
return b <a ? <div>hello</div>:<a>world</a>
26+
}
27+
28+
return b<a?<div>hello</div>:<a>world</a>
1729
}
1830
}
1931

@@ -23,7 +35,9 @@ class Hoge extends React.Component {
2335
this.state = { };
2436
if (foo <= 300) {
2537
return <div style={{margin:0}}>
26-
Hello world
38+
<div>hello, world</div>
39+
<table.row hello="world">
40+
</table.row>
2741
</div>
2842
}
2943
}
@@ -96,6 +110,7 @@ export const Hoge = () => (
96110
hoge={aaa}
97111
hoge={aaa}
98112
/>
113+
{foo && <div>foo</div>}
99114
</div>
100115
)
101116

0 commit comments

Comments
 (0)