Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Prism::Translation::Parser::Compiler#visit_assoc_node
visit_assoc_node(node)
lib/prism/translation/parser/compiler.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/prism/translation/parser/compiler.rb, line 111
def visit_assoc_node(node)
key = node.key
if in_pattern
if node.value.is_a?(ImplicitNode)
if key.is_a?(SymbolNode)
if key.opening.nil?
builder.match_hash_var([key.unescaped, srange(key.location)])
else
builder.match_hash_var_from_str(token(key.opening_loc), [builder.string_internal([key.unescaped, srange(key.value_loc)])], token(key.closing_loc))
end
else
builder.match_hash_var_from_str(token(key.opening_loc), visit_all(key.parts), token(key.closing_loc))
end
elsif key.opening.nil?
builder.pair_keyword([key.unescaped, srange(key.location)], visit(node.value))
else
builder.pair_quoted(token(key.opening_loc), [builder.string_internal([key.unescaped, srange(key.value_loc)])], token(key.closing_loc), visit(node.value))
end
elsif node.value.is_a?(ImplicitNode)
if (value = node.value.value).is_a?(LocalVariableReadNode)
builder.pair_keyword(
[key.unescaped, srange(key)],
builder.ident([value.name, srange(key.value_loc)]).updated(:lvar)
)
else
builder.pair_label([key.unescaped, srange(key.location)])
end
elsif node.operator_loc
builder.pair(visit(key), token(node.operator_loc), visit(node.value))
elsif key.is_a?(SymbolNode) && key.opening_loc.nil?
builder.pair_keyword([key.unescaped, srange(key.location)], visit(node.value))
else
parts =
if key.is_a?(SymbolNode)
[builder.string_internal([key.unescaped, srange(key.value_loc)])]
else
visit_all(key.parts)
end
builder.pair_quoted(token(key.opening_loc), parts, token(key.closing_loc), visit(node.value))
end
end
{ a: 1 }
^^^^