Skip to content

Commit

Permalink
Merge pull request #572 from sveltejs/compound-if-block-outros
Browse files Browse the repository at this point in the history
fix destruction of compound if blocks with outros
  • Loading branch information
Rich-Harris authored May 6, 2017
2 parents 35d820f + e8c07e8 commit a43115c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/generators/dom/visitors/IfBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ export default function visitIfBlock ( generator, block, state, node ) {
} else if ( node.next ) {
node.next.usedAsAnchor = true;
}

block.builders.destroy.addLine(
`${if_name}${name}.destroy( ${state.parentNode ? 'false' : 'detach'} );`
);
}

function simple ( generator, block, state, node, branch, dynamic, { name, anchor, params } ) {
function simple ( generator, block, state, node, branch, dynamic, { name, anchor, params, if_name } ) {
block.builders.create.addBlock( deindent`
var ${name} = (${branch.condition}) && ${branch.block}( ${params}, ${block.component} );
` );
Expand Down Expand Up @@ -151,6 +147,10 @@ function simple ( generator, block, state, node, branch, dynamic, { name, anchor
${exit}
}
` );

block.builders.destroy.addLine(
`${if_name}${name}.destroy( ${state.parentNode ? 'false' : 'detach'} );`
);
}

function compound ( generator, block, state, node, branches, dynamic, { name, anchor, params, hasElse, if_name } ) {
Expand Down Expand Up @@ -201,6 +201,10 @@ function compound ( generator, block, state, node, branches, dynamic, { name, an
}
` );
}

block.builders.destroy.addLine(
`${if_name}${name}.destroy( ${state.parentNode ? 'false' : 'detach'} );`
);
}

// if any of the siblings have outros, we need to keep references to the blocks
Expand Down Expand Up @@ -304,4 +308,8 @@ function compoundWithOutros ( generator, block, state, node, branches, dynamic,
}
` );
}

block.builders.destroy.addLine(
`${if_current_block_index}${if_blocks}[ ${current_block_index} ].destroy( ${state.parentNode ? 'false' : 'detach'} );`
);
}

0 comments on commit a43115c

Please sign in to comment.