@@ -1895,23 +1895,22 @@ exports.If = class If extends Base
1895
1895
if exeq
1896
1896
return new If (@condition .invert (), @ elseBodyNode (), type : ' if' ).compile o
1897
1897
1898
+ indent = o .indent + TAB
1899
+ body = @ ensureBlock (@body ).compile merge o, {indent}
1898
1900
cond = @condition .compile o, LEVEL_PAREN
1899
- o .indent += TAB
1900
- body = @ ensureBlock (@body )
1901
- ifPart = " if (#{ cond} ) {\n #{ body .compile (o)} \n #{ @tab } }"
1901
+ ifPart = " if (#{ cond} ) {\n #{ body} \n #{ @tab } }"
1902
1902
ifPart = @tab + ifPart unless child
1903
1903
return ifPart unless @elseBody
1904
1904
ifPart + ' else ' + if @isChain
1905
- o .indent = @tab
1906
1905
o .chainChild = yes
1907
1906
@elseBody .unwrap ().compile o, LEVEL_TOP
1908
1907
else
1909
- " {\n #{ @elseBody .compile o , LEVEL_TOP } \n #{ @tab } }"
1908
+ " {\n #{ @elseBody .compile merge (o, {indent}) , LEVEL_TOP } \n #{ @tab } }"
1910
1909
1911
1910
# Compile the `If` as a conditional operator.
1912
1911
compileExpression : (o ) ->
1913
- cond = @condition .compile o, LEVEL_COND
1914
1912
body = @ bodyNode ().compile o, LEVEL_LIST
1913
+ cond = @condition .compile o, LEVEL_COND
1915
1914
alt = if @ elseBodyNode () then @ elseBodyNode ().compile (o, LEVEL_LIST) else ' void 0'
1916
1915
code = " #{ cond} ? #{ body} : #{ alt} "
1917
1916
if o .level >= LEVEL_COND then " (#{ code} )" else code
0 commit comments