Skip to content

Commit 4d0851c

Browse files
committed
Fix parser translator tokens for comment-only file
In #3393 I made a mistake. When there is no previous token, it wraps around to -1. Oops
1 parent 01cbec9 commit 4d0851c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/prism/translation/parser/lexer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ def to_a
284284
value.chomp!
285285
location = range(token.location.start_offset, token.location.end_offset - 1)
286286

287-
prev_token = lexed[index - 2][0]
287+
prev_token = lexed[index - 2][0] if index - 2 >= 0
288288
next_token = lexed[index][0]
289289

290-
is_inline_comment = prev_token.location.start_line == token.location.start_line
290+
is_inline_comment = prev_token&.location&.start_line == token.location.start_line
291291
if is_inline_comment && !COMMENT_CONTINUATION_TYPES.include?(next_token&.type)
292292
tokens << [:tCOMMENT, [value, location]]
293293

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Foo

test/prism/snapshots/comment_single.txt

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

0 commit comments

Comments
 (0)