Skip to content

Commit bf32202

Browse files
authored
Fix implicit node coloring (#1215)
`{ lvar:, meth:, CONST: }` was unintentionally colored as "lvar:"(magenta), "meth"(cyna) + ":"(no-color), "CONST:"(magenta). All three labels should be colored as magenta.
1 parent 50a7961 commit bf32202

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

lib/irb/color.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ def visit_alias_method_node(node)
258258
super
259259
end
260260

261+
def visit_implicit_node(_node)
262+
# Label of implicit nodes are colored as LABEL in visit_symbol_node.
263+
# We need to prevent value part from being colored with another type.
264+
end
265+
261266
def visit_call_node(node)
262267
if node.call_operator_loc.nil? && OPERATORS.include?(node.name)
263268
# Operators should not be colored as method call

test/irb/test_color.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def test_colorize_code
137137
'ENV' => "#{BLUE}#{BOLD}#{UNDERLINE}ENV#{CLEAR}",
138138
'f do end' => "#{CYAN}f#{CLEAR} #{GREEN}do#{CLEAR} #{GREEN}end#{CLEAR}",
139139
'f true do end' => "#{CYAN}f#{CLEAR} #{CYAN}#{BOLD}true#{CLEAR} #{GREEN}do#{CLEAR} #{GREEN}end#{CLEAR}",
140+
'{"foo": 1, bar:, BAZ:}' => "{#{MAGENTA}\"foo\":#{CLEAR} #{BLUE}#{BOLD}1#{CLEAR}, #{MAGENTA}bar:#{CLEAR}, #{MAGENTA}BAZ:#{CLEAR}}",
140141
}
141142

142143
tests.each do |code, result|

0 commit comments

Comments
 (0)