From b9b72a9f4526b75f72b042d8a28b861554ca1eed Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Wed, 18 Sep 2019 21:51:19 -0400 Subject: [PATCH] fixes --- .../compile/render_dom/wrappers/IfBlock.ts | 24 +++++++++++++------ .../compile/render_dom/wrappers/Title.ts | 6 ++--- test/runtime/samples/head-if-block/_config.js | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/IfBlock.ts b/src/compiler/compile/render_dom/wrappers/IfBlock.ts index 85623896f1..34f679bce9 100644 --- a/src/compiler/compile/render_dom/wrappers/IfBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/IfBlock.ts @@ -191,7 +191,7 @@ export default class IfBlockWrapper extends Wrapper { 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) { 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.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 @@ -362,7 +366,7 @@ export default class IfBlockWrapper extends Wrapper { ${this.branches.map(({ dependencies, condition, snippet }, i) => condition ? b` ${snippet && b`if ((${condition} == null) || ${changed(dependencies)}) ${condition} = !!(${snippet})`} - if (${condition}) return ${String(i)};` + if (${condition}) return ${i};` : b`return ${i};`)} ${!has_else && b`return -1;`} } @@ -545,11 +549,17 @@ export default class IfBlockWrapper extends Wrapper { `); } } else if (dynamic) { - block.chunks.update.push( - b`if (${branch.condition}) ${name}.p(#changed, #ctx);` - ); + block.chunks.update.push(b` + 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}); + } + `); } } diff --git a/src/compiler/compile/render_dom/wrappers/Title.ts b/src/compiler/compile/render_dom/wrappers/Title.ts index 148d66dfda..2a02f1bc08 100644 --- a/src/compiler/compile/render_dom/wrappers/Title.ts +++ b/src/compiler/compile/render_dom/wrappers/Title.ts @@ -3,7 +3,7 @@ import Wrapper from './shared/Wrapper'; import Renderer from '../Renderer'; import Block from '../Block'; 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 Text from '../../nodes/Text'; import { Identifier } from 'estree'; @@ -93,8 +93,8 @@ export default class TitleWrapper extends Wrapper { } } else { 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};`); } diff --git a/test/runtime/samples/head-if-block/_config.js b/test/runtime/samples/head-if-block/_config.js index 439ed2cb1b..cb8b6eccb9 100644 --- a/test/runtime/samples/head-if-block/_config.js +++ b/test/runtime/samples/head-if-block/_config.js @@ -3,7 +3,7 @@ export default { condition: false }, - test({ assert, component, target, window }) { + test({ assert, component, window }) { assert.equal(window.document.title, ''); component.condition = true;