Skip to content

Commit 3642c33

Browse files
committed
Fix #4150: Correctly outdent ternary followed by method call
1 parent ac1b2b5 commit 3642c33

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/coffee-script/rewriter.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rewriter.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ class exports.Rewriter
398398
not (token[0] is 'TERMINATOR' and @tag(i + 1) in EXPRESSION_CLOSE) and
399399
not (token[0] is 'ELSE' and starter isnt 'THEN') and
400400
not (token[0] in ['CATCH', 'FINALLY'] and starter in ['->', '=>']) or
401-
token[0] in CALL_CLOSERS and @tokens[i - 1].newLine
401+
token[0] in CALL_CLOSERS and
402+
(@tokens[i - 1].newLine or @tokens[i - 1][0] is 'OUTDENT')
402403

403404
action = (token, i) ->
404405
@tokens.splice (if @tag(i - 1) is ',' then i - 1 else i), 0, outdent

test/formatting.coffee

+21
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,27 @@ test "#1495, method call chaining", ->
198198
).join ', '
199199
eq 'a, b, c', result
200200

201+
test "chaining after inline ternary", ->
202+
throws -> CoffeeScript.compile """
203+
if 0 then 1 else g
204+
a: 42
205+
.h()
206+
"""
207+
208+
# Wrap calls containing spilling ternary
209+
f = (x) -> h: x
210+
id = (x) -> x
211+
result = f if true then 42 else id
212+
a: 2
213+
.h
214+
eq 42, result
215+
216+
# Chaining within spilling ternary works
217+
result = f if false then 1 else id
218+
a: 3
219+
.a
220+
eq 3, result.h
221+
201222
# Nested blocks caused by paren unwrapping
202223
test "#1492: Nested blocks don't cause double semicolons", ->
203224
js = CoffeeScript.compile '(0;0)'

0 commit comments

Comments
 (0)