determine needsAnchor lazily

pull/803/head
Rich Harris 7 years ago
parent 5c88b6c864
commit 457f0189d4

@ -421,10 +421,8 @@ function preprocessChildren(
const preprocessor = preprocessors[child.type]; const preprocessor = preprocessors[child.type];
if (preprocessor) preprocessor(generator, block, state, child, inEachBlock, elementStack, componentStack, stripWhitespace, cleaned[i + 1] || nextSibling); if (preprocessor) preprocessor(generator, block, state, child, inEachBlock, elementStack, componentStack, stripWhitespace, cleaned[i + 1] || nextSibling);
if (lastChild) { if (lastChild) lastChild.next = child;
lastChild.next = child; child.prev = lastChild;
lastChild.needsAnchor = !child._state || !child._state.name;
}
lastChild = child; lastChild = child;
}); });
@ -446,10 +444,6 @@ function preprocessChildren(
} }
} }
if (lastChild) {
lastChild.needsAnchor = !state.parentNode;
}
node.children = cleaned; node.children = cleaned;
} }

@ -18,7 +18,9 @@ export default function visitEachBlock(
const each_block_value = node._block.listName; const each_block_value = node._block.listName;
const iterations = block.getUniqueName(`${each_block}_iterations`); const iterations = block.getUniqueName(`${each_block}_iterations`);
const params = block.params.join(', '); 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`) ? block.getUniqueName(`${each_block}_anchor`)
: (node.next && node.next._state.name) || 'null'; : (node.next && node.next._state.name) || 'null';
@ -53,7 +55,7 @@ export default function visitEachBlock(
const isToplevel = !state.parentNode; const isToplevel = !state.parentNode;
if (node.needsAnchor) { if (needsAnchor) {
block.addElement( block.addElement(
anchor, anchor,
`@createComment()`, `@createComment()`,

@ -78,7 +78,9 @@ export default function visitIfBlock(
componentStack: Node[] componentStack: Node[]
) { ) {
const name = generator.getUniqueName(`if_block`); 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`) ? block.getUniqueName(`${name}_anchor`)
: (node.next && node.next._state.name) || 'null'; : (node.next && node.next._state.name) || 'null';
const params = block.params.join(', '); const params = block.params.join(', ');
@ -117,7 +119,7 @@ export default function visitIfBlock(
`${if_name}${name}.claim( ${state.parentNodes} );` `${if_name}${name}.claim( ${state.parentNodes} );`
); );
if (node.needsAnchor) { if (needsAnchor) {
block.addElement( block.addElement(
anchor, anchor,
`@createComment()`, `@createComment()`,

Loading…
Cancel
Save