22" Language: Javascript
33" Maintainer: Chris Paul ( https://github.com/bounceme )
44" URL: https://github.com/pangloss/vim-javascript
5- " Last Change: June 15 , 2017
5+ " Last Change: June 27 , 2017
66
77" Only load this indent file when no other was loaded.
88if exists (' b:did_indent' )
@@ -204,9 +204,10 @@ function s:ExprCol()
204204 endif
205205 elseif tok == ' ?'
206206 let bal += 1
207- elseif tok == ' {' && ! s: IsBlock ()
208- let bal = 1
209- elseif tok != ' }' || ! s: GetPair (' {' ,' }' ,' bW' ,s: skip_expr ,200 )
207+ elseif tok == ' {'
208+ let bal = ! s: IsBlock ()
209+ break
210+ elseif ! s: GetPair (' {' ,' }' ,' bW' ,s: skip_expr ,200 )
210211 break
211212 endif
212213 endwhile
@@ -271,9 +272,8 @@ endfunction
271272
272273" Check if line 'lnum' has a balanced amount of parentheses.
273274function s: Balanced (lnum)
274- let l: open = 0
275- let l: line = getline (a: lnum )
276- let pos = match (l: line , ' [][(){}]' , 0 )
275+ let [l: open , l: line ] = [0 , getline (a: lnum )]
276+ let pos = match (l: line , ' [][(){}]' )
277277 while pos != -1
278278 if s: SynAt (a: lnum ,pos + 1 ) !~? b: syng_strcom
279279 let l: open += match (' ' . l: line [pos],' [[({]' )
@@ -289,9 +289,8 @@ function s:Balanced(lnum)
289289endfunction
290290
291291function s: OneScope (lnum)
292- let pline = s: Trim (a: lnum )
292+ let [ pline, kw] = [ s: Trim (a: lnum ), ' else do ' ]
293293 call cursor (a: lnum ,strlen (pline))
294- let kw = ' else do'
295294 if pline[-1 :] == ' )' && s: GetPair (' (' , ' )' , ' bW' , s: skip_expr , 100 )
296295 if s: PreviousToken () = ~# ' ^\%(await\|each\)$'
297296 call s: PreviousToken ()
@@ -325,8 +324,8 @@ endfunction
325324" a continued expression, which could have started in a braceless context
326325function s: IsContOne (i ,num,cont)
327326 let [l: i , l: num , b_l] = [a: i , a: num + ! a: num , 0 ]
328- let pind = a: num ? indent (l : num ) + s: sw () : 0
329- let ind = indent (l : i ) + (a: cont ? 0 : s: sw ())
327+ let pind = a: num ? indent (a : num ) + s: sw () : 0
328+ let ind = indent (a : i ) + (a: cont ? 0 : s: sw ())
330329 while l: i >= l: num && (ind > pind || l: i == l: num )
331330 if indent (l: i ) < ind && s: OneScope (l: i )
332331 let b_l += 1
@@ -387,12 +386,13 @@ function s:IsBlock()
387386endfunction
388387
389388function GetJavascriptIndent ()
390- let b: js_cache = get (b: ,' js_cache' ,[0 ,0 ,0 ])
391- let s: synid_cache = {}
392- " Get the current line.
393- let l: line = getline (v: lnum )
389+ let [b: js_cache , s: synid_cache , l: line , s: stack ] = [
390+ \ get (b: ,' js_cache' ,[0 ,0 ,0 ]),
391+ \ {},
392+ \ getline (v: lnum ),
393+ \ map (synstack (v: lnum ,1 )," synIDattr(v:val,'name')" ),
394+ \ ]
394395 " use synstack as it validates syn state and works in an empty line
395- let s: stack = map (synstack (v: lnum ,1 )," synIDattr(v:val,'name')" )
396396 let syns = get (s: stack ,-1 ,' ' )
397397
398398 " start with strings,comments,etc.
0 commit comments