Class: Opal::Rewriters::Hashes::KeyDuplicatesRewriter
- Inherits:
-
Base
- Object
- Parser::AST::Processor
- Base
- Opal::Rewriters::Hashes::KeyDuplicatesRewriter
- Defined in:
- opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb
Defined Under Namespace
Classes: UniqKeysSet
Instance Method Summary collapse
-
#initialize ⇒ KeyDuplicatesRewriter
constructor
A new instance of KeyDuplicatesRewriter.
- #on_hash(node) ⇒ Object
- #on_kwsplat(node) ⇒ Object
- #on_pair(node) ⇒ Object
Methods inherited from Base
#append_to_body, #prepend_to_body, #s, s
Constructor Details
#initialize ⇒ KeyDuplicatesRewriter
Returns a new instance of KeyDuplicatesRewriter
9 10 11 |
# File 'opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb', line 9 def initialize @keys = UniqKeysSet.new end |
Instance Method Details
#on_hash(node) ⇒ Object
13 14 15 16 17 18 |
# File 'opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb', line 13 def on_hash(node) previous_keys, @keys = @keys, UniqKeysSet.new super(node) ensure @keys = previous_keys end |
#on_kwsplat(node) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb', line 30 def on_kwsplat(node) hash, _ = *node if hash.type == :hash hash = process_regular_node(hash) end node.updated(nil, [hash]) end |
#on_pair(node) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb', line 20 def on_pair(node) key, _value = *node if %i(str sym).include?(key.type) @keys << key end super(node) end |