Skip to content

Commit 7710cee

Browse files
committed
Fix up lex compat on Ruby HEAD
1 parent ceaa366 commit 7710cee

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/yarp/lex_compat.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ def result
574574
result = YARP.lex(source, @filepath)
575575
result_value = result.value
576576
previous_state = nil
577+
578+
# In previous versions of Ruby, Ripper wouldn't flush the bom before the
579+
# first token, so we had to have a hack in place to account for that. This
580+
# checks for that behavior.
581+
bom_flushed = Ripper.lex("\xEF\xBB\xBF# test")[0][0][1] == 0
577582
bom = source.byteslice(0..2) == "\xEF\xBB\xBF"
578583

579584
result_value.each_with_index do |(token, lex_state), index|
@@ -588,7 +593,7 @@ def result
588593
if bom && lineno == 1
589594
column -= 3
590595

591-
if index == 0 && column == 0
596+
if index == 0 && column == 0 && !bom_flushed
592597
flushed =
593598
case token.type
594599
when :BACK_REFERENCE, :INSTANCE_VARIABLE, :CLASS_VARIABLE,

0 commit comments

Comments
 (0)