Skip to content

Commit

Permalink
Replace regexp check with parse
Browse files Browse the repository at this point in the history
  • Loading branch information
prikha committed Jan 23, 2024
1 parent d8c0b59 commit 03c5722
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/unparser/emitter/primitive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ class Symbol < self

# mutant:disable
def dispatch
if RUBY_VERSION < '3.2' && value.match?(/=\z/)
if inspect_breaks_parsing?
write(":#{value.name.inspect}")
else
write(value.inspect)
end
end

# mutant:disable
def inspect_breaks_parsing?
return false unless RUBY_VERSION < '3.2.'

Unparser.parse(value.inspect)
false
rescue Parser::SyntaxError
true
end
end # Symbol

# Emitter for complex literals
Expand Down

0 comments on commit 03c5722

Please sign in to comment.