Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 279d2a7

Browse files
committed
Properly handle trailing comments after a then operator on a When or In clause.
1 parent a77e4a1 commit 279d2a7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
5454
- Properly handle breaking parameters when there are no parentheses.
5555
- Properly handle trailing operators in call chains with attached comments.
5656
- Force using braces if the block is within the predicate of a ternary.
57+
- Properly handle trailing comments after a `then` operator on a `When` or `In` clause.
5758

5859
### Removed
5960

lib/syntax_tree.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7166,8 +7166,9 @@ def on_in(pattern, statements, consequent)
71667166
beginning = find_token(Kw, "in")
71677167
ending = consequent || find_token(Kw, "end")
71687168

7169+
statements_start = find_token(Kw, "then", consume: false) || pattern
71697170
statements.bind(
7170-
find_next_statement_start(pattern.location.end_char),
7171+
find_next_statement_start(statements_start.location.end_char),
71717172
ending.location.start_char
71727173
)
71737174

@@ -12758,8 +12759,9 @@ def on_when(arguments, statements, consequent)
1275812759
beginning = find_token(Kw, "when")
1275912760
ending = consequent || find_token(Kw, "end")
1276012761

12762+
statements_start = find_token(Kw, "then", consume: false) || arguments
1276112763
statements.bind(
12762-
find_next_statement_start(arguments.location.end_char),
12764+
find_next_statement_start(statements_start.location.end_char),
1276312765
ending.location.start_char
1276412766
)
1276512767

0 commit comments

Comments
 (0)