millermedeiros / esformatter

ECMAScript code beautifier/formatter
MIT License
970 stars 91 forks source link

if statement format wrong #446

Closed futurist closed 8 years ago

futurist commented 8 years ago

tested below if statement:

var a = 1
if(a>1) a=3
else{
  a=2
}

after formatted, the result:

var a = 1
if (a > 1)
  a = 3else {
  a = 2
}
millermedeiros commented 8 years ago

need to do something similar to: https://github.com/millermedeiros/esformatter/blob/master/lib/hooks/IfStatement.js#L33-L40 for the _br.limitBefore(elseKeyword, 'ElseStatement'); inside else if (alt.type === 'BlockStatement')

I won't have time to work on it this week, PRs are highly appreciated.

see: https://github.com/millermedeiros/esformatter/commit/a3599b7c092bbd636bfed154d95d7e6b49064e87 and #426