lib/unparser/emitter/primitive.rb in unparser-0.6.12 vs lib/unparser/emitter/primitive.rb in unparser-0.6.13
- old
+ new
@@ -8,18 +8,44 @@
children :value
# Emitter for primitives based on Object#inspect
class Inspect < self
- handle :sym, :str
+ handle :str
private
def dispatch
write(value.inspect)
end
end # Inspect
+
+ class Symbol < self
+
+ handle :sym
+
+ private
+
+ # mutant:disable
+ def dispatch
+ 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
class Complex < self
handle :complex