Skip to content

Commit 0d2d6ca

Browse files
committed
Fix indent config
Actual : ` test() { return ( <div> <Input /> <Button onClick={this.kepe.bind(this)} /> </div> ); } ` Expect : ` test() { return ( <div> <Input /> <Button onClick={this.kepe.bind(this)} /> </div> ); } `
1 parent 0fdd16f commit 0d2d6ca

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

after/indent/javascript.vim

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ else
3434
endfunction
3535
endif
3636

37+
let s:starttag = '^\s*<'
3738
let s:endtag = '^\s*\/\?>\s*;\='
3839
let s:real_endtag = '\s*<\/\+[A-Za-z]*>'
3940

@@ -65,7 +66,7 @@ function! s:syn_jsx_block_end(syns)
6566
\ s:syn_attr_jsx(get(a:syns, -2))
6667
endfunction
6768

68-
function! s:syn_jsx_depth(syns)
69+
function! s:syn_jsx_region(syns)
6970
return len(filter(copy(a:syns), 'v:val ==# "jsxRegion"'))
7071
endfunction
7172

@@ -86,8 +87,8 @@ function! s:syn_jsx_escapejs(syns)
8687
endfunction
8788

8889
function! s:syn_jsx_continues(cursyn, prevsyn)
89-
let curdepth = s:syn_jsx_depth(a:cursyn)
90-
let prevdepth = s:syn_jsx_depth(a:prevsyn)
90+
let curdepth = s:syn_jsx_region(a:cursyn)
91+
let prevdepth = s:syn_jsx_region(a:prevsyn)
9192

9293
return prevdepth == curdepth ||
9394
\ (prevdepth == curdepth + 1 && get(a:cursyn, -1) ==# 'jsxRegion')
@@ -113,15 +114,22 @@ function! GetJsxIndent()
113114
" <div | <div
114115
" hoge={ | hoge={
115116
" <div></div> | ##<div></div>
116-
if s:syn_jsx_escapejs(prevsyn) && !(getline(v:lnum - 1) =~? '}') && getline(v:lnum - 1) =~? '{'
117+
if s:syn_jsx_escapejs(prevsyn) && !(getline(v:lnum - 1) =~? '}')
118+
\&& getline(v:lnum - 1) =~? '{'
119+
let ind = ind + s:sw()
120+
endif
121+
122+
if getline(v:lnum) =~? s:starttag
123+
\&& getline(v:lnum) =~? '}' && getline(v:lnum) =~? '{'
117124
let ind = ind + s:sw()
118125
endif
119126

120127
" <div | <div
121128
" hoge={ | hoge={
122129
" <div></div> | <div></div>
123130
" } | }##
124-
if s:syn_jsx_escapejs(cursyn) && getline(v:lnum) =~? '}' && !(getline(v:lnum) =~? '{')
131+
if s:syn_jsx_escapejs(cursyn) && getline(v:lnum) =~? '}'
132+
\&& !(getline(v:lnum) =~? '{')
125133
let ind = ind - s:sw()
126134
endif
127135

@@ -133,7 +141,8 @@ function! GetJsxIndent()
133141
let ind = ind - s:sw()
134142
endif
135143

136-
if (s:syn_jsx_else_block(cursyn) || s:syn_js_repeat_braces(cursyn)) && s:syn_jsx_close_tag(prevsyn)
144+
if (s:syn_jsx_else_block(cursyn) || s:syn_js_repeat_braces(cursyn))
145+
\&& s:syn_jsx_close_tag(prevsyn)
137146
let ind = ind - s:sw()
138147
endif
139148
else

sample.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ class Hoge extends React.Component {
3939
);
4040
}
4141

42+
test() {
43+
return (
44+
<div>
45+
<Input a='a' />
46+
<Button onClick={this.kepe.bind(this)} />
47+
</div>
48+
);
49+
}
50+
4251
render() {
4352
return (
4453
<div>

0 commit comments

Comments
 (0)