mirror of https://github.com/vuejs/core.git
fix(compiler-core): keep whitespaces between interpolation and comment (#6828)
fix #6352
This commit is contained in:
parent
28a4fc040e
commit
48876182db
|
@ -1980,6 +1980,17 @@ foo
|
||||||
expect(ast.children[2].type).toBe(NodeTypes.INTERPOLATION)
|
expect(ast.children[2].type).toBe(NodeTypes.INTERPOLATION)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should NOT remove whitespaces w/ newline between interpolation and comment', () => {
|
||||||
|
const ast = parse(`<!-- foo --> \n {{msg}}`)
|
||||||
|
expect(ast.children.length).toBe(3)
|
||||||
|
expect(ast.children[0].type).toBe(NodeTypes.COMMENT)
|
||||||
|
expect(ast.children[1]).toMatchObject({
|
||||||
|
type: NodeTypes.TEXT,
|
||||||
|
content: ' '
|
||||||
|
})
|
||||||
|
expect(ast.children[2].type).toBe(NodeTypes.INTERPOLATION)
|
||||||
|
})
|
||||||
|
|
||||||
it('should NOT remove whitespaces w/o newline between elements', () => {
|
it('should NOT remove whitespaces w/o newline between elements', () => {
|
||||||
const ast = parse(`<div/> <div/> <div/>`)
|
const ast = parse(`<div/> <div/> <div/>`)
|
||||||
expect(ast.children.length).toBe(5)
|
expect(ast.children.length).toBe(5)
|
||||||
|
|
|
@ -264,14 +264,19 @@ function parseChildren(
|
||||||
const next = nodes[i + 1]
|
const next = nodes[i + 1]
|
||||||
// Remove if:
|
// Remove if:
|
||||||
// - the whitespace is the first or last node, or:
|
// - the whitespace is the first or last node, or:
|
||||||
// - (condense mode) the whitespace is adjacent to a comment, or:
|
// - (condense mode) the whitespace is between twos comments, or:
|
||||||
|
// - (condense mode) the whitespace is between comment and element, or:
|
||||||
// - (condense mode) the whitespace is between two elements AND contains newline
|
// - (condense mode) the whitespace is between two elements AND contains newline
|
||||||
if (
|
if (
|
||||||
!prev ||
|
!prev ||
|
||||||
!next ||
|
!next ||
|
||||||
(shouldCondense &&
|
(shouldCondense &&
|
||||||
(prev.type === NodeTypes.COMMENT ||
|
((prev.type === NodeTypes.COMMENT &&
|
||||||
next.type === NodeTypes.COMMENT ||
|
next.type === NodeTypes.COMMENT) ||
|
||||||
|
(prev.type === NodeTypes.COMMENT &&
|
||||||
|
next.type === NodeTypes.ELEMENT) ||
|
||||||
|
(prev.type === NodeTypes.ELEMENT &&
|
||||||
|
next.type === NodeTypes.COMMENT) ||
|
||||||
(prev.type === NodeTypes.ELEMENT &&
|
(prev.type === NodeTypes.ELEMENT &&
|
||||||
next.type === NodeTypes.ELEMENT &&
|
next.type === NodeTypes.ELEMENT &&
|
||||||
/[\r\n]/.test(node.content))))
|
/[\r\n]/.test(node.content))))
|
||||||
|
|
Loading…
Reference in New Issue