diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index 7855a52f89..bafbd5d397 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -421,10 +421,8 @@ function preprocessChildren( const preprocessor = preprocessors[child.type]; if (preprocessor) preprocessor(generator, block, state, child, inEachBlock, elementStack, componentStack, stripWhitespace, cleaned[i + 1] || nextSibling); - if (lastChild) { - lastChild.next = child; - lastChild.needsAnchor = !child._state || !child._state.name; - } + if (lastChild) lastChild.next = child; + child.prev = lastChild; lastChild = child; }); @@ -446,10 +444,6 @@ function preprocessChildren( } } - if (lastChild) { - lastChild.needsAnchor = !state.parentNode; - } - node.children = cleaned; } diff --git a/src/generators/dom/visitors/EachBlock.ts b/src/generators/dom/visitors/EachBlock.ts index 406ed6e2a3..bf838e5a25 100644 --- a/src/generators/dom/visitors/EachBlock.ts +++ b/src/generators/dom/visitors/EachBlock.ts @@ -18,7 +18,9 @@ export default function visitEachBlock( const each_block_value = node._block.listName; const iterations = block.getUniqueName(`${each_block}_iterations`); const params = block.params.join(', '); - const anchor = node.needsAnchor + + const needsAnchor = node.next ? (!node.next._state || !node.next._state.name) : !state.parentNode; + const anchor = needsAnchor ? block.getUniqueName(`${each_block}_anchor`) : (node.next && node.next._state.name) || 'null'; @@ -53,7 +55,7 @@ export default function visitEachBlock( const isToplevel = !state.parentNode; - if (node.needsAnchor) { + if (needsAnchor) { block.addElement( anchor, `@createComment()`, diff --git a/src/generators/dom/visitors/IfBlock.ts b/src/generators/dom/visitors/IfBlock.ts index e858668932..d91da53d02 100644 --- a/src/generators/dom/visitors/IfBlock.ts +++ b/src/generators/dom/visitors/IfBlock.ts @@ -78,7 +78,9 @@ export default function visitIfBlock( componentStack: Node[] ) { const name = generator.getUniqueName(`if_block`); - const anchor = node.needsAnchor + + const needsAnchor = node.next ? (!node.next._state || !node.next._state.name) : !state.parentNode; + const anchor = needsAnchor ? block.getUniqueName(`${name}_anchor`) : (node.next && node.next._state.name) || 'null'; const params = block.params.join(', '); @@ -117,7 +119,7 @@ export default function visitIfBlock( `${if_name}${name}.claim( ${state.parentNodes} );` ); - if (node.needsAnchor) { + if (needsAnchor) { block.addElement( anchor, `@createComment()`,