Skip to content

Commit a91e1ef

Browse files
committed
fix: fix TypeError in table diffs
1 parent 1372785 commit a91e1ef

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.7.1
2+
3+
- Fix a TypeError in table diff, which occured when THEAD or TFOOT was added or removed, and a column was removed.
4+
15
# 0.7.0
26

37
- Add `diffText` option.

demo/main.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ table {
1313
border-collapse: collapse;
1414
}
1515

16+
th,
1617
td {
1718
border: calc(1rem / 16) solid black;
1819
padding: 0.25rem;

src/diff.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,28 @@ test.each<[string, Node, Node, string, Options | undefined]>([
884884
'<table><tbody><tr><th>first column</th><th class="vdd-removed">second column</th><th>last column</th></tr><tr class="vdd-removed"><td>1111</td><td>2222</td><td>3333</td></tr><tr><td>4444</td><td class="vdd-removed">5555</td><td>6666</td></tr></tbody></table>',
885885
undefined,
886886
],
887+
[
888+
'table - remove column and add THEAD',
889+
htmlToFragment(
890+
'<table><tbody><tr><th>first column</th><th>second column</th><th>last column</th></tr></tbody></table>',
891+
),
892+
htmlToFragment(
893+
'<table><thead><tr><th>1111</th><th>3333</th></tr></thead><tbody><tr><th>first column</th><th>last column</th></tr></tbody></table>',
894+
),
895+
'<table><thead class="vdd-added"><tr><th>1111</th><td class="vdd-removed"></td><th>3333</th></tr></thead><tbody><tr><th>first column</th><th class="vdd-removed">second column</th><th>last column</th></tr></tbody></table>',
896+
undefined,
897+
],
898+
[
899+
'table - remove column and THEAD',
900+
htmlToFragment(
901+
'<table><thead><tr><th>1111</th><th>2222</th><th>3333</th></tr></thead><tbody><tr><th>first column</th><th>second column</th><th>last column</th></tr></tbody></table>',
902+
),
903+
htmlToFragment(
904+
'<table><tbody><tr><th>first column</th><th>last column</th></tr></tbody></table>',
905+
),
906+
'<table><thead class="vdd-removed"><tr><th>1111</th><th>2222</th><th>3333</th></tr></thead><tbody><tr><th>first column</th><th class="vdd-removed">second column</th><th>last column</th></tr></tbody></table>',
907+
undefined,
908+
],
887909
])(
888910
'%s',
889911
(

src/diff.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ export function visualDomDiff(
466466
for (const row of new DomIterator(outputTable, trIteratorOptions)) {
467467
const cells = row.childNodes
468468

469-
if (addedNodes.has(row)) {
469+
if (addedNodes.has(row) || addedNodes.has(row.parentNode!)) {
470470
if (cells.length < columnCount) {
471471
for (let i = 0; i < columnCount; ++i) {
472472
if (columns[i] === -1) {
@@ -476,7 +476,10 @@ export function visualDomDiff(
476476
}
477477
}
478478
}
479-
} else if (removedNodes.has(row)) {
479+
} else if (
480+
removedNodes.has(row) ||
481+
removedNodes.has(row.parentNode!)
482+
) {
480483
if (cells.length < columnCount) {
481484
for (let i = 0; i < columnCount; ++i) {
482485
if (columns[i] === 1) {

0 commit comments

Comments
 (0)