Skip to content

Commit 6f82551

Browse files
committed
Fix failing tests
Set `claim_order` in claim_html_tag
1 parent d5e2a90 commit 6f82551

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/runtime/internal/dom.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,15 @@ export function children(element: Element) {
306306
return Array.from(element.childNodes);
307307
}
308308

309-
function claim_node<R extends ChildNodeEx>(nodes: ChildNodeArray, predicate: (node: ChildNodeEx) => node is R, processNode: (node: ChildNodeEx) => void, createNode: () => R, dontUpdateLastIndex: boolean = false) {
310-
// Try to find nodes in an order such that we lengthen the longest increasing subsequence
309+
function init_claim_info(nodes: ChildNodeArray) {
311310
if (nodes.claim_info === undefined) {
312311
nodes.claim_info = {last_index: 0, total_claimed: 0};
313312
}
313+
}
314+
315+
function claim_node<R extends ChildNodeEx>(nodes: ChildNodeArray, predicate: (node: ChildNodeEx) => node is R, processNode: (node: ChildNodeEx) => void, createNode: () => R, dontUpdateLastIndex: boolean = false) {
316+
// Try to find nodes in an order such that we lengthen the longest increasing subsequence
317+
init_claim_info(nodes);
314318

315319
const resultNode = (() => {
316320
// We first try to find an element after the previous one
@@ -408,10 +412,17 @@ export function claim_html_tag(nodes) {
408412
if (start_index === end_index) {
409413
return new HtmlTag();
410414
}
415+
416+
init_claim_info(nodes);
411417
const html_tag_nodes = nodes.splice(start_index, end_index + 1);
412418
detach(html_tag_nodes[0]);
413419
detach(html_tag_nodes[html_tag_nodes.length - 1]);
414-
return new HtmlTag(html_tag_nodes.slice(1, html_tag_nodes.length - 1));
420+
const claimed_nodes = html_tag_nodes.slice(1, html_tag_nodes.length - 1);
421+
for (const n of claimed_nodes) {
422+
n.claim_order = nodes.claim_info.total_claimed;
423+
nodes.claim_info.total_claimed += 1;
424+
}
425+
return new HtmlTag(claimed_nodes);
415426
}
416427

417428
export function set_data(text, data) {
@@ -537,7 +548,7 @@ export function custom_event<T=any>(type: string, detail?: T) {
537548
}
538549

539550
export function query_selector_all(selector: string, parent: HTMLElement = document.body) {
540-
return Array.from(parent.querySelectorAll(selector));
551+
return Array.from(parent.querySelectorAll(selector)) as ChildNodeArray;
541552
}
542553

543554
export class HtmlTag {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
<title>Some Title</title>
12
<link href="/" rel="canonical">
23
<meta content="some description" name="description">
34
<meta content="some keywords" name="keywords">
4-
<title>Some Title</title>

test/js/samples/hydrated-void-element/expected.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function create_fragment(ctx) {
3535
this.h();
3636
},
3737
h() {
38-
if (img.src !== (img_src_value = "donuts.jpg")) attr(img, "src", img_src_value);
38+
if (img.src !== new URL(img_src_value = "donuts.jpg", location).href) attr(img, "src", img_src_value);
3939
attr(img, "alt", "donuts");
4040
},
4141
m(target, anchor) {
@@ -61,4 +61,4 @@ class Component extends SvelteComponent {
6161
}
6262
}
6363

64-
export default Component;
64+
export default Component;

test/js/samples/src-attribute-check/expected.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ function create_fragment(ctx) {
3535
},
3636
h() {
3737
attr(img0, "alt", "potato");
38-
if (img0.src !== (img0_src_value = /*url*/ ctx[0])) attr(img0, "src", img0_src_value);
38+
if (img0.src !== new URL(img0_src_value = /*url*/ ctx[0], location).href) attr(img0, "src", img0_src_value);
3939
attr(img1, "alt", "potato");
40-
if (img1.src !== (img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"))) attr(img1, "src", img1_src_value);
40+
if (img1.src !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) attr(img1, "src", img1_src_value);
4141
},
4242
m(target, anchor) {
4343
insert(target, img0, anchor);
4444
insert(target, t, anchor);
4545
insert(target, img1, anchor);
4646
},
4747
p(ctx, [dirty]) {
48-
if (dirty & /*url*/ 1 && img0.src !== (img0_src_value = /*url*/ ctx[0])) {
48+
if (dirty & /*url*/ 1 && img0.src !== new URL(img0_src_value = /*url*/ ctx[0], location).href) {
4949
attr(img0, "src", img0_src_value);
5050
}
5151

52-
if (dirty & /*slug*/ 2 && img1.src !== (img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"))) {
52+
if (dirty & /*slug*/ 2 && img1.src !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) {
5353
attr(img1, "src", img1_src_value);
5454
}
5555
},
@@ -82,4 +82,4 @@ class Component extends SvelteComponent {
8282
}
8383
}
8484

85-
export default Component;
85+
export default Component;

0 commit comments

Comments
 (0)