Skip to content

Commit 15efef9

Browse files
committed
separate hasOutros from hasOutroMethod - fixes #1492
1 parent 9e52cf9 commit 15efef9

File tree

11 files changed

+63
-23
lines changed

11 files changed

+63
-23
lines changed

src/compile/dom/Block.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ export default class Block {
4444

4545
maintainContext: boolean;
4646
hasAnimation: boolean;
47-
hasIntroMethod: boolean;
47+
hasIntros: boolean;
48+
hasOutros: boolean;
49+
hasIntroMethod: boolean; // could have the method without the transition, due to siblings
4850
hasOutroMethod: boolean;
4951
outros: number;
5052

@@ -127,11 +129,11 @@ export default class Block {
127129
}
128130

129131
addIntro() {
130-
this.hasIntroMethod = this.compiler.target.hasIntroTransitions = true;
132+
this.hasIntros = this.hasIntroMethod = this.compiler.target.hasIntroTransitions = true;
131133
}
132134

133135
addOutro() {
134-
this.hasOutroMethod = this.compiler.target.hasOutroTransitions = true;
136+
this.hasOutros = this.hasOutroMethod = this.compiler.target.hasOutroTransitions = true;
135137
this.outros += 1;
136138
}
137139

src/compile/nodes/Attribute.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export default class Attribute extends Node {
232232
if (this.dependencies.size || isSelectValueAttribute) {
233233
const dependencies = Array.from(this.dependencies);
234234
const changedCheck = (
235-
( block.hasOutroMethod ? `#outroing || ` : '' ) +
235+
( block.hasOutros ? `#outroing || ` : '' ) +
236236
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
237237
);
238238

@@ -308,7 +308,7 @@ export default class Attribute extends Node {
308308
if (propDependencies.size) {
309309
const dependencies = Array.from(propDependencies);
310310
const condition = (
311-
(block.hasOutroMethod ? `#outroing || ` : '') +
311+
(block.hasOutros ? `#outroing || ` : '') +
312312
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
313313
);
314314

src/compile/nodes/AwaitBlock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export default class AwaitBlock extends Node {
6161
block.addDependencies(child.block.dependencies);
6262
}
6363

64-
if (child.block.hasIntroMethod) hasIntros = true;
65-
if (child.block.hasOutroMethod) hasOutros = true;
64+
if (child.block.hasIntros) hasIntros = true;
65+
if (child.block.hasOutros) hasOutros = true;
6666
});
6767

6868
this.pending.block.hasUpdateMethod = isDynamic;

src/compile/nodes/EachBlock.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default class EachBlock extends Node {
119119
this.else.block.hasUpdateMethod = this.else.block.dependencies.size > 0;
120120
}
121121

122-
if (this.block.hasOutroMethod || (this.else && this.else.block.hasOutroMethod)) {
122+
if (this.block.hasOutros || (this.else && this.else.block.hasOutros)) {
123123
block.addOutro();
124124
}
125125
}
@@ -317,14 +317,14 @@ export default class EachBlock extends Node {
317317
const rects = block.getUniqueName('rects');
318318
const destroy = this.block.hasAnimation
319319
? `@fixAndOutroAndDestroyBlock`
320-
: this.block.hasOutroMethod
320+
: this.block.hasOutros
321321
? `@outroAndDestroyBlock`
322322
: `@destroyBlock`;
323323

324324
block.builders.update.addBlock(deindent`
325325
const ${this.each_block_value} = ${snippet};
326326
327-
${this.block.hasOutroMethod && `@transitionManager.groupOutros();`}
327+
${this.block.hasOutros && `@transitionManager.groupOutros();`}
328328
${this.block.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].r();`}
329329
${blocks} = @updateKeyedEach(${blocks}, #component, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, "${mountOrIntro}", ${anchor}, ${this.get_each_context});
330330
${this.block.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].a();`}
@@ -393,7 +393,7 @@ export default class EachBlock extends Node {
393393
allDependencies.add(dependency);
394394
});
395395

396-
const outro = this.block.hasOutroMethod && block.getUniqueName('outro')
396+
const outro = this.block.hasOutros && block.getUniqueName('outro')
397397
if (outro) {
398398
block.builders.init.addBlock(deindent`
399399
function ${outro}(i, detach, fn) {
@@ -415,7 +415,7 @@ export default class EachBlock extends Node {
415415

416416
if (condition !== '') {
417417
const forLoopBody = this.block.hasUpdateMethod
418-
? (this.block.hasIntroMethod || this.block.hasOutroMethod)
418+
? (this.block.hasIntros || this.block.hasOutros)
419419
? deindent`
420420
if (${iterations}[#i]) {
421421
${iterations}[#i].p(changed, child_ctx);
@@ -444,7 +444,7 @@ export default class EachBlock extends Node {
444444

445445
let destroy;
446446

447-
if (this.block.hasOutroMethod) {
447+
if (this.block.hasOutros) {
448448
destroy = deindent`
449449
@transitionManager.groupOutros();
450450
for (; #i < ${iterations}.length; #i += 1) ${outro}(#i, 1);

src/compile/nodes/IfBlock.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ export default class IfBlock extends Node {
6868
block.addDependencies(node.block.dependencies);
6969
}
7070

71-
if (node.block.hasIntroMethod) hasIntros = true;
72-
if (node.block.hasOutroMethod) hasOutros = true;
71+
if (node.block.hasIntros) hasIntros = true;
72+
if (node.block.hasOutros) hasOutros = true;
7373

7474
if (isElseIf(node.else)) {
7575
attachBlocks(node.else.children[0]);
@@ -302,8 +302,8 @@ export default class IfBlock extends Node {
302302
const destroyOldBlock = deindent`
303303
@transitionManager.groupOutros();
304304
${name}.o(function() {
305-
${if_blocks}[ ${previous_block_index} ].d(1);
306-
${if_blocks}[ ${previous_block_index} ] = null;
305+
${if_blocks}[${previous_block_index}].d(1);
306+
${if_blocks}[${previous_block_index}] = null;
307307
});
308308
`;
309309

@@ -355,9 +355,7 @@ export default class IfBlock extends Node {
355355
}
356356

357357
block.builders.destroy.addLine(deindent`
358-
${if_current_block_type_index}{
359-
${if_blocks}[${current_block_type_index}].d(${parentNode ? '' : 'detach'});
360-
}
358+
${if_current_block_type_index}${if_blocks}[${current_block_type_index}].d(${parentNode ? '' : 'detach'});
361359
`);
362360
}
363361

src/compile/nodes/Title.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class Title extends Node {
8181
if (allDependencies.size) {
8282
const dependencies = Array.from(allDependencies);
8383
const changedCheck = (
84-
( block.hasOutroMethod ? `#outroing || ` : '' ) +
84+
( block.hasOutros ? `#outroing || ` : '' ) +
8585
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
8686
);
8787

src/compile/nodes/shared/Tag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class Tag extends Node {
3535

3636
if (dependencies.size) {
3737
const changedCheck = (
38-
(block.hasOutroMethod ? `#outroing || ` : '') +
38+
(block.hasOutros ? `#outroing || ` : '') +
3939
[...dependencies].map((dependency: string) => `changed.${dependency}`).join(' || ')
4040
);
4141

src/parse/read/directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const DIRECTIVES: Record<string, {
7777
attribute(start, end, type, name, expression) {
7878
return { start, end, type, name, expression };
7979
},
80-
allowedExpressionTypes: [ 'Identifier', 'MemberExpression', 'ObjectExpression', 'Literal', 'CallExpression' ],
80+
allowedExpressionTypes: ['Identifier', 'MemberExpression', 'ObjectExpression', 'Literal', 'CallExpression'],
8181
error: 'Data passed to actions must be an identifier (e.g. `foo`), a member expression ' +
8282
'(e.g. `foo.bar` or `foo[baz]`), a method call (e.g. `foo()`), or a literal (e.g. `true` or `\'a string\'`'
8383
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default {
2+
data: {
3+
x: 1,
4+
y: false,
5+
},
6+
7+
html: `
8+
<span>1</span>
9+
`,
10+
11+
nestedTransitions: true,
12+
13+
test(assert, component, target) {
14+
component.set({ x: 2 });
15+
assert.htmlEqual(target.innerHTML, `
16+
<span>2</span>
17+
`);
18+
},
19+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{#if y}
2+
<Foo/>
3+
{:else}
4+
<span>{x}</span>
5+
{/if}
6+
7+
<script>
8+
export default {
9+
components: {
10+
Foo: './Foo.html'
11+
},
12+
13+
data() {
14+
return {
15+
x: 'x',
16+
y: false
17+
};
18+
}
19+
};
20+
</script>

0 commit comments

Comments
 (0)