fix(compiler-core): bail static stringfication even threshold is met (#1298)

fix #1128
This commit is contained in:
Zardddddd60 2020-06-10 04:26:03 +08:00 committed by GitHub
parent 215c106297
commit 64ec8bfb54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 6 deletions

View File

@ -225,4 +225,28 @@ describe('stringify static html', () => {
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
}) })
}) })
test('should bail on non attribute bindings', () => {
const { ast } = compileWithStringify(
`<div><div>${repeat(
`<span class="foo">foo</span>`,
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
)}<input indeterminate></div></div>`
)
expect(ast.hoists.length).toBe(1)
expect(ast.hoists[0]).toMatchObject({
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
const { ast: ast2 } = compileWithStringify(
`<div><div>${repeat(
`<span class="foo">foo</span>`,
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
)}<input :indeterminate="true"></div></div>`
)
expect(ast2.hoists.length).toBe(1)
expect(ast2.hoists[0]).toMatchObject({
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
})
}) })

View File

@ -189,16 +189,10 @@ function analyzeNode(node: StringifiableNode): [number, number] | false {
} }
for (let i = 0; i < node.children.length; i++) { for (let i = 0; i < node.children.length; i++) {
nc++ nc++
if (nc >= StringifyThresholds.NODE_COUNT) {
return true
}
const child = node.children[i] const child = node.children[i]
if (child.type === NodeTypes.ELEMENT) { if (child.type === NodeTypes.ELEMENT) {
if (child.props.length > 0) { if (child.props.length > 0) {
ec++ ec++
if (ec >= StringifyThresholds.ELEMENT_WITH_BINDING_COUNT) {
return true
}
} }
walk(child) walk(child)
if (bailed) { if (bailed) {