0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

determine needsAnchor lazily

This commit is contained in:
Rich Harris 2017-08-29 22:10:29 -04:00
parent 5c88b6c864
commit 457f0189d4
3 changed files with 10 additions and 12 deletions

View File

@ -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;
}

View File

@ -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()`,

View File

@ -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()`,