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 Jul 4, 2017
1 parent 9d82bf7 commit e4bf163
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/coffee-script/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 @@ -303,8 +303,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 e4bf163

Please sign in to comment.