File tree 3 files changed +35
-1
lines changed
src/compiler/compile/render-dom/wrappers
test/runtime/samples/fragment-trailing-whitespace
3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,13 @@ function link(next: Wrapper, prev: Wrapper) {
42
42
if ( next ) next . prev = prev ;
43
43
}
44
44
45
+ function trimmable_at ( child : INode , next_sibling : Wrapper ) : boolean {
46
+ // Whitespace is trimmable if one of the following is true:
47
+ // The child and its sibling share a common nearest each block (not at an each block boundary)
48
+ // The next sibling's previous node is an each block
49
+ return ( next_sibling . node . find_nearest ( / E a c h B l o c k / ) === child . find_nearest ( / E a c h B l o c k / ) ) || next_sibling . node . prev . type === 'EachBlock' ;
50
+ }
51
+
45
52
export default class FragmentWrapper {
46
53
nodes : Wrapper [ ] ;
47
54
@@ -85,7 +92,7 @@ export default class FragmentWrapper {
85
92
if ( this . nodes . length === 0 ) {
86
93
const should_trim = (
87
94
// @ts -ignore todo: probably error, should it be next_sibling.node.data?
88
- next_sibling ? ( next_sibling . node . type === 'Text' && / ^ \s / . test ( next_sibling . data ) ) : ! child . has_ancestor ( 'EachBlock' )
95
+ next_sibling ? ( next_sibling . node . type === 'Text' && / ^ \s / . test ( next_sibling . data ) && trimmable_at ( child , next_sibling ) ) : ! child . has_ancestor ( 'EachBlock' )
89
96
) ;
90
97
91
98
if ( should_trim ) {
Original file line number Diff line number Diff line change
1
+ const message = "the quick brown fox jumps over the lazy dog" ;
2
+ const expected = [ ...message ] . map ( c => `<span>${ c + " " } </span>` ) . join ( "" ) ;
3
+
4
+ export default {
5
+ props : {
6
+ message
7
+ } ,
8
+
9
+ async test ( { assert, target } ) {
10
+ const firstSpanList = target . children [ 0 ] ;
11
+ assert . equal ( firstSpanList . innerHTML , expected ) ;
12
+
13
+ const secondSpanList = target . children [ 1 ] ;
14
+ assert . equal ( secondSpanList . innerHTML , expected ) ;
15
+ }
16
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ let message = " the quick brown fox jumps over the lazy dog"
3
+ </script >
4
+
5
+ <div id =" first" >
6
+ {#each message as char }
7
+ <span >{char } </span >
8
+ {/each }
9
+ </div >
10
+
11
+ <div id ="second" >{#each message as char }<span >{char } </span >{/each }</div >
You can’t perform that action at this time.
0 commit comments