pull/3539/head
Richard Harris 6 years ago
parent 41becdc5fb
commit b9b72a9f45

@ -191,7 +191,7 @@ export default class IfBlockWrapper extends Wrapper {
const vars = { name, anchor, if_exists_condition, has_else, has_transitions }; const vars = { name, anchor, if_exists_condition, has_else, has_transitions };
const detaching = is_head(parent_node) ? '' : 'detaching'; const detaching = is_head(parent_node) ? null : 'detaching';
if (this.node.else) { if (this.node.else) {
this.branches.forEach(branch => { this.branches.forEach(branch => {
@ -322,7 +322,11 @@ export default class IfBlockWrapper extends Wrapper {
block.chunks.update.push(b`${name}.p(#changed, #ctx);`); block.chunks.update.push(b`${name}.p(#changed, #ctx);`);
} }
block.chunks.destroy.push(b`if (${if_exists_condition}) ${name}.d(${detaching});`); block.chunks.destroy.push(b`
if (${if_exists_condition}) {
${name}.d(${detaching});
}
`);
} }
// if any of the siblings have outros, we need to keep references to the blocks // if any of the siblings have outros, we need to keep references to the blocks
@ -362,7 +366,7 @@ export default class IfBlockWrapper extends Wrapper {
${this.branches.map(({ dependencies, condition, snippet }, i) => condition ${this.branches.map(({ dependencies, condition, snippet }, i) => condition
? b` ? b`
${snippet && b`if ((${condition} == null) || ${changed(dependencies)}) ${condition} = !!(${snippet})`} ${snippet && b`if ((${condition} == null) || ${changed(dependencies)}) ${condition} = !!(${snippet})`}
if (${condition}) return ${String(i)};` if (${condition}) return ${i};`
: b`return ${i};`)} : b`return ${i};`)}
${!has_else && b`return -1;`} ${!has_else && b`return -1;`}
} }
@ -545,11 +549,17 @@ export default class IfBlockWrapper extends Wrapper {
`); `);
} }
} else if (dynamic) { } else if (dynamic) {
block.chunks.update.push( block.chunks.update.push(b`
b`if (${branch.condition}) ${name}.p(#changed, #ctx);` if (${branch.condition}) {
); ${name}.p(#changed, #ctx);
}
`);
} }
block.chunks.destroy.push(b`if (${if_exists_condition}) ${name}.d(${detaching});`); block.chunks.destroy.push(b`
if (${if_exists_condition}) {
${name}.d(${detaching});
}
`);
} }
} }

@ -3,7 +3,7 @@ import Wrapper from './shared/Wrapper';
import Renderer from '../Renderer'; import Renderer from '../Renderer';
import Block from '../Block'; import Block from '../Block';
import Title from '../../nodes/Title'; import Title from '../../nodes/Title';
import { stringify, string_literal } from '../../utils/stringify'; import { string_literal } from '../../utils/stringify';
import add_to_set from '../../utils/add_to_set'; import add_to_set from '../../utils/add_to_set';
import Text from '../../nodes/Text'; import Text from '../../nodes/Text';
import { Identifier } from 'estree'; import { Identifier } from 'estree';
@ -93,8 +93,8 @@ export default class TitleWrapper extends Wrapper {
} }
} else { } else {
const value = this.node.children.length > 0 const value = this.node.children.length > 0
? stringify((this.node.children[0] as Text).data) ? string_literal((this.node.children[0] as Text).data)
: '""'; : x`""`;
block.chunks.hydrate.push(b`@_document.title = ${value};`); block.chunks.hydrate.push(b`@_document.title = ${value};`);
} }

@ -3,7 +3,7 @@ export default {
condition: false condition: false
}, },
test({ assert, component, target, window }) { test({ assert, component, window }) {
assert.equal(window.document.title, ''); assert.equal(window.document.title, '');
component.condition = true; component.condition = true;

Loading…
Cancel
Save