From 84b5345aee826907f468e96aa8eb51006138e69e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 20 Sep 2018 20:55:26 -0400 Subject: [PATCH] fix transitions and stuff --- src/compile/render-dom/wrappers/Element/index.ts | 12 +++++++++++- src/compile/render-dom/wrappers/Fragment.ts | 12 ++++++++++++ src/compile/render-dom/wrappers/IfBlock.ts | 2 +- src/compile/render-dom/wrappers/Text.ts | 6 ++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index a6d8acabee..f8c0e46704 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -158,6 +158,16 @@ export default class ElementWrapper extends Wrapper { throw new Error(`no binding was created`); } + if (node.intro || node.outro) { + if (node.intro) block.addIntro(); + if (node.outro) block.addOutro(); + this.cannotUseInnerHTML(); + } + + if (node.animation) { + block.addAnimation(); + } + this.fragment = new FragmentWrapper(renderer, block, node.children, this, stripWhitespace, nextSibling); } @@ -657,7 +667,7 @@ export default class ElementWrapper extends Wrapper { addTransitions( block: Block ) { - const { intro, outro } = this; + const { intro, outro } = this.node; if (!intro && !outro) return; diff --git a/src/compile/render-dom/wrappers/Fragment.ts b/src/compile/render-dom/wrappers/Fragment.ts index 03828b5541..71d4d00af9 100644 --- a/src/compile/render-dom/wrappers/Fragment.ts +++ b/src/compile/render-dom/wrappers/Fragment.ts @@ -106,6 +106,18 @@ export default class FragmentWrapper { } } + if (stripWhitespace) { + const first = this.nodes[0]; + + if (first && first.node.type === 'Text') { + first.data = trimStart(first.data); + if (!first.data) { + this.nodes.shift(); + link(null, this.nodes[0]); + } + } + } + if (windowWrapper) { this.nodes.unshift(windowWrapper); link(lastChild, windowWrapper); diff --git a/src/compile/render-dom/wrappers/IfBlock.ts b/src/compile/render-dom/wrappers/IfBlock.ts index 9e7afb2dfd..a994221cb5 100644 --- a/src/compile/render-dom/wrappers/IfBlock.ts +++ b/src/compile/render-dom/wrappers/IfBlock.ts @@ -161,7 +161,7 @@ export default class IfBlockWrapper extends Wrapper { if (this.node.else) { if (hasOutros) { - this.renderCompoundWithOutros(block, parentNode, parentNodes, branches, dynamic, vars); + this.renderCompoundWithOutros(block, parentNode, parentNodes, dynamic, vars); if (this.renderer.options.nestedTransitions) { block.builders.outro.addBlock(deindent` diff --git a/src/compile/render-dom/wrappers/Text.ts b/src/compile/render-dom/wrappers/Text.ts index 98b6d55671..8d07d351e3 100644 --- a/src/compile/render-dom/wrappers/Text.ts +++ b/src/compile/render-dom/wrappers/Text.ts @@ -32,6 +32,7 @@ function shouldSkip(node: Text) { export default class TextWrapper extends Wrapper { node: Text; + data: string; skip: boolean; var: string; @@ -44,6 +45,7 @@ export default class TextWrapper extends Wrapper { super(renderer, block, parent, node); this.skip = shouldSkip(this.node); + this.data = node.data; this.var = this.skip ? null : 'text'; } @@ -52,8 +54,8 @@ export default class TextWrapper extends Wrapper { block.addElement( this.var, - `@createText(${stringify(this.node.data)})`, - parentNodes && `@claimText(${parentNodes}, ${stringify(this.node.data)})`, + `@createText(${stringify(this.data)})`, + parentNodes && `@claimText(${parentNodes}, ${stringify(this.data)})`, parentNode ); }