From 0fbcda12aa5bb6558de665efcf1d7e71ea2c8e16 Mon Sep 17 00:00:00 2001 From: Bryan Terce Date: Thu, 20 Jun 2019 02:44:17 -0700 Subject: [PATCH] Better function name? --- src/compiler/compile/render-dom/wrappers/Fragment.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/compiler/compile/render-dom/wrappers/Fragment.ts b/src/compiler/compile/render-dom/wrappers/Fragment.ts index fac77470a6..bd20c9107f 100644 --- a/src/compiler/compile/render-dom/wrappers/Fragment.ts +++ b/src/compiler/compile/render-dom/wrappers/Fragment.ts @@ -42,8 +42,11 @@ function link(next: Wrapper, prev: Wrapper) { if (next) next.prev = prev; } -function at_each_boundary(child: INode, next_sibling: Wrapper): boolean { - return next_sibling.node.find_nearest(/EachBlock/) === child.find_nearest(/EachBlock/) || next_sibling.node.prev.type === 'EachBlock'; +function trimmable_at(child: INode, next_sibling: Wrapper): boolean { + // Whitespace is trimmable if one of the following is true: + // The child and its sibling share a common nearest each block (not at an each block boundary) + // The next sibling's previous node is an each block + return (next_sibling.node.find_nearest(/EachBlock/) === child.find_nearest(/EachBlock/)) || next_sibling.node.prev.type === 'EachBlock'; } export default class FragmentWrapper { @@ -89,7 +92,7 @@ export default class FragmentWrapper { if (this.nodes.length === 0) { const should_trim = ( // @ts-ignore todo: probably error, should it be next_sibling.node.data? - next_sibling ? (next_sibling.node.type === 'Text' && /^\s/.test(next_sibling.data) && at_each_boundary(child, next_sibling)) : !child.has_ancestor('EachBlock') + next_sibling ? (next_sibling.node.type === 'Text' && /^\s/.test(next_sibling.data) && trimmable_at(child, next_sibling)) : !child.has_ancestor('EachBlock') ); if (should_trim) {