Class: RubyNext::Language::Rewriters::ShorthandHash
Constant Summary collapse
- NAME =
"shorthand-hash"- SYNTAX_PROBE =
"data = {x:}"- MIN_SUPPORTED_VERSION =
Gem::Version.new("3.1.0")
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Methods inherited from Abstract
ast?, #initialize, text?, transform, unsupported_syntax?, unsupported_version?
Constructor Details
This class inherits a constructor from RubyNext::Language::Rewriters::Base
Instance Method Details
#on_pair(node) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby-next/language/rewriters/3.1/shorthand_hash.rb', line 11 def on_pair(node) return super(node) unless (node.children[0].loc.last_column == node.children[1].loc.last_column) && (node.children[1].loc.first_line == node.children[1].loc.last_line) context.track! self _, ident, = *node.children key = key_from_ident(ident) replace( node.loc.expression, "#{key}: #{key}" ) node.updated( :pair, [ s(:sym, key), ident ] ) end |