File tree 2 files changed +19
-3
lines changed
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -1980,6 +1980,17 @@ foo
1980
1980
expect ( ast . children [ 2 ] . type ) . toBe ( NodeTypes . INTERPOLATION )
1981
1981
} )
1982
1982
1983
+ it ( 'should NOT remove whitespaces w/ newline between interpolation and comment' , ( ) => {
1984
+ const ast = parse ( `<!-- foo --> \n {{msg}}` )
1985
+ expect ( ast . children . length ) . toBe ( 3 )
1986
+ expect ( ast . children [ 0 ] . type ) . toBe ( NodeTypes . COMMENT )
1987
+ expect ( ast . children [ 1 ] ) . toMatchObject ( {
1988
+ type : NodeTypes . TEXT ,
1989
+ content : ' '
1990
+ } )
1991
+ expect ( ast . children [ 2 ] . type ) . toBe ( NodeTypes . INTERPOLATION )
1992
+ } )
1993
+
1983
1994
it ( 'should NOT remove whitespaces w/o newline between elements' , ( ) => {
1984
1995
const ast = parse ( `<div/> <div/> <div/>` )
1985
1996
expect ( ast . children . length ) . toBe ( 5 )
Original file line number Diff line number Diff line change @@ -264,14 +264,19 @@ function parseChildren(
264
264
const next = nodes [ i + 1 ]
265
265
// Remove if:
266
266
// - the whitespace is the first or last node, or:
267
- // - (condense mode) the whitespace is adjacent to a comment, or:
267
+ // - (condense mode) the whitespace is between twos comments, or:
268
+ // - (condense mode) the whitespace is between comment and element, or:
268
269
// - (condense mode) the whitespace is between two elements AND contains newline
269
270
if (
270
271
! prev ||
271
272
! next ||
272
273
( shouldCondense &&
273
- ( prev . type === NodeTypes . COMMENT ||
274
- next . type === NodeTypes . COMMENT ||
274
+ ( ( prev . type === NodeTypes . COMMENT &&
275
+ next . type === NodeTypes . COMMENT ) ||
276
+ ( prev . type === NodeTypes . COMMENT &&
277
+ next . type === NodeTypes . ELEMENT ) ||
278
+ ( prev . type === NodeTypes . ELEMENT &&
279
+ next . type === NodeTypes . COMMENT ) ||
275
280
( prev . type === NodeTypes . ELEMENT &&
276
281
next . type === NodeTypes . ELEMENT &&
277
282
/ [ \r \n ] / . test ( node . content ) ) ) )
You can’t perform that action at this time.
0 commit comments