File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
test/unit/modules/compiler Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -229,19 +229,20 @@ export function parse (
229
229
currentParent . attrsMap . placeholder === text ) {
230
230
return
231
231
}
232
+ const children = currentParent . children
232
233
text = inPre || text . trim ( )
233
234
? decodeHTMLCached ( text )
234
235
// only preserve whitespace if its not right after a starting tag
235
- : preserveWhitespace && currentParent . children . length ? ' ' : ''
236
+ : preserveWhitespace && children . length ? ' ' : ''
236
237
if ( text ) {
237
238
let expression
238
239
if ( ! inVPre && text !== ' ' && ( expression = parseText ( text , delimiters ) ) ) {
239
- currentParent . children . push ( {
240
+ children . push ( {
240
241
type : 2 ,
241
242
expression,
242
243
text
243
244
} )
244
- } else {
245
+ } else if ( text !== ' ' || children [ children . length - 1 ] . text !== ' ' ) {
245
246
currentParent . children . push ( {
246
247
type : 3 ,
247
248
text
Original file line number Diff line number Diff line change @@ -82,6 +82,14 @@ describe('parser', () => {
82
82
expect ( 'Component template should contain exactly one root element:\n\n<div></div><div></div>' ) . toHaveBeenWarned ( )
83
83
} )
84
84
85
+ it ( 'remove duplicate whitespace text nodes caused by comments' , ( ) => {
86
+ const ast = parse ( `<div><a></a> <!----> <a></a></div>` , baseOptions )
87
+ expect ( ast . children . length ) . toBe ( 3 )
88
+ expect ( ast . children [ 0 ] . tag ) . toBe ( 'a' )
89
+ expect ( ast . children [ 1 ] . text ) . toBe ( ' ' )
90
+ expect ( ast . children [ 2 ] . tag ) . toBe ( 'a' )
91
+ } )
92
+
85
93
it ( 'remove text nodes between v-if conditions' , ( ) => {
86
94
const ast = parse ( `<div><div v-if="1"></div> <div v-else-if="2"></div> <div v-else></div> <span></span></div>` , baseOptions )
87
95
expect ( ast . children . length ) . toBe ( 3 )
You can’t perform that action at this time.
0 commit comments