fix: bail stringification for slots

fix #1281, close #1286
This commit is contained in:
Evan You
2020-06-10 14:31:51 -04:00
parent fbaf52ae9f
commit 9b5d13e598
4 changed files with 59 additions and 12 deletions

View File

@@ -250,7 +250,7 @@ describe('stringify static html', () => {
})
})
test('should bail on break content with innerHTML (eg.tables related tags)', () => {
test('should bail on tags that has placement constraints (eg.tables related tags)', () => {
const { ast } = compileWithStringify(
`<table><tbody>${repeat(
`<tr class="foo"><td>foo</td></tr>`,
@@ -262,4 +262,36 @@ describe('stringify static html', () => {
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
})
test('should bail inside slots', () => {
const { ast } = compileWithStringify(
`<foo>${repeat(
`<div class="foo"></div>`,
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
)}</foo>`
)
expect(ast.hoists.length).toBe(
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
)
ast.hoists.forEach(node => {
expect(node).toMatchObject({
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
})
const { ast: ast2 } = compileWithStringify(
`<foo><template #foo>${repeat(
`<div class="foo"></div>`,
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
)}</template></foo>`
)
expect(ast2.hoists.length).toBe(
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
)
ast2.hoists.forEach(node => {
expect(node).toMatchObject({
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
})
})
})

View File

@@ -59,7 +59,15 @@ type StringifiableNode = PlainElementNode | TextCallNode
*
* This optimization is only performed in Node.js.
*/
export const stringifyStatic: HoistTransform = (children, context) => {
export const stringifyStatic: HoistTransform = (children, context, parent) => {
if (
parent.type === NodeTypes.ELEMENT &&
(parent.tagType === ElementTypes.COMPONENT ||
parent.tagType === ElementTypes.TEMPLATE)
) {
return
}
let nc = 0 // current node count
let ec = 0 // current element with binding count
const currentChunk: StringifiableNode[] = []