Skip to content

Commit 951bc19

Browse files
committed
refactor jsxRegion start regex. fix #8
1 parent 4caf3b7 commit 951bc19

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

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: 16 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,7 @@ 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>
2739
</div>
2840
}
2941
}
@@ -96,6 +108,7 @@ export const Hoge = () => (
96108
hoge={aaa}
97109
hoge={aaa}
98110
/>
111+
{foo && <div>foo</div>}
99112
</div>
100113
)
101114

0 commit comments

Comments
 (0)