Skip to content

Commit 42a3b8f

Browse files
Earlopainschneems
authored andcommitted
Handle on_sp when using prism
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby/ruby#15914 * ruby/prism#3859
1 parent 20d1c51 commit 42a3b8f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## HEAD (unreleased)
22

3+
- Fix: Correctly identify trailing slashes when using Prism > 1.8.0. (https://github.com/ruby/syntax_suggest/pull/241)
34
- Internal: Add tests to multiple versions of prism
45

56
## 2.0.2

lib/syntax_suggest/code_line.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,13 @@ def ignore_newline_not_beg?
180180
# EOM
181181
# expect(lines.first.trailing_slash?).to eq(true)
182182
#
183-
if SyntaxSuggest.use_prism_parser?
183+
if SyntaxSuggest.use_prism_parser? && Prism::VERSION <= "1.8.0"
184+
# Older versions of prism didn't correctly emit on_sp
184185
def trailing_slash?
185186
last = @lex.last
186-
last&.type == :on_tstring_end
187+
return false unless last
188+
189+
last.type == :on_tstring_end || (last.type == :on_sp && last.token == TRAILING_SLASH)
187190
end
188191
else
189192
def trailing_slash?

0 commit comments

Comments
 (0)