Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function parse (
// remove trailing whitespace
const element = stack[stack.length - 1]
const lastNode = element.children[element.children.length - 1]
if (lastNode && lastNode.type === 3 && lastNode.text === ' ') {
if (lastNode && lastNode.type === 3 && lastNode.text === ' ' && !inPre) {
element.children.pop()
}
// pop stack
Expand Down Expand Up @@ -242,7 +242,7 @@ export function parse (
expression,
text
})
} else if (text !== ' ' || children[children.length - 1].text !== ' ') {
} else if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') {
currentParent.children.push({
type: 3,
text
Expand Down
6 changes: 5 additions & 1 deletion test/unit/modules/compiler/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,16 @@ describe('parser', () => {

it('preserve whitespace in <pre> tag', function () {
const options = extend({}, baseOptions)
const ast = parse('<pre><code> \n<span>hi</span>\n </code></pre>', options)
const ast = parse('<pre><code> \n<span>hi</span>\n </code><span> </span></pre>', options)
const code = ast.children[0]
expect(code.children[0].type).toBe(3)
expect(code.children[0].text).toBe(' \n')
expect(code.children[2].type).toBe(3)
expect(code.children[2].text).toBe('\n ')

const span = ast.children[1]
expect(span.children[0].type).toBe(3)
expect(span.children[0].text).toBe(' ')
})

it('forgivingly handle < in plain text', () => {
Expand Down