From 2e68fe0043c43fab4c143e961827c1c127f2d3fe Mon Sep 17 00:00:00 2001 From: "Sebastian L. K. Sorensen" Date: Mon, 20 May 2024 22:27:49 +0200 Subject: [PATCH] fix root tagName change --- CHANGELOG.md | 6 ++++++ src/walker.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00eff494..db17609a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.0.31] - 2024-05-20 + +### Fixed + +- Fix when root node becomes a new tag ([#38](https://github.com/tentjs/tent/issues/38)) + ## [0.0.29] & [0.0.30] - 2024-05-16 - A mistake was made in the versioning, so these are re-releases of `0.0.28`. The changelog is kept for transparency. diff --git a/src/walker.ts b/src/walker.ts index 5b6aaa31..a68a739a 100644 --- a/src/walker.ts +++ b/src/walker.ts @@ -2,6 +2,12 @@ import { addAttribute } from './attributes'; import { type Attrs, type TentNode } from './types'; function walker(oldNode: TentNode, newNode: TentNode) { + if (oldNode.tagName !== newNode.tagName) { + oldNode.replaceWith(newNode); + + return; + } + const nc = Array.from(newNode.childNodes, (n) => n as TentNode); const oc = Array.from(oldNode.childNodes, (n) => n as TentNode);