Skip to content

Commit baa07dd

Browse files
authored
refactor isblock for jsx (pangloss#668)
* react/jsx interpolated expressions * refactor isBlock
1 parent 7d30463 commit baa07dd

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

indent/javascript.vim

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Javascript
33
" Maintainer: Chris Paul ( https://github.com/bounceme )
44
" URL: https://github.com/pangloss/vim-javascript
5-
" Last Change: October 9, 2016
5+
" Last Change: October 12, 2016
66

77
" Only load this indent file when no other was loaded.
88
if exists('b:did_indent')
@@ -38,7 +38,6 @@ else
3838
endif
3939

4040
let s:line_pre = '^\s*\%(\%(\%(\/\*.\{-}\)\=\*\+\/\s*\)\=\)\@>'
41-
let s:line_term = '\s*\%(\%(\/\%(\%(\*.\{-}\*\/\)\|\%(\*\+\)\)\)\s*\)\=$'
4241

4342
let s:expr_case = '\<\%(\%(case\>\s*\S.\{-}\)\|default\)\s*:\C'
4443
" Regex of syntax group names that are or delimit string or are comments.
@@ -130,25 +129,32 @@ endfunction
130129
" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
131130
function s:IsBlock()
132131
if getline(line('.'))[col('.')-1] == '{'
133-
if search('\C\<return\s*\%#','nbW')
134-
return 0
135-
endif
136-
if search('\*\/\_s*\%#','bW') && synIDattr(synID(line('.'),col('.'),0),'name') =~? 'comment'
137-
call searchpair('\/\*','','\*\/','bW')
138-
endif
132+
let l:ln = line('.')
139133
if search('\S','bW')
140134
let char = getline(line('.'))[col('.')-1]
141-
if char =~# '\l'
135+
let prechar = getline(line('.'))[col('.')-2]
136+
if char == '/' && prechar == '*' && synIDattr(synID(line('.'),col('.'),0),'name') =~? 'comment'
137+
if !(search('\/\*','bW') && search('\S','bW'))
138+
return 1
139+
endif
140+
let char = getline(line('.'))[col('.')-1]
141+
let prechar = getline(line('.'))[col('.')-2]
142+
endif
143+
let syn = synIDattr(synID(line('.'),col('.')-1,0),'name')
144+
if syn =~? '\%(xml\|jsx\)'
145+
return char != '{'
146+
elseif char =~# '\l'
147+
if line('.') == l:ln && expand('<cword>') ==# 'return'
148+
return 0
149+
endif
142150
return expand('<cword>') !~#
143-
\ '^\%(var\|const\|let\|\%(im\|ex\)port\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)$'
151+
\ '^\%(var\|const\|let\|import\|export\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)$'
144152
elseif char == '>'
145-
return search('=\%#','bW') || synIDattr(synID(line('.'),col('.'),0),'name') =~? 'flownoise'
153+
return prechar == '=' || syn =~? '^jsflow'
146154
elseif char == ':'
147155
return strpart(getline(line('.')),0,col('.')) =~# s:expr_case . '$'
148-
elseif char == '{'
149-
return s:IsBlock()
150156
else
151-
return char !~# '[-=~!<*+,./?^%|&\[(]'
157+
return char !~# '[-=~!<*+,/?^%|&([]'
152158
endif
153159
else
154160
return 1

0 commit comments

Comments
 (0)