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 d421720
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/unparser/emitter/primitive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ class Symbol < self

private

# 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 d421720

Please sign in to comment.