@@ -80,7 +80,7 @@ export default function visitIfBlock(
80
80
) {
81
81
const name = node . var ;
82
82
83
- const needsAnchor = node . next ? ! isDomNode ( node . next ) : ! state . parentNode ;
83
+ const needsAnchor = node . next ? ! isDomNode ( node . next , generator ) : ! state . parentNode || ! isDomNode ( node . parent , generator ) ;
84
84
const anchor = needsAnchor
85
85
? block . getUniqueName ( `${ name } _anchor` )
86
86
: ( node . next && node . next . var ) || 'null' ;
@@ -94,7 +94,7 @@ export default function visitIfBlock(
94
94
const dynamic = branches [ 0 ] . hasUpdateMethod ; // can use [0] as proxy for all, since they necessarily have the same value
95
95
const hasOutros = branches [ 0 ] . hasOutroMethod ;
96
96
97
- const vars = { name, anchor, params, if_name, hasElse } ;
97
+ const vars = { name, needsAnchor , anchor, params, if_name, hasElse } ;
98
98
99
99
if ( node . else ) {
100
100
if ( hasOutros ) {
@@ -137,7 +137,7 @@ function simple(
137
137
node : Node ,
138
138
branch ,
139
139
dynamic ,
140
- { name, anchor, params, if_name }
140
+ { name, needsAnchor , anchor, params, if_name }
141
141
) {
142
142
block . builders . init . addBlock ( deindent `
143
143
var ${ name } = (${ branch . condition } ) && ${ branch . block } (${ params } , #component);
@@ -152,7 +152,7 @@ function simple(
152
152
`if (${ name } ) ${ name } .${ mountOrIntro } (${ targetNode } , ${ anchorNode } );`
153
153
) ;
154
154
155
- const parentNode = state . parentNode || `${ anchor } .parentNode` ;
155
+ const parentNode = ( state . parentNode && ! needsAnchor ) ? state . parentNode : `${ anchor } .parentNode` ;
156
156
157
157
const enter = dynamic
158
158
? branch . hasIntroMethod
@@ -227,7 +227,7 @@ function compound(
227
227
node : Node ,
228
228
branches ,
229
229
dynamic ,
230
- { name, anchor, params, hasElse, if_name }
230
+ { name, needsAnchor , anchor, params, hasElse, if_name }
231
231
) {
232
232
const select_block_type = generator . getUniqueName ( `select_block_type` ) ;
233
233
const current_block_type = block . getUniqueName ( `current_block_type` ) ;
@@ -255,7 +255,7 @@ function compound(
255
255
`${ if_name } ${ name } .${ mountOrIntro } (${ targetNode } , ${ anchorNode } );`
256
256
) ;
257
257
258
- const parentNode = state . parentNode || `${ anchor } .parentNode` ;
258
+ const parentNode = ( state . parentNode && ! needsAnchor ) ? state . parentNode : `${ anchor } .parentNode` ;
259
259
260
260
const changeBlock = deindent `
261
261
${ hasElse
@@ -303,7 +303,7 @@ function compoundWithOutros(
303
303
node : Node ,
304
304
branches ,
305
305
dynamic ,
306
- { name, anchor, params, hasElse }
306
+ { name, needsAnchor , anchor, params, hasElse }
307
307
) {
308
308
const select_block_type = block . getUniqueName ( `select_block_type` ) ;
309
309
const current_block_type_index = block . getUniqueName ( `current_block_type_index` ) ;
@@ -354,7 +354,7 @@ function compoundWithOutros(
354
354
`${ if_current_block_type_index } ${ if_blocks } [${ current_block_type_index } ].${ mountOrIntro } (${ targetNode } , ${ anchorNode } );`
355
355
) ;
356
356
357
- const parentNode = state . parentNode || `${ anchor } .parentNode` ;
357
+ const parentNode = ( state . parentNode && ! needsAnchor ) ? state . parentNode : `${ anchor } .parentNode` ;
358
358
359
359
const destroyOldBlock = deindent `
360
360
${ name } .outro(function() {
0 commit comments