@@ -96,8 +96,8 @@ export interface ParserContext {
96
96
offset : number
97
97
line : number
98
98
column : number
99
- inPre : boolean // HTML <pre> tag, preserve whitespaces
100
- inVPre : boolean // v-pre, do not process directives and interpolations
99
+ inPre : number // HTML <pre> tag, preserve whitespaces
100
+ inVPre : number // v-pre, do not process directives and interpolations
101
101
onWarn : NonNullable < ErrorHandlingOptions [ 'onWarn' ] >
102
102
}
103
103
@@ -134,8 +134,8 @@ function createParserContext(
134
134
offset : 0 ,
135
135
originalSource : content ,
136
136
source : content ,
137
- inPre : false ,
138
- inVPre : false ,
137
+ inPre : 0 ,
138
+ inVPre : 0 ,
139
139
onWarn : options . onWarn
140
140
}
141
141
}
@@ -254,7 +254,7 @@ function parseChildren(
254
254
// Whitespace handling strategy like v2
255
255
let removedWhitespace = false
256
256
if ( mode !== TextModes . RAWTEXT && mode !== TextModes . RCDATA ) {
257
- const preserve = context . options . whitespace = == 'preserve'
257
+ const shouldCondense = context . options . whitespace ! == 'preserve'
258
258
for ( let i = 0 ; i < nodes . length ; i ++ ) {
259
259
const node = nodes [ i ]
260
260
if ( ! context . inPre && node . type === NodeTypes . TEXT ) {
@@ -268,7 +268,7 @@ function parseChildren(
268
268
if (
269
269
! prev ||
270
270
! next ||
271
- ( ! preserve &&
271
+ ( shouldCondense &&
272
272
( prev . type === NodeTypes . COMMENT ||
273
273
next . type === NodeTypes . COMMENT ||
274
274
( prev . type === NodeTypes . ELEMENT &&
@@ -281,7 +281,7 @@ function parseChildren(
281
281
// Otherwise, the whitespace is condensed into a single space
282
282
node . content = ' '
283
283
}
284
- } else if ( ! preserve ) {
284
+ } else if ( shouldCondense ) {
285
285
// in condense mode, consecutive whitespaces in text are condensed
286
286
// down to a single space.
287
287
node . content = node . content . replace ( / [ \t \r \n \f ] + / g, ' ' )
@@ -428,7 +428,7 @@ function parseElement(
428
428
if ( element . isSelfClosing || context . options . isVoidTag ( element . tag ) ) {
429
429
// #4030 self-closing <pre> tag
430
430
if ( context . options . isPreTag ( element . tag ) ) {
431
- context . inPre = false
431
+ context . inPre --
432
432
}
433
433
return element
434
434
}
@@ -479,10 +479,10 @@ function parseElement(
479
479
element . loc = getSelection ( context , element . loc . start )
480
480
481
481
if ( isPreBoundary ) {
482
- context . inPre = false
482
+ context . inPre --
483
483
}
484
484
if ( isVPreBoundary ) {
485
- context . inVPre = false
485
+ context . inVPre --
486
486
}
487
487
return element
488
488
}
@@ -534,9 +534,8 @@ function parseTag(
534
534
const currentSource = context . source
535
535
536
536
// check <pre> tag
537
- const isPreTag = context . options . isPreTag ( tag )
538
- if ( isPreTag ) {
539
- context . inPre = true
537
+ if ( context . options . isPreTag ( tag ) ) {
538
+ context . inPre ++
540
539
}
541
540
542
541
// Attributes.
@@ -548,7 +547,7 @@ function parseTag(
548
547
! context . inVPre &&
549
548
props . some ( p => p . type === NodeTypes . DIRECTIVE && p . name === 'pre' )
550
549
) {
551
- context . inVPre = true
550
+ context . inVPre ++
552
551
// reset context
553
552
extend ( context , cursor )
554
553
context . source = currentSource
0 commit comments