Skip to content

Commit 2653b3b

Browse files
Julian RosseGeoffreyBooth
Julian Rosse
authored andcommitted
Refine sameLine implicit object tagging [Fixes #4568] (#4598)
1 parent 64c790f commit 2653b3b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/coffeescript/rewriter.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rewriter.coffee

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,9 @@ exports.Rewriter = class Rewriter
336336

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

342343
newLine = prevTag is 'OUTDENT' or prevToken.newLine
343344
if tag in IMPLICIT_END or tag in CALL_CLOSERS and newLine

test/formatting.coffee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ test "method call chaining inside objects", ->
232232
.c
233233
eq 42, result.b
234234

235+
test "#4568: refine sameLine implicit object tagging", ->
236+
condition = yes
237+
fn = -> yes
238+
239+
x =
240+
fn bar: {
241+
foo: 123
242+
} if not condition
243+
eq x, undefined
244+
235245
# Nested blocks caused by paren unwrapping
236246
test "#1492: Nested blocks don't cause double semicolons", ->
237247
js = CoffeeScript.compile '(0;0)'

0 commit comments

Comments
 (0)