Fix failing tests

Set `claim_order` in claim_html_tag
pull/6449/head
Altan Birler 5 years ago
parent 34f9ffe2d8
commit d8aceba369

@ -313,11 +313,15 @@ export function children(element: Element) {
return Array.from(element.childNodes); return Array.from(element.childNodes);
} }
function claim_node<R extends ChildNodeEx>(nodes: ChildNodeArray, predicate: (node: ChildNodeEx) => node is R, processNode: (node: ChildNodeEx) => void, createNode: () => R, dontUpdateLastIndex: boolean = false) { function init_claim_info(nodes: ChildNodeArray) {
// Try to find nodes in an order such that we lengthen the longest increasing subsequence
if (nodes.claim_info === undefined) { if (nodes.claim_info === undefined) {
nodes.claim_info = {last_index: 0, total_claimed: 0}; nodes.claim_info = {last_index: 0, total_claimed: 0};
} }
}
function claim_node<R extends ChildNodeEx>(nodes: ChildNodeArray, predicate: (node: ChildNodeEx) => node is R, processNode: (node: ChildNodeEx) => void, createNode: () => R, dontUpdateLastIndex: boolean = false) {
// Try to find nodes in an order such that we lengthen the longest increasing subsequence
init_claim_info(nodes);
const resultNode = (() => { const resultNode = (() => {
// We first try to find an element after the previous one // We first try to find an element after the previous one
@ -415,10 +419,17 @@ export function claim_html_tag(nodes) {
if (start_index === end_index) { if (start_index === end_index) {
return new HtmlTag(); return new HtmlTag();
} }
init_claim_info(nodes);
const html_tag_nodes = nodes.splice(start_index, end_index + 1); const html_tag_nodes = nodes.splice(start_index, end_index + 1);
detach(html_tag_nodes[0]); detach(html_tag_nodes[0]);
detach(html_tag_nodes[html_tag_nodes.length - 1]); detach(html_tag_nodes[html_tag_nodes.length - 1]);
return new HtmlTag(html_tag_nodes.slice(1, html_tag_nodes.length - 1)); const claimed_nodes = html_tag_nodes.slice(1, html_tag_nodes.length - 1);
for (const n of claimed_nodes) {
n.claim_order = nodes.claim_info.total_claimed;
nodes.claim_info.total_claimed += 1;
}
return new HtmlTag(claimed_nodes);
} }
export function set_data(text, data) { export function set_data(text, data) {
@ -544,7 +555,7 @@ export function custom_event<T=any>(type: string, detail?: T, bubbles: boolean =
} }
export function query_selector_all(selector: string, parent: HTMLElement = document.body) { export function query_selector_all(selector: string, parent: HTMLElement = document.body) {
return Array.from(parent.querySelectorAll(selector)); return Array.from(parent.querySelectorAll(selector)) as ChildNodeArray;
} }
export class HtmlTag { export class HtmlTag {

@ -1,4 +1,4 @@
<title>Some Title</title>
<link href="/" rel="canonical"> <link href="/" rel="canonical">
<meta content="some description" name="description"> <meta content="some description" name="description">
<meta content="some keywords" name="keywords"> <meta content="some keywords" name="keywords">
<title>Some Title</title>

@ -35,7 +35,7 @@ function create_fragment(ctx) {
this.h(); this.h();
}, },
h() { h() {
if (img.src !== (img_src_value = "donuts.jpg")) attr(img, "src", img_src_value); if (img.src !== new URL(img_src_value = "donuts.jpg", location).href) attr(img, "src", img_src_value);
attr(img, "alt", "donuts"); attr(img, "alt", "donuts");
}, },
m(target, anchor) { m(target, anchor) {

@ -35,9 +35,9 @@ function create_fragment(ctx) {
}, },
h() { h() {
attr(img0, "alt", "potato"); attr(img0, "alt", "potato");
if (img0.src !== (img0_src_value = /*url*/ ctx[0])) attr(img0, "src", img0_src_value); if (img0.src !== new URL(img0_src_value = /*url*/ ctx[0], location).href) attr(img0, "src", img0_src_value);
attr(img1, "alt", "potato"); attr(img1, "alt", "potato");
if (img1.src !== (img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"))) attr(img1, "src", img1_src_value); if (img1.src !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) attr(img1, "src", img1_src_value);
}, },
m(target, anchor) { m(target, anchor) {
insert(target, img0, anchor); insert(target, img0, anchor);
@ -45,11 +45,11 @@ function create_fragment(ctx) {
insert(target, img1, anchor); insert(target, img1, anchor);
}, },
p(ctx, [dirty]) { p(ctx, [dirty]) {
if (dirty & /*url*/ 1 && img0.src !== (img0_src_value = /*url*/ ctx[0])) { if (dirty & /*url*/ 1 && img0.src !== new URL(img0_src_value = /*url*/ ctx[0], location).href) {
attr(img0, "src", img0_src_value); attr(img0, "src", img0_src_value);
} }
if (dirty & /*slug*/ 2 && img1.src !== (img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"))) { if (dirty & /*slug*/ 2 && img1.src !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) {
attr(img1, "src", img1_src_value); attr(img1, "src", img1_src_value);
} }
}, },

Loading…
Cancel
Save