filters out duplicates and extends all nodes
175454
function(nodes) {
      if (nodes.length == 0) return nodes;
      var results = [], n;
      for (var i = 0, l = nodes.length; i < l; i++)
        if (!(n = nodes[i])._counted) {
          n._counted = true;
          results.push(Element.extend(n));
        }
      return Selector.handlers.unmark(results);
    }
1314248
function (original, tag) {
      var nu = shallowAs(original, tag);

      Insert.before(original, nu);
      var children = Traverse.children(original);
      InsertAll.append(nu, children);
      Remove.remove(original);
      return nu;
    }
1049181
def extend_node_list(acc, new):
        """"""
        if new is None:
            new = []
        elif not isinstance(new, list):
            new = [new]
        return acc + new
1228567
function cloneWithRaws(node) {
      if (node.nodes) {
        const oldNodes = node.nodes;
        node.nodes = [];
        const clone = node.clone({ raws: node.raws });
        node.nodes = oldNodes;
        for (const clonedChild of oldNodes.map(cloneWithRaws)) {
          clone.append(clonedChild);
        }
        return clone;
      } else {
        return node.clone({ raws: node.raws });
      }
    }
1218516
def _extend_nodelist(extends_node, context, instance_types):
    
    results = []

    # Find all blocks in the complete inheritance chain
    blocks = extends_node.blocks.copy()  # dict with all blocks in the current template
    _extend_blocks(extends_node, blocks, context)

    # Dive into all blocks of the page one by one
    all_block_names = list(blocks.keys())
    for block in list(blocks.values()):
        results += _scan_nodes(block.nodelist, context, instance_types, block, ignore_blocks=all_block_names)

    # Scan topmost template for nodes that exist outside of blocks
    parent_template = _find_topmost_template(extends_node, context)
    if not parent_template:
        return []
    else:
        results += _scan_nodes(parent_template.nodelist, context, instance_types, ignore_blocks=all_block_names)
        return results
723130
function(rootNode, filters) {
            if(modules.utils.isString(filters)){
                filters = [filters];
            }
			var newRootNode = modules.domUtils.createNode('div'),
				items = this.findRootNodes(rootNode, true),
				i = 0,
				x = 0,
				y = 0;

            // add v1 names
            y = filters.length;
            while (y--) {
                if(this.getMapping(filters[y])){
                    var v1Name = this.getMapping(filters[y]).root;
                    filters.push(v1Name);
                }
            }

			if(items){
				i = items.length;
				while(x < i) {
					// append matching nodes into newRootNode
					y = filters.length;
					while (y--) {
						if(modules.domUtils.hasAttributeValue(items[x], 'class', filters[y])){
							var clone = modules.domUtils.clone(items[x]);
							modules.domUtils.appendChild(newRootNode, clone);
							break;
						}
					}
					x++;
				}
			}

			return newRootNode;
		}
118734
def overextends(parser, token):
    
    bits = token.split_contents()
    if len(bits) != 2:
        raise TemplateSyntaxError("'%s' takes one argument" % bits[0])
    parent_name = parser.compile_filter(bits[1])
    nodelist = parser.parse()
    if nodelist.get_nodes_by_type(ExtendsNode):
        raise TemplateSyntaxError("'%s' cannot appear more than once "
                                  "in the same template" % bits[0])
    return OverExtendsNode(nodelist, parent_name, None)
391403
function removeTypeDuplicates(nodes) {
  var generics = {};
  var bases = {};

  // store union type groups to circular references
  var typeGroups = [];

  var types = [];

  for (var i = 0; i < nodes.length; i++) {
    var node = nodes[i];
    if (!node) continue;

    // detect duplicates
    if (types.indexOf(node) >= 0) {
      continue;
    }

    // this type matches anything
    if (t.isAnyTypeAnnotation(node)) {
      return [node];
    }

    //
    if (t.isFlowBaseAnnotation(node)) {
      bases[node.type] = node;
      continue;
    }

    //
    if (t.isUnionTypeAnnotation(node)) {
      if (typeGroups.indexOf(node.types) < 0) {
        nodes = nodes.concat(node.types);
        typeGroups.push(node.types);
      }
      continue;
    }

    // find a matching generic type and merge and deduplicate the type parameters
    if (t.isGenericTypeAnnotation(node)) {
      var _name = node.id.name;

      if (generics[_name]) {
        var existing = generics[_name];
        if (existing.typeParameters) {
          if (node.typeParameters) {
            existing.typeParameters.params = removeTypeDuplicates(existing.typeParameters.params.concat(node.typeParameters.params));
          }
        } else {
          existing = node.typeParameters;
        }
      } else {
        generics[_name] = node;
      }

      continue;
    }

    types.push(node);
  }

  // add back in bases
  for (var type in bases) {
    types.push(bases[type]);
  }

  // add back in generics
  for (var _name2 in generics) {
    types.push(generics[_name2]);
  }

  return types;
}
1028082
def filter_nodes(n: Node, query: str) -> CompatNodeIterator:
    
    return CompatNodeIterator(filter(n, query)._nodeit, only_nodes=True)
1058147
def _create_extended_jinja_tags(self, nodes):
        """"""

        jinja_a = None
        jinja_b = None
        ext_node = None
        ext_nodes = []

        for node in nodes:

            if isinstance(node, EmptyLine):
                continue


            if node.has_children():
                node.children = self._create_extended_jinja_tags(node.children)

            if not isinstance(node, JinjaTag):
                jinja_a = None
                continue

            if jinja_a is None or (
                node.tag_name in self._extended_tags and jinja_a.tag_name not in self._extended_tags[node.tag_name]):
                jinja_a = node
                continue


            if node.tag_name in self._extended_tags and \
                jinja_a.tag_name in self._extended_tags[node.tag_name]:

                if ext_node is None:
                    ext_node = ExtendedJinjaTag()
                    ext_node.add(jinja_a)
                    ext_nodes.append(ext_node)
                ext_node.add(node)

            else:
                ext_node = None
                jinja_a = node

        #replace the nodes with the new extended node
        for node in ext_nodes:
            nodes.insert(nodes.index(node.children[0]), node)

            index = nodes.index(node.children[0])
            del nodes[index:index+len(node.children)]

        return nodes
419134
function clean(nodes) {
        mark(nodes, []);
        return prune(nodes);
        function mark(nodes, ancestors) {
          _.each(nodes, function(node) {
            if (node.publish) {
              node.good = true;
              _.each(ancestors, function(ancestor) {
                ancestor.good = true;
              });
            }
            mark(node.children || [], ancestors.concat([ node ]));
          });
        }
        function prune(nodes) {
          var newNodes = [];
          _.each(nodes, function(node) {
            node.children = prune(node.children || []);
            if (node.good) {
              newNodes.push(node);
            }
          });
          return newNodes;
        }
      }
68499
def duplicate(self):
        """"""
        other = Matcher(self.loc, self.check_var, self.checkdefs, self.names, self.var_index)
        other.insert_check(0, "not " + self.check_var)
        self.others.append(other)
        return other
203674
function extend(dest, source){
    for (var key in source)
      dest[key] = source[key];

    return dest;
  }
1314321
def filter(self, *args):
    """"""
    if not args:
      return self
    preds = []
    f = self.filters
    if f:
      preds.append(f)
    for arg in args:
      if not isinstance(arg, Node):
        raise TypeError('Cannot filter a non-Node argument; received %r' % arg)
      preds.append(arg)
    if not preds:
      pred = None
    elif len(preds) == 1:
      pred = preds[0]
    else:
      pred = ConjunctionNode(*preds)
    return self.__class__(kind=self.kind, ancestor=self.ancestor,
                          filters=pred, orders=self.orders,
                          app=self.app, namespace=self.namespace,
                          default_options=self.default_options,
                          projection=self.projection, group_by=self.group_by)
288563
function parseExtensions(collection, extensions) {
  extensions.forEach(extNode => {
    const ext = new AdExtension();
    const extNodeAttrs = extNode.attributes;
    const childNodes = extNode.childNodes;

    if (extNode.attributes) {
      for (const extNodeAttrKey in extNodeAttrs) {
        const extNodeAttr = extNodeAttrs[extNodeAttrKey];

        if (extNodeAttr.nodeName && extNodeAttr.nodeValue) {
          ext.attributes[extNodeAttr.nodeName] = extNodeAttr.nodeValue;
        }
      }
    }

    for (const childNodeKey in childNodes) {
      const childNode = childNodes[childNodeKey];
      const txt = parserUtils.parseNodeText(childNode);

      // ignore comments / empty value
      if (childNode.nodeName !== '#comment' && txt !== '') {
        const extChild = new AdExtensionChild();
        extChild.name = childNode.nodeName;
        extChild.value = txt;

        if (childNode.attributes) {
          const childNodeAttributes = childNode.attributes;

          for (const extChildNodeAttrKey in childNodeAttributes) {
            const extChildNodeAttr = childNodeAttributes[extChildNodeAttrKey];

            extChild.attributes[extChildNodeAttr.nodeName] =
              extChildNodeAttr.nodeValue;
          }
        }

        ext.children.push(extChild);
      }
    }

    collection.push(ext);
  });
}
411711
function getOveruse(duplicates, limit) {
    var duplicate;
    for (duplicate in duplicates) {
        if (duplicates[duplicate] < limit) {
            delete duplicates[duplicate]
        }
    }
    return keys(duplicates);
}
388342
function filterTree (obj, iterate, options, context) {
  var result = []
  if (obj && iterate) {
    context = context || this
    eachTree(obj, function (item, index, items, path, parent) {
      if (iterate.call(context, item, index, items, path, parent)) {
        result.push(item)
      }
    }, options)
  }
  return result
}