fix(compiler): fix pre tag whitespace handling

- should preserve whitespace even in nested elements
- should remove leading newline per spec

fix #908
This commit is contained in:
Evan You
2020-04-03 21:02:20 -04:00
parent c7c3a6a3be
commit 7f30cb5772
2 changed files with 83 additions and 40 deletions

View File

@@ -116,11 +116,36 @@ describe('DOM parser', () => {
})
test('<pre> tag should preserve raw whitespace', () => {
const rawText = ` \na b \n c`
const rawText = ` \na <div>foo \n bar</div> \n c`
const ast = parse(`<pre>${rawText}</pre>`, parserOptions)
expect((ast.children[0] as ElementNode).children).toMatchObject([
{
type: NodeTypes.TEXT,
content: ` \na `
},
{
type: NodeTypes.ELEMENT,
children: [
{
type: NodeTypes.TEXT,
content: `foo \n bar`
}
]
},
{
type: NodeTypes.TEXT,
content: ` \n c`
}
])
})
// #908
test('<pre> tag should remove leading newline', () => {
const rawText = `\nhello`
const ast = parse(`<pre>${rawText}</pre>`, parserOptions)
expect((ast.children[0] as ElementNode).children[0]).toMatchObject({
type: NodeTypes.TEXT,
content: rawText
content: rawText.slice(1)
})
})
})