lib/opal/nodes/hash.rb
# Compiles hashes containing kwsplats inside.
# hash like { **{ nested: 1 }, a: 1, **{ nested: 2} }
# should be compiled to
# { nested: 1}.merge(a: 1).merge(nested: 2)
# Each kwsplat overrides previosly defined keys
# Hash k/v pairs override previously defined kwsplat values
Compiles hashes containing kwsplats inside.
Compiles hashes containing kwsplats inside .
def compile_merge
        helper :hash
        result, seq = [], []
        children.each do |child|
          if child.type == :kwsplat
            unless seq.empty?
              result << expr(s(:hash, *seq))
            end
            result << expr(child)
            seq = []
          else
            seq << child
          end
        end
        unless seq.empty?
          result << expr(s(:hash, *seq))
        end
        result.each_with_index do |fragment, idx|
          if idx == 0
            push fragment
          else
            push '.$merge(', fragment, ')'
          end
        end
      end
def compile_merge helper :hash result , seq = [ ] , [ ] children . each do | child | if child . type == :kwsplat unless seq . empty? result << expr ( s ( :hash , * seq ) ) end result << expr ( child ) seq = [ ] else seq << child end end unless seq . empty? result << expr ( s ( :hash , * seq ) ) end result . each_with_index do | fragment , idx | if idx == 0 push fragment else push '.$merge(' , fragment , ')' end end end
Compiles hashes containing kwsplats inside.
Compiles hashes containing kwsplats inside .