If we are not escaping, replace the parentNode with a documentFragment created as with `func`'s return value.
960570
function (span, parentNode) {
                    // updates the elements with the new content
                    update = function (newVal) {
                        // is this still part of the DOM?
                        var attached = nodes[0].parentNode;
                        // update the nodes in the DOM with the new rendered value
                        if (attached) {
                            makeAndPut(newVal);
                        }
                        teardownCheck(nodes[0].parentNode);
                    };

                    // make sure we have a valid parentNode
                    parentNode = getParentNode(span, parentNode);
                    // A helper function to manage inserting the contents
                    // and removing the old contents
                    var nodes, makeAndPut = function (val) {
                        // create the fragment, but don't hook it up
                        // we need to insert it into the document first
                        var frag = can.view.frag(val, parentNode),
                            // keep a reference to each node
                            newNodes = can.makeArray(frag.childNodes),
                            last = nodes ? nodes[nodes.length - 1] : span;

                        // Insert it in the `document` or `documentFragment`
                        if (last.nextSibling) {
                            last.parentNode.insertBefore(frag, last.nextSibling);
                        } else {
                            last.parentNode.appendChild(frag);
                        }
                        // nodes hasn't been set yet
                        if (!nodes) {
                            can.remove(can.$(span));
                            nodes = newNodes;
                            // set the teardown nodeList
                            nodeList = nodes;
                            can.view.registerNode(nodes);
                        } else {
                            // Update node Array's to point to new nodes
                            // and then remove the old nodes.
                            // It has to be in this order for Mootools
                            // and IE because somehow, after an element
                            // is removed from the DOM, it loses its
                            // expando values.
                            var nodesToRemove = can.makeArray(nodes);
                            can.view.replace(nodes, newNodes);
                            can.remove(can.$(nodesToRemove));
                        }
                    };
                    // nodes are the nodes that any updates will replace
                    // at this point, these nodes could be part of a documentFragment
                    makeAndPut(binding.value, [span]);

                    setupTeardownOnDestroy(parentNode);
                    //children have to be properly nested HTML for buildFragment to work properly
                }
1051872
function(markup) {

        if (!markup) return undefined;

        var fragment = markup.fragment;
        if (!(markup.fragment instanceof DocumentFragment) || !markup.fragment.hasChildNodes()) throw new Error('dia.LinkView: invalid label markup.');

        var vNode;
        var childNodes = fragment.childNodes;

        if ((childNodes.length > 1) || childNodes[0].nodeName.toUpperCase() !== 'G') {
            // default markup fragment is not wrapped in <g />
            // add a <g /> container
            vNode = V('g').append(fragment);
        } else {
            vNode = V(childNodes[0]);
        }

        vNode.addClass('label');

        return { node: vNode.node, selectors: markup.selectors };
    }
713379
function customFragment (token, tokens) {
  let escaping = false
  let fragment = ''
  token = tokens.shift() // remove opened {
  while (true) {
    if (!token) {
      throw new Error('A custom fragment requires "}" to terminate')
    }
    if (escaping) {
      if (includes('{}', token)) {
        fragment += token
      } else {
        fragment += `\\${token}`
      }
      escaping = false
    } else if (token === '\\') {
      escaping = true
    } else if (token === '}') {
      break
    } else {
      fragment += token
    }
    token = tokens.shift()
  }
  return { _type: customFragment.name, fragment }
}
135739
function appendSpy(child) {
        // ignore appending to the node that's not yet added to DOM tree
        if (!this.parentNode) {
            return;
        }

        var destNodePath = phantomas.getDOMPath(this),
            appendedNodePath = phantomas.getDOMPath(child);

        // skip undefined nodes (issue #560)
        if (destNodePath === false) {
            return;
        }

        // don't count elements added to fragments as a DOM inserts (issue #350)
        // DocumentFragment > div[0]
        if (destNodePath.indexOf('DocumentFragment') === 0) {
            return;
        }

        phantomas.incrMetric('DOMinserts');
        phantomas.addOffender('DOMinserts', {append: appendedNodePath, node: destNodePath});

        phantomas.log('DOM insert: node "%s" appended to "%s"', appendedNodePath, destNodePath);
    }
239671
def newDocFragment(self):
        
        ret = libxml2mod.xmlNewDocFragment(self._o)
        if ret is None:raise treeError('xmlNewDocFragment() failed')
        __tmp = xmlNode(_obj=ret)
        return __tmp
465419
function replaceExt(fpath, newExt) {
  const oldExt = path.extname(fpath);
  return _nativeExt.includes(oldExt) ? fpath :
    path.join(path.dirname(fpath), path.basename(fpath, oldExt) + newExt);
}
210521
private void inlineConstReturn(Node parent, Node call, Node returnedValue) {
    Node retValue = returnedValue.cloneTree();
    parent.replaceChild(call, retValue);
    compiler.reportChangeToEnclosingScope(retValue);
  }
1023187
protected Element replaceOrAddElementText(Document doc, Element parent, String name, String content, List<String> beforeNames) {
        Element element = replaceOrAddElement(doc, parent, name, beforeNames);
        element.setTextContent(content);
        return element;
    }
1198404
function wrapChildrenInDefaultBlock(
    opts: Options,
    change: Change,
    node: Node
): Change {
    change.wrapBlockByKey(node.nodes.first().key, opts.typeDefault, {
        normalize: false
    });

    const wrapper = change.value.document.getDescendant(node.key).nodes.first();

    // Add in the remaining items
    node.nodes.rest().forEach((child, index) =>
        change.moveNodeByKey(child.key, wrapper.key, index + 1, {
            normalize: false
        })
    );

    return change;
}
1266812
def transform(self, node, results):
        
        """
        params = results.get(u"params")
        ret = results.get(u"ret")
        if ret is not None:
            assert ret.prev_sibling.type == token.RARROW, u"Invalid return annotation"
            self.warn_once(node, reason=warning_text)
            ret.prev_sibling.remove()
            ret.remove()
        if params is None: return
        if params.type == syms.typedargslist:
            # more than one param in a typedargslist
            for param in params.children:
                if param.type == syms.tname:
                    self.warn_once(node, reason=warning_text)
                    param.replace(param_without_annotations(param))
        elif params.type == syms.tname:
            # one param
            self.warn_once(node, reason=warning_text)
            params.replace(param_without_annotations(params))
1130732
function() {
      var clonedTestElement = testElement.cloneNode(false),
          returnValue,
          innerHTML;

      clonedTestElement.innerHTML = "<p><div></div>";
      innerHTML                   = clonedTestElement.innerHTML.toLowerCase();
      returnValue                 = innerHTML === "<p></p><div></div>" || innerHTML === "<p><div></div></p>";

      // Cache result by overwriting current function
      this.autoClosesUnclosedTags = function() { return returnValue; };

      return returnValue;
    }
1235435
function replaceSuperMethodCall(node, state, path, options) {
  // like super.foo()
  console.assert(node.type === "CallExpression");
  console.assert(node.callee.object.type === "Super");

  return funcCall(
            member(
              funcCall(
                member(options.functionNode, "_get"),
                replaceSuper(node.callee.object, state, path.concat(["callee", "object"]), options),
                literal(node.callee.property.value || node.callee.property.name),
                id("this")),
                "call"),
            id("this"), ...node.arguments);
}
632583
function (result) {
            var frag = can.buildFragment(result, document.body);
            // If we have an empty frag...
            if (!frag.childNodes.length) {
                frag.appendChild(document.createTextNode(''));
            }
            return frag;
        }
452275
function getFragmentRect ({ _fragmentStart, _fragmentEnd }) {
  let top, bottom, left, right
  util().mapNodeRange(_fragmentStart, _fragmentEnd, function (node) {
    let rect
    if (node.nodeType === 1 || node.getBoundingClientRect) {
      rect = node.getBoundingClientRect()
    } else if (node.nodeType === 3 && node.data.trim()) {
      rect = getTextRect(node)
    }
    if (rect) {
      if (!top || rect.top < top) {
        top = rect.top
      }
      if (!bottom || rect.bottom > bottom) {
        bottom = rect.bottom
      }
      if (!left || rect.left < left) {
        left = rect.left
      }
      if (!right || rect.right > right) {
        right = rect.right
      }
    }
  })
  return {
    top,
    left,
    width: right - left,
    height: bottom - top
  }
}
121516
function replace(node, parent, scope, remaps) {
  var remap = remaps[node.name];
  if (!remap) return;

  var ownBinding = scope.getBindingIdentifier(node.name);
  if (ownBinding === remap.binding) {
    node.name = remap.uid;
  } else {
    // scope already has it's own binding that doesn't
    // match the one we have a stored replacement for
    if (this) this.skip();
  }
}
238287
function (e) {
        if (e && e.prevValue === e.newValue) {
            return;
        }

        var par   = this.current ? this.current.parentNode : null,
            after = this.link;

        if (par) {
            switch (this.paginator.getTotalPages()) {
                case Paginator.VALUE_UNLIMITED :
                        after = this.na; break;
                case this.paginator.getCurrentPage() :
                        after = this.span; break;
            }

            if (this.current !== after) {
                par.replaceChild(after,this.current);
                this.current = after;
            }
        }
    }
928526
@Override
  public void endVisit(ParenthesizedExpression node) {
    if (getReplaceableValue(node.getExpression()) != null) {
      node.replaceWith(node.getExpression().copy());
    }
  }