Skip to content

Commit b8161a2

Browse files
committed
Ensure all nodes that could have heredocs nested know about their end lines.
1 parent b937a26 commit b8161a2

File tree

2 files changed

+7
-36
lines changed

2 files changed

+7
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1414
- Allow arrays of `CHAR` nodes to be converted to `QWords` under certain conditions.
1515
- Allow `Hash` opening braces to have trailing comments.
1616
- Add parentheses if `Yield` breaks onto multiple lines.
17+
- Ensure all nodes that could have heredocs nested know about their end lines.
1718

1819
### Changed
1920

lib/syntax_tree.rb

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def to(other)
7575
Location.new(
7676
start_line: start_line,
7777
start_char: start_char,
78-
end_line: other.end_line,
78+
end_line: [end_line, other.end_line].max,
7979
end_char: other.end_char
8080
)
8181
end
@@ -3146,13 +3146,7 @@ def on_call(receiver, operator, message)
31463146
receiver: receiver,
31473147
operator: operator,
31483148
message: message,
3149-
location:
3150-
Location.new(
3151-
start_line: receiver.location.start_line,
3152-
start_char: receiver.location.start_char,
3153-
end_line: [ending.location.end_line, receiver.location.end_line].max,
3154-
end_char: ending.location.end_char
3155-
)
3149+
location: receiver.location.to(ending.location)
31563150
)
31573151
end
31583152

@@ -3588,13 +3582,7 @@ def on_command(message, arguments)
35883582
Command.new(
35893583
message: message,
35903584
arguments: arguments,
3591-
location:
3592-
Location.new(
3593-
start_line: message.location.start_line,
3594-
start_char: message.location.start_char,
3595-
end_line: [message.location.end_line, arguments.location.end_line].max,
3596-
end_char: arguments.location.end_char
3597-
)
3585+
location: message.location.to(arguments.location)
35983586
)
35993587
end
36003588

@@ -3741,13 +3729,7 @@ def on_command_call(receiver, operator, message, arguments)
37413729
operator: operator,
37423730
message: message,
37433731
arguments: arguments,
3744-
location:
3745-
Location.new(
3746-
start_line: receiver.location.start_line,
3747-
start_char: receiver.location.start_char,
3748-
end_line: [receiver.location.end_line, ending.location.end_line].max,
3749-
end_char: ending.location.end_char
3750-
)
3732+
location: receiver.location.to(ending.location)
37513733
)
37523734
end
37533735

@@ -7001,13 +6983,7 @@ def on_if_mod(predicate, statement)
70016983
IfMod.new(
70026984
statement: statement,
70036985
predicate: predicate,
7004-
location:
7005-
Location.new(
7006-
start_line: statement.location.start_line,
7007-
start_char: statement.location.start_char,
7008-
end_line: [statement.location.end_line, predicate.location.end_line].max,
7009-
end_char: predicate.location.end_char
7010-
)
6986+
location: statement.location.to(predicate.location)
70116987
)
70126988
end
70136989

@@ -12159,13 +12135,7 @@ def on_unless_mod(predicate, statement)
1215912135
UnlessMod.new(
1216012136
statement: statement,
1216112137
predicate: predicate,
12162-
location:
12163-
Location.new(
12164-
start_line: statement.location.start_line,
12165-
start_char: statement.location.start_char,
12166-
end_line: [statement.location.end_line, predicate.location.end_line].max,
12167-
end_char: predicate.location.end_char
12168-
)
12138+
location: statement.location.to(predicate.location)
1216912139
)
1217012140
end
1217112141

0 commit comments

Comments
 (0)