···2323 else
2424 from.replaceWith(to.cloneNode(true));
2525 }
2626- else {
2727- throw new Error(`Cannot morph nodes of different types: from is ${from.constructor.name}, to is ${to.constructor.name}`);
2828- }
2626+ else
2727+ throw new Error(`Cannot morph from ${from.constructor.name}, to ${to.constructor.name}`);
2928}
3029function morphAttributes(from, to) {
3130 for (const { name } of from.attributes)
+5-5
src/morphlite.ts
···2222 if (from.attributes.length > 0 || to.attributes.length > 0) morphAttributes(from, to);
2323 if (from.childNodes.length > 0 || to.childNodes.length > 0) morphChildNodes(from, to, idMap);
2424 } else from.replaceWith(to.cloneNode(true));
2525- } else {
2626- throw new Error(
2727- `Cannot morph nodes of different types: from is ${from.constructor.name}, to is ${to.constructor.name}`,
2828- );
2929- }
2525+ } else throw new Error(`Cannot morph from ${from.constructor.name}, to ${to.constructor.name}`);
3026}
31273228function morphAttributes(from: Element, to: Element): void {
···9793function numberOfItemsInCommon<T>(a: Set<T>, b: Set<T>): number {
9894 return [...a].filter((item) => b.has(item)).length;
9995}
9696+9797+// We cannot use `instanceof` when nodes might be from different documents,
9898+// so we use type guards instead. This keeps TypeScript happy, while doing
9999+// the necessary checks at runtime.
100100101101function isElement(node: Node): node is Element {
102102 return node.nodeType === 1;