Skip to content

Commit

Permalink
fix(compiler-core): bail static stringfication even threshold is met (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Zardddddd60 authored Jun 9, 2020
1 parent 215c106 commit 64ec8bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
24 changes: 24 additions & 0 deletions packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,28 @@ describe('stringify static html', () => {
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
})
})
})
6 changes: 0 additions & 6 deletions packages/compiler-dom/src/transforms/stringifyStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,10 @@ function analyzeNode(node: StringifiableNode): [number, number] | false {
}
for (let i = 0; i < node.children.length; i++) {
nc++
if (nc >= StringifyThresholds.NODE_COUNT) {
return true
}
const child = node.children[i]
if (child.type === NodeTypes.ELEMENT) {
if (child.props.length > 0) {
ec++
if (ec >= StringifyThresholds.ELEMENT_WITH_BINDING_COUNT) {
return true
}
}
walk(child)
if (bailed) {
Expand Down

0 comments on commit 64ec8bf

Please sign in to comment.