Skip to content

Commit

Permalink
works correct
Browse files Browse the repository at this point in the history
  • Loading branch information
cudr committed May 25, 2019
1 parent 2f80667 commit ac287ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/compile/render-dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});`);
Expand Down
17 changes: 13 additions & 4 deletions src/compile/render-dom/wrappers/RawMustacheTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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);
Expand All @@ -100,4 +109,4 @@ export default class RawMustacheTagWrapper extends Tag {
add_anchor_after();
}
}
}
}

0 comments on commit ac287ed

Please sign in to comment.