Skip to content

Commit 0aa77f1

Browse files
zdenkoGeoffreyBooth
authored andcommitted
fix #4871 (#4872)
1 parent 1849f0d commit 0aa77f1

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

lib/coffeescript/rewriter.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rewriter.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ exports.Rewriter = class Rewriter
621621
tokens.splice i + 1, 0, indent, outdent
622622
return 1
623623
if tag in SINGLE_LINERS and @tag(i + 1) isnt 'INDENT' and
624-
not (tag is 'ELSE' and @tag(i + 1) is 'IF' and ifThens.length > 1) and
624+
not (tag is 'ELSE' and @tag(i + 1) is 'IF') and
625625
not conditionTag
626626
starter = tag
627627
[indent, outdent] = @indentation tokens[i]

test/control_flow.coffee

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,3 +1257,33 @@ test "#3909: backslash `for ... in`", ->
12571257
x8 = ( key for key \
12581258
in arr )
12591259
arrayEq x8, arr
1260+
1261+
test "#4871: `else if` no longer output together ", ->
1262+
eqJS '''
1263+
if a then b else if c then d else if e then f else g
1264+
''',
1265+
'''
1266+
if (a) {
1267+
b;
1268+
} else if (c) {
1269+
d;
1270+
} else if (e) {
1271+
f;
1272+
} else {
1273+
g;
1274+
}
1275+
'''
1276+
1277+
eqJS '''
1278+
if no
1279+
1
1280+
else if yes
1281+
2
1282+
''',
1283+
'''
1284+
if (false) {
1285+
1;
1286+
} else if (true) {
1287+
2;
1288+
}
1289+
'''

0 commit comments

Comments
 (0)