This commit is contained in:
Rudy 2025-06-30 14:28:42 +03:00 committed by GitHub
commit 8423964a98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 4 deletions

View File

@ -7,7 +7,26 @@ exports[`compiler: parse > Edge Cases > invalid html 1`] = `
{ {
"children": [ "children": [
{ {
"children": [], "children": [
{
"content": " ",
"loc": {
"end": {
"column": 1,
"line": 3,
"offset": 13,
},
"source": "
",
"start": {
"column": 7,
"line": 2,
"offset": 12,
},
},
"type": 2,
},
],
"codegenNode": undefined, "codegenNode": undefined,
"loc": { "loc": {
"end": { "end": {

View File

@ -2371,6 +2371,12 @@ describe('compiler: parse', () => {
expect((ast.children[0] as TextNode).content).toBe(` foo bar baz `) expect((ast.children[0] as TextNode).content).toBe(` foo bar baz `)
}) })
// #7789
test('should condense consecutive whitespaces in texts full of whitespaces', () => {
const ast = parse(` `)
expect((ast.children[0] as TextNode).content).toBe(` `)
})
test('should remove leading newline character immediately following the pre element start tag', () => { test('should remove leading newline character immediately following the pre element start tag', () => {
const ast = parse(`<pre>\n foo bar </pre>`, { const ast = parse(`<pre>\n foo bar </pre>`, {
isPreTag: tag => tag === 'pre', isPreTag: tag => tag === 'pre',
@ -2488,6 +2494,13 @@ describe('compiler: parse', () => {
const ast = parse(content) const ast = parse(content)
expect((ast.children[0] as TextNode).content).toBe(content) expect((ast.children[0] as TextNode).content).toBe(content)
}) })
// #7789
test('should preserve consecutive whitespaces in texts full of whitespaces', () => {
const whitespaces = ' '
const ast = parse(`${whitespaces}`)
expect((ast.children[0] as TextNode).content).toBe(whitespaces)
})
}) })
describe('expression parsing', () => { describe('expression parsing', () => {

View File

@ -839,7 +839,8 @@ function condenseWhitespace(nodes: TemplateChildNode[]): TemplateChildNode[] {
const node = nodes[i] const node = nodes[i]
if (node.type === NodeTypes.TEXT) { if (node.type === NodeTypes.TEXT) {
if (!inPre) { if (!inPre) {
if (isAllWhitespace(node.content)) { // #7789
if (isAllWhitespace(node.content) && nodes.length > 1) {
const prev = nodes[i - 1] && nodes[i - 1].type const prev = nodes[i - 1] && nodes[i - 1].type
const next = nodes[i + 1] && nodes[i + 1].type const next = nodes[i + 1] && nodes[i + 1].type
// Remove if: // Remove if:

View File

@ -132,8 +132,7 @@ describe('transition-group', () => {
test('attribute fallthrough', () => { test('attribute fallthrough', () => {
expect( expect(
compile( compile(
`<transition-group tag="ul" class="red" id="ok"> `<transition-group tag="ul" class="red" id="ok"></transition-group>`,
</transition-group>`,
).code, ).code,
).toMatchInlineSnapshot(` ).toMatchInlineSnapshot(`
"const { mergeProps: _mergeProps } = require("vue") "const { mergeProps: _mergeProps } = require("vue")