Просмотр исходного кода

fix(runtime-core): simplify block-tracking disabling in h() (#13841)

edison 7 месяцев назад
Родитель
Сommit
75220c7995
1 измененных файлов с 22 добавлено и 26 удалено
  1. 22 26
      packages/runtime-core/src/h.ts

+ 22 - 26
packages/runtime-core/src/h.ts

@@ -202,35 +202,31 @@ export function h<P>(
 
 
 // Actual implementation
 // Actual implementation
 export function h(type: any, propsOrChildren?: any, children?: any): VNode {
 export function h(type: any, propsOrChildren?: any, children?: any): VNode {
-  // #6913 disable tracking block in h function
-  const doCreateVNode = (type: any, props?: any, children?: any) => {
+  try {
+    // #6913 disable tracking block in h function
     setBlockTracking(-1)
     setBlockTracking(-1)
-    try {
-      return createVNode(type, props, children)
-    } finally {
-      setBlockTracking(1)
-    }
-  }
-
-  const l = arguments.length
-  if (l === 2) {
-    if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
-      // single vnode without props
-      if (isVNode(propsOrChildren)) {
-        return doCreateVNode(type, null, [propsOrChildren])
+    const l = arguments.length
+    if (l === 2) {
+      if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
+        // single vnode without props
+        if (isVNode(propsOrChildren)) {
+          return createVNode(type, null, [propsOrChildren])
+        }
+        // props without children
+        return createVNode(type, propsOrChildren)
+      } else {
+        // omit props
+        return createVNode(type, null, propsOrChildren)
       }
       }
-      // props without children
-      return doCreateVNode(type, propsOrChildren)
     } else {
     } else {
-      // omit props
-      return doCreateVNode(type, null, propsOrChildren)
-    }
-  } else {
-    if (l > 3) {
-      children = Array.prototype.slice.call(arguments, 2)
-    } else if (l === 3 && isVNode(children)) {
-      children = [children]
+      if (l > 3) {
+        children = Array.prototype.slice.call(arguments, 2)
+      } else if (l === 3 && isVNode(children)) {
+        children = [children]
+      }
+      return createVNode(type, propsOrChildren, children)
     }
     }
-    return doCreateVNode(type, propsOrChildren, children)
+  } finally {
+    setBlockTracking(1)
   }
   }
 }
 }