Skip to content

Commit

Permalink
fix(compiler-core): should not condense whitespace in RCDATA text mode (
Browse files Browse the repository at this point in the history
  • Loading branch information
HcySunYang authored Mar 25, 2021
1 parent 6e88156 commit b4b8215
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/compiler-core/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,16 @@ foo
`\n foo bar `
)
})

it('should NOT condense whitespaces in RCDATA text mode', () => {
const ast = baseParse(`<textarea>Text:\n foo</textarea>`, {
getTextMode: ({ tag }) =>
tag === 'textarea' ? TextModes.RCDATA : TextModes.DATA
})
const preElement = ast.children[0] as ElementNode
expect(preElement.children).toHaveLength(1)
expect((preElement.children[0] as TextNode).content).toBe(`Text:\n foo`)
})
})

describe('Errors', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function parseChildren(
// Whitespace management for more efficient output
// (same as v2 whitespace: 'condense')
let removedWhitespace = false
if (mode !== TextModes.RAWTEXT) {
if (mode !== TextModes.RAWTEXT && mode !== TextModes.RCDATA) {
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i]
if (!context.inPre && node.type === NodeTypes.TEXT) {
Expand Down

0 comments on commit b4b8215

Please sign in to comment.