Skip to content

Commit

Permalink
fix(compiler-core): fix self-closing tags with v-pre
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 19, 2021
1 parent 7e75b41 commit a21ca3d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
57 changes: 57 additions & 0 deletions packages/compiler-core/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,54 @@ describe('compiler: parse', () => {
})
})

test('self-closing v-pre', () => {
const ast = baseParse(
`<div v-pre/>\n<div :id="foo"><Comp/>{{ bar }}</div>`
)
// should not affect siblings after it
const divWithoutPre = ast.children[1] as ElementNode
expect(divWithoutPre.props).toMatchObject([
{
type: NodeTypes.DIRECTIVE,
name: `bind`,
arg: {
type: NodeTypes.SIMPLE_EXPRESSION,
isStatic: true,
content: `id`
},
exp: {
type: NodeTypes.SIMPLE_EXPRESSION,
isStatic: false,
content: `foo`
},
loc: {
source: `:id="foo"`,
start: {
line: 2,
column: 6
},
end: {
line: 2,
column: 15
}
}
}
])
expect(divWithoutPre.children[0]).toMatchObject({
type: NodeTypes.ELEMENT,
tagType: ElementTypes.COMPONENT,
tag: `Comp`
})
expect(divWithoutPre.children[1]).toMatchObject({
type: NodeTypes.INTERPOLATION,
content: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: `bar`,
isStatic: false
}
})
})

test('end tags are case-insensitive.', () => {
const ast = baseParse('<div>hello</DIV>after')
const element = ast.children[0] as ElementNode
Expand Down Expand Up @@ -1884,6 +1932,15 @@ foo
)
})

it('self-closing pre tag', () => {
const ast = baseParse(`<pre/><span>\n foo bar</span>`, {
isPreTag: tag => tag === 'pre'
})
const elementAfterPre = ast.children[1] as ElementNode
// should not affect the <span> and condense its whitepsace inside
expect((elementAfterPre.children[0] as TextNode).content).toBe(` foo bar`)
})

it('should NOT condense whitespaces in RCDATA text mode', () => {
const ast = baseParse(`<textarea>Text:\n foo</textarea>`, {
getTextMode: ({ tag }) =>
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ function parseElement(
if (isPreBoundary) {
context.inPre = false
}
if (isVPreBoundary) {
context.inVPre = false
}
return element
}

Expand Down

0 comments on commit a21ca3d

Please sign in to comment.