File tree 2 files changed +7
-3
lines changed
test/unit/modules/compiler
2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ export function parse (
197
197
// remove trailing whitespace
198
198
const element = stack [ stack . length - 1 ]
199
199
const lastNode = element . children [ element . children . length - 1 ]
200
- if ( lastNode && lastNode . type === 3 && lastNode . text === ' ' ) {
200
+ if ( lastNode && lastNode . type === 3 && lastNode . text === ' ' && ! inPre ) {
201
201
element . children . pop ( )
202
202
}
203
203
// pop stack
@@ -242,7 +242,7 @@ export function parse (
242
242
expression,
243
243
text
244
244
} )
245
- } else if ( text !== ' ' || children [ children . length - 1 ] . text !== ' ' ) {
245
+ } else if ( text !== ' ' || ! children . length || children [ children . length - 1 ] . text !== ' ' ) {
246
246
currentParent . children . push ( {
247
247
type : 3 ,
248
248
text
Original file line number Diff line number Diff line change @@ -481,12 +481,16 @@ describe('parser', () => {
481
481
482
482
it ( 'preserve whitespace in <pre> tag' , function ( ) {
483
483
const options = extend ( { } , baseOptions )
484
- const ast = parse ( '<pre><code> \n<span>hi</span>\n </code></pre>' , options )
484
+ const ast = parse ( '<pre><code> \n<span>hi</span>\n </code><span> </span>< /pre>' , options )
485
485
const code = ast . children [ 0 ]
486
486
expect ( code . children [ 0 ] . type ) . toBe ( 3 )
487
487
expect ( code . children [ 0 ] . text ) . toBe ( ' \n' )
488
488
expect ( code . children [ 2 ] . type ) . toBe ( 3 )
489
489
expect ( code . children [ 2 ] . text ) . toBe ( '\n ' )
490
+
491
+ const span = ast . children [ 1 ]
492
+ expect ( span . children [ 0 ] . type ) . toBe ( 3 )
493
+ expect ( span . children [ 0 ] . text ) . toBe ( ' ' )
490
494
} )
491
495
492
496
it ( 'forgivingly handle < in plain text' , ( ) => {
You can’t perform that action at this time.
0 commit comments