class Sanitize

def transform_node!(node, node_allowlist)

def transform_node!(node, node_allowlist)
  @transformers.each do |transformer|
    # Since transform_node! may be called in a tight loop to process thousands
    # of items, we can optimize both memory and CPU performance by:
    #
    # 1. Reusing the same config hash for each transformer
    # 2. Directly assigning values to hash instead of using merge!. Not only
    # does merge! create a new hash, it is also 2.6x slower:
    # https://github.com/JuanitoFatas/fast-ruby#hashmerge-vs-hashmerge-code
    config = @transformer_config
    config[:is_allowlisted] = config[:is_whitelisted] = node_allowlist.include?(node)
    config[:node] = node
    config[:node_name] = node.name.downcase
    config[:node_allowlist] = config[:node_whitelist] = node_allowlist
    result = transformer.call(**config)
    if result.is_a?(Hash)
      result_allowlist = result[:node_allowlist] || result[:node_whitelist]
      if result_allowlist.respond_to?(:each)
        node_allowlist.merge(result_allowlist)
      end
    end
  end
  node
end