Skip to content

Commit

Permalink
Refine sameLine implicit object tagging [Fixes #4568] (#4598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Rosse authored and GeoffreyBooth committed Aug 3, 2017
1 parent 64c790f commit 2653b3b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/coffeescript/rewriter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/rewriter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ exports.Rewriter = class Rewriter

# Mark all enclosing objects as not sameLine
if tag in LINEBREAKS
for stackItem in stack by -1 when isImplicitObject stackItem
stackItem[2].sameLine = no
for stackItem in stack by -1
break unless isImplicit stackItem
stackItem[2].sameLine = no if isImplicitObject stackItem

newLine = prevTag is 'OUTDENT' or prevToken.newLine
if tag in IMPLICIT_END or tag in CALL_CLOSERS and newLine
Expand Down
10 changes: 10 additions & 0 deletions test/formatting.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ test "method call chaining inside objects", ->
.c
eq 42, result.b

test "#4568: refine sameLine implicit object tagging", ->
condition = yes
fn = -> yes

x =
fn bar: {
foo: 123
} if not condition
eq x, undefined

# Nested blocks caused by paren unwrapping
test "#1492: Nested blocks don't cause double semicolons", ->
js = CoffeeScript.compile '(0;0)'
Expand Down

0 comments on commit 2653b3b

Please sign in to comment.