works correct

pull/2880/head
cudr 5 years ago
parent 2f80667f20
commit ac287ed9f4

@ -164,7 +164,7 @@ export default class Block {
if (parent_node) {
this.builders.mount.add_line(`@append(${parent_node}, ${name});`);
if (parent_node === 'document.head') this.builders.destroy.add_line(`@detach(${name});`);
if (parent_node === 'document.head' && !no_detach) this.builders.destroy.add_line(`@detach(${name});`);
} else {
this.builders.mount.add_line(`@insert(#target, ${name}, anchor);`);
if (!no_detach) this.builders.destroy.add_conditional('detaching', `@detach(${name});`);

@ -21,9 +21,18 @@ export default class RawMustacheTagWrapper extends Tag {
render(block: Block, parent_node: string, parent_nodes: string) {
const name = this.var;
const in_head = parent_node === 'document.head';
const needs_anchors = !parent_node || in_head;
// if in head always needs anchors
if (in_head) {
this.prev = null;
this.next = null;
}
// TODO use is_dom_node instead of type === 'Element'?
const needs_anchor_before = this.prev ? this.prev.node.type !== 'Element' : !parent_node;
const needs_anchor_after = this.next ? this.next.node.type !== 'Element' : !parent_node;
const needs_anchor_before = this.prev ? this.prev.node.type !== 'Element' : needs_anchors;
const needs_anchor_after = this.next ? this.next.node.type !== 'Element' : needs_anchors;
const anchor_before = needs_anchor_before
? block.get_unique_name(`${name}_before`)
@ -89,7 +98,7 @@ export default class RawMustacheTagWrapper extends Tag {
block.builders.mount.add_line(insert(init));
if (!parent_node) {
if (needs_anchors) {
block.builders.destroy.add_conditional('detaching', needs_anchor_before
? `${detach}\n@detach(${anchor_before});`
: detach);
@ -100,4 +109,4 @@ export default class RawMustacheTagWrapper extends Tag {
add_anchor_after();
}
}
}
}

Loading…
Cancel
Save