]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): bail static stringfication even threshold is met (#1298)
authorZardddddd60 <ldd_60@163.com>
Tue, 9 Jun 2020 20:26:03 +0000 (04:26 +0800)
committerGitHub <noreply@github.com>
Tue, 9 Jun 2020 20:26:03 +0000 (16:26 -0400)
fix #1128

packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
packages/compiler-dom/src/transforms/stringifyStatic.ts

index b4d96605c0bd21480f85e0fda427701309f461f1..46fe259177fb3452b31b70620f7fc30e115d7b2b 100644 (file)
@@ -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
+    })
+  })
 })
index a354dc2cdd9521e7afca71248ea13f1495f80108..6130d2395d3f9a093b41d40aa38d96e8959e0b0a 100644 (file)
@@ -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) {