Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
let root
let currentParent
let inVPre = false
let inPre = false
let inPre = 0
let warned = false

function warnOnce(msg, range) {
Expand Down Expand Up @@ -173,7 +173,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
inVPre = false
}
if (platformIsPreTag(element.tag)) {
inPre = false
inPre = Math.max(inPre - 1, 0)
}
// apply post-transforms
for (let i = 0; i < postTransforms.length; i++) {
Expand Down Expand Up @@ -287,7 +287,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
}
}
if (platformIsPreTag(element.tag)) {
inPre = true
inPre += 1
}
if (inVPre) {
processRawAttrs(element)
Expand Down
12 changes: 12 additions & 0 deletions test/unit/modules/compiler/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,18 @@ describe('parser', () => {
expect(pre2.children[0].text).toBe('\nabc')
})

it(`preserve whitespace after nested <pre> tags with whitespace: 'condense'`, () => {
const options = extend({}, condenseOptions)
const ast = parse(
'<pre>1\n\n2\n\n<pre>aaa\nbbb\nc\n</pre>\n3\n</pre>',
options
)
expect(ast.tag).toBe('pre')
expect(ast.children[1].tag).toBe('pre')
expect(ast.children[2].type).toBe(3)
expect(ast.children[2].text).toBe('\n3\n')
})

it(`keep first newline after unary tag in <pre> with whitespace: 'condense'`, () => {
const options = extend({}, condenseOptions)
const ast = parse('<pre>abc<input>\ndef</pre>', options)
Expand Down