]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: remove null comparisons
authorEvan You <yyx990803@gmail.com>
Wed, 18 Mar 2020 22:14:51 +0000 (18:14 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 18 Mar 2020 22:14:51 +0000 (18:14 -0400)
18 files changed:
packages/compiler-core/src/parse.ts
packages/reactivity/src/effect.ts
packages/runtime-core/src/apiWatch.ts
packages/runtime-core/src/componentProps.ts
packages/runtime-core/src/componentProxy.ts
packages/runtime-core/src/componentRenderUtils.ts
packages/runtime-core/src/componentSlots.ts
packages/runtime-core/src/components/KeepAlive.ts
packages/runtime-core/src/components/Portal.ts
packages/runtime-core/src/components/Suspense.ts
packages/runtime-core/src/errorHandling.ts
packages/runtime-core/src/hydration.ts
packages/runtime-core/src/renderer.ts
packages/runtime-core/src/vnode.ts
packages/runtime-dom/src/modules/props.ts
packages/runtime-dom/src/nodeOps.ts
packages/runtime-test/src/nodeOps.ts
packages/server-renderer/src/renderToString.ts

index dbadeff771bbc57556e455b36afecea230ee3b8f..648511c8353e3fe758ea18e53ef7f0506a754e32 100644 (file)
@@ -545,7 +545,7 @@ function parseAttribute(
   {
     const pattern = /["'<]/g
     let m: RegExpExecArray | null
-    while ((m = pattern.exec(name)) !== null) {
+    while ((m = pattern.exec(name))) {
       emitError(
         context,
         ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME,
@@ -696,7 +696,7 @@ function parseAttributeValue(
     }
     const unexpectedChars = /["'<=`]/g
     let m: RegExpExecArray | null
-    while ((m = unexpectedChars.exec(match[0])) !== null) {
+    while ((m = unexpectedChars.exec(match[0]))) {
       emitError(
         context,
         ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE,
index ae339be9d3d5abb0fa66d152a724b52dbc685a1b..7b8ec4d4b9312f38e076ea5b8518ccfe9603663e 100644 (file)
@@ -46,7 +46,7 @@ export let activeEffect: ReactiveEffect | undefined
 export const ITERATE_KEY = Symbol('iterate')
 
 export function isEffect(fn: any): fn is ReactiveEffect {
-  return fn != null && fn._isEffect === true
+  return fn && fn._isEffect === true
 }
 
 export function effect<T = any>(
index 889821a72a2bb85ec91e80ce10cb072e3b30ca06..329b639c421e9d622d5f61dc4c755d6a26d7f770 100644 (file)
@@ -229,7 +229,7 @@ function doWatch(
     scheduler = invoke
   } else if (flush === 'pre') {
     scheduler = job => {
-      if (!instance || instance.vnode.el != null) {
+      if (!instance || instance.isMounted) {
         queueJob(job)
       } else {
         // with 'pre' option, the first call must happen before
index d2f35da2ee2b93376dab248dd13d8f7d4d7c5502..0e55d022686df6e7d6acc98ccc8e15d4c0f4702c 100644 (file)
@@ -98,7 +98,7 @@ export function resolveProps(
   rawProps: Data | null,
   _options: ComponentPropsOptions | void
 ) {
-  const hasDeclaredProps = _options != null
+  const hasDeclaredProps = !!_options
   if (!rawProps && !hasDeclaredProps) {
     return
   }
@@ -122,7 +122,7 @@ export function resolveProps(
   // allow mutation of propsProxy (which is readonly by default)
   unlock()
 
-  if (rawProps != null) {
+  if (rawProps) {
     for (const key in rawProps) {
       const value = rawProps[key]
       // key, ref are reserved and never passed down
@@ -186,10 +186,7 @@ export function resolveProps(
   // in case of dynamic props, check if we need to delete keys from
   // the props proxy
   const { patchFlag } = instance.vnode
-  if (
-    propsProxy !== null &&
-    (patchFlag === 0 || patchFlag & PatchFlags.FULL_PROPS)
-  ) {
+  if (propsProxy && (patchFlag === 0 || patchFlag & PatchFlags.FULL_PROPS)) {
     const rawInitialProps = toRaw(propsProxy)
     for (const key in rawInitialProps) {
       if (!hasOwn(props, key)) {
@@ -250,7 +247,7 @@ function normalizePropsOptions(
         const opt = raw[key]
         const prop: NormalizedProp = (options[normalizedKey] =
           isArray(opt) || isFunction(opt) ? { type: opt } : opt)
-        if (prop != null) {
+        if (prop) {
           const booleanIndex = getTypeIndex(Boolean, prop.type)
           const stringIndex = getTypeIndex(String, prop.type)
           prop[BooleanFlags.shouldCast] = booleanIndex > -1
index fcbc406478a6673aac401fbe39ab45e550ed693f..eb496f658d2f4322e3795ab1b58066fefc9b7931 100644 (file)
@@ -109,7 +109,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
       } else if (renderContext !== EMPTY_OBJ && hasOwn(renderContext, key)) {
         accessCache![key] = AccessTypes.CONTEXT
         return renderContext[key]
-      } else if (type.props != null) {
+      } else if (type.props) {
         // only cache other properties when instance has declared (this stable)
         // props
         if (hasOwn(props, key)) {
@@ -125,20 +125,20 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
     // public $xxx properties & user-attached properties (sink)
     const publicGetter = publicPropertiesMap[key]
     let cssModule
-    if (publicGetter != null) {
+    if (publicGetter) {
       if (__DEV__ && key === '$attrs') {
         markAttrsAccessed()
       }
       return publicGetter(target)
     } else if (
       __BUNDLER__ &&
-      (cssModule = type.__cssModules) != null &&
+      (cssModule = type.__cssModules) &&
       (cssModule = cssModule[key])
     ) {
       return cssModule
     } else if (hasOwn(sink, key)) {
       return sink[key]
-    } else if (__DEV__ && currentRenderingInstance != null) {
+    } else if (__DEV__ && currentRenderingInstance) {
       warn(
         `Property ${JSON.stringify(key)} was accessed during render ` +
           `but is not defined on instance.`
@@ -152,7 +152,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
       accessCache![key] !== undefined ||
       (data !== EMPTY_OBJ && hasOwn(data, key)) ||
       hasOwn(renderContext, key) ||
-      (type.props != null && hasOwn(type.props, key)) ||
+      (type.props && hasOwn(type.props, key)) ||
       hasOwn(publicPropertiesMap, key) ||
       hasOwn(sink, key)
     )
index 316bb80ac478d7a8db1d7f2f201d173da0816eb7..571128b136ee492a21b145541a079f526d7bbfb2 100644 (file)
@@ -90,7 +90,7 @@ export function renderComponentRoot(
         result = cloneVNode(result, fallthroughAttrs)
         // If the child root node is a compiler optimized vnode, make sure it
         // force update full props to account for the merged attrs.
-        if (result.dynamicChildren !== null) {
+        if (result.dynamicChildren) {
           result.patchFlag |= PatchFlags.FULL_PROPS
         }
       } else if (__DEV__ && !accessedAttrs && result.type !== Comment) {
@@ -109,7 +109,7 @@ export function renderComponentRoot(
       result = cloneVNode(result, { [parentScopeId]: '' })
     }
     // inherit directives
-    if (vnode.dirs != null) {
+    if (vnode.dirs) {
       if (__DEV__ && !isElementRoot(result)) {
         warn(
           `Runtime directive used on component with non-element root node. ` +
@@ -119,7 +119,7 @@ export function renderComponentRoot(
       result.dirs = vnode.dirs
     }
     // inherit transition data
-    if (vnode.transition != null) {
+    if (vnode.transition) {
       if (__DEV__ && !isElementRoot(result)) {
         warn(
           `Component inside <Transition> renders non-element root node ` +
@@ -185,7 +185,7 @@ export function shouldUpdateComponent(
   }
 
   // force child update on runtime directive usage on component vnode.
-  if (nextVNode.dirs != null) {
+  if (nextVNode.dirs) {
     return true
   }
 
@@ -218,18 +218,18 @@ export function shouldUpdateComponent(
   } else if (!optimized) {
     // this path is only taken by manually written render functions
     // so presence of any children leads to a forced update
-    if (prevChildren != null || nextChildren != null) {
-      if (nextChildren == null || !(nextChildren as any).$stable) {
+    if (prevChildren || nextChildren) {
+      if (!nextChildren || !(nextChildren as any).$stable) {
         return true
       }
     }
     if (prevProps === nextProps) {
       return false
     }
-    if (prevProps === null) {
-      return nextProps !== null
+    if (!prevProps) {
+      return !!nextProps
     }
-    if (nextProps === null) {
+    if (!nextProps) {
       return true
     }
     return hasPropsChanged(prevProps, nextProps)
index db049246e7ce5d241b9c1846904aa5a60b6c75b0..e945996344f280c83a76aef7fd06e52002cafdbd 100644 (file)
@@ -40,7 +40,7 @@ const normalizeSlot = (
   ctx: ComponentInternalInstance | null | undefined
 ): Slot =>
   withCtx((props: any) => {
-    if (__DEV__ && currentInstance != null) {
+    if (__DEV__ && currentInstance) {
       warn(
         `Slot "${key}" invoked outside of the render function: ` +
           `this will not track dependencies used in the slot. ` +
@@ -80,7 +80,7 @@ export function resolveSlots(
         }
       }
     }
-  } else if (children !== null) {
+  } else if (children) {
     // non slot object children (direct value) passed to a component
     if (__DEV__ && !isKeepAlive(instance.vnode)) {
       warn(
index 8aae9b4efc29cdfb0c021b00e0e68e2e6a12dc0f..c7ecb3e85da8e71d59fa7076c63caa01e70d3759 100644 (file)
@@ -85,7 +85,7 @@ const KeepAliveImpl = {
       queuePostRenderEffect(() => {
         const component = vnode.component!
         component.isDeactivated = false
-        if (component.a !== null) {
+        if (component.a) {
           invokeHooks(component.a)
         }
       }, parentSuspense)
@@ -95,7 +95,7 @@ const KeepAliveImpl = {
       move(vnode, storageContainer, null, MoveType.LEAVE, parentSuspense)
       queuePostRenderEffect(() => {
         const component = vnode.component!
-        if (component.da !== null) {
+        if (component.da) {
           invokeHooks(component.da)
         }
         component.isDeactivated = true
index 93676867ad8e57740e121749ba5a1892e2a2873b..2a091cd368e7cf9d9c95a7455af6fd9c8e173729 100644 (file)
@@ -44,7 +44,7 @@ export const PortalImpl = {
       const target = (n2.target = isString(targetSelector)
         ? querySelector!(targetSelector)
         : targetSelector)
-      if (target != null) {
+      if (target) {
         if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {
           setElementText(target, children as string)
         } else if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
@@ -93,7 +93,7 @@ export const PortalImpl = {
         const nextTarget = (n2.target = isString(targetSelector)
           ? querySelector!(targetSelector)
           : targetSelector)
-        if (nextTarget != null) {
+        if (nextTarget) {
           // move content
           if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {
             setElementText(target, '')
index bdb44907e3f3e4f43a465bdb018b9499c74312f1..a7dd7e01fce54d1a32f2d7e32ab535125a69ced8 100644 (file)
@@ -536,7 +536,7 @@ export function queueEffectWithSuspense(
   fn: Function | Function[],
   suspense: SuspenseBoundary | null
 ): void {
-  if (suspense !== null && !suspense.isResolved) {
+  if (suspense && !suspense.isResolved) {
     if (isArray(fn)) {
       suspense.effects.push(...fn)
     } else {
index f027f0c3f76b147a725667640eb32ad0a9041154..c57fd8a99c4b09a464c36818cfb5209e9dc3c457 100644 (file)
@@ -79,7 +79,7 @@ export function callWithAsyncErrorHandling(
 ): any[] {
   if (isFunction(fn)) {
     const res = callWithErrorHandling(fn, instance, type, args)
-    if (res != null && !res._isVue && isPromise(res)) {
+    if (res && !res._isVue && isPromise(res)) {
       res.catch(err => {
         handleError(err, instance, type)
       })
@@ -108,7 +108,7 @@ export function handleError(
     const errorInfo = __DEV__ ? ErrorTypeStrings[type] : type
     while (cur) {
       const errorCapturedHooks = cur.ec
-      if (errorCapturedHooks !== null) {
+      if (errorCapturedHooks) {
         for (let i = 0; i < errorCapturedHooks.length; i++) {
           if (errorCapturedHooks[i](err, exposedInstance, errorInfo)) {
             return
index d81e6abdf3c3d66d91c47b5c27c056fd1ccd5edf..aa6c81b751c63c53146e90ae0febcf6ffc467bec 100644 (file)
@@ -199,12 +199,12 @@ export function createHydrationFunctions(
     parentSuspense: SuspenseBoundary | null,
     optimized: boolean
   ) => {
-    optimized = optimized || vnode.dynamicChildren !== null
+    optimized = optimized || !!vnode.dynamicChildren
     const { props, patchFlag, shapeFlag, dirs } = vnode
     // skip props & children if this is hoisted static nodes
     if (patchFlag !== PatchFlags.HOISTED) {
       // props
-      if (props !== null) {
+      if (props) {
         if (
           !optimized ||
           (patchFlag & PatchFlags.FULL_PROPS ||
@@ -215,7 +215,7 @@ export function createHydrationFunctions(
               patchProp(el, key, null, props[key])
             }
           }
-        } else if (props.onClick != null) {
+        } else if (props.onClick) {
           // Fast path for click listeners (which is most often) to avoid
           // iterating through props.
           patchProp(el, 'onClick', null, props.onClick)
@@ -223,16 +223,13 @@ export function createHydrationFunctions(
       }
       // vnode / directive hooks
       let vnodeHooks: VNodeHook | null | undefined
-      if ((vnodeHooks = props && props.onVnodeBeforeMount) != null) {
+      if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
         invokeVNodeHook(vnodeHooks, parentComponent, vnode)
       }
-      if (dirs != null) {
+      if (dirs) {
         invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount')
       }
-      if (
-        (vnodeHooks = props && props.onVnodeMounted) != null ||
-        dirs != null
-      ) {
+      if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
         queueEffectWithSuspense(() => {
           vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode)
           dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted')
@@ -242,7 +239,7 @@ export function createHydrationFunctions(
       if (
         shapeFlag & ShapeFlags.ARRAY_CHILDREN &&
         // skip if element has innerHTML / textContent
-        !(props !== null && (props.innerHTML || props.textContent))
+        !(props && (props.innerHTML || props.textContent))
       ) {
         let next = hydrateChildren(
           el.firstChild,
@@ -291,7 +288,7 @@ export function createHydrationFunctions(
     parentSuspense: SuspenseBoundary | null,
     optimized: boolean
   ): Node | null => {
-    optimized = optimized || vnode.dynamicChildren !== null
+    optimized = optimized || !!vnode.dynamicChildren
     const children = vnode.children as VNode[]
     const l = children.length
     let hasWarned = false
@@ -369,7 +366,7 @@ export function createHydrationFunctions(
     const target = (vnode.target = isString(targetSelector)
       ? document.querySelector(targetSelector)
       : targetSelector)
-    if (target != null && vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
+    if (target && vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
       hydrateChildren(
         target.firstChild,
         vnode,
index c8788352d3208b1f2f1cf744c1726e087ba1b442..942bedb5969873675449bea32edba05a9d5118de 100644 (file)
@@ -348,7 +348,7 @@ function baseCreateRenderer<
     optimized = false
   ) => {
     // patching & not same type, unmount old tree
-    if (n1 != null && !isSameVNodeType(n1, n2)) {
+    if (n1 && !isSameVNodeType(n1, n2)) {
       anchor = getNextHostNode(n1)
       unmount(n1, parentComponent, parentSuspense, true)
       n1 = null
@@ -476,7 +476,7 @@ function baseCreateRenderer<
     anchor: HostNode | null,
     isSVG: boolean
   ) => {
-    if (n2.el != null && hostCloneNode !== undefined) {
+    if (n2.el && hostCloneNode !== undefined) {
       hostInsert(hostCloneNode(n2.el), container, anchor)
     } else {
       // static nodes are only present when used with compiler-dom/runtime-dom
@@ -514,7 +514,7 @@ function baseCreateRenderer<
     } else {
       patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized)
     }
-    if (n2.ref !== null && parentComponent !== null) {
+    if (n2.ref != null && parentComponent) {
       setRef(n2.ref, n1 && n1.ref, parentComponent, n2.el)
     }
   }
@@ -540,7 +540,7 @@ function baseCreateRenderer<
       dirs
     } = vnode
     if (
-      vnode.el !== null &&
+      vnode.el &&
       hostCloneNode !== undefined &&
       patchFlag === PatchFlags.HOISTED
     ) {
@@ -551,29 +551,29 @@ function baseCreateRenderer<
     } else {
       el = vnode.el = hostCreateElement(vnode.type as string, isSVG)
       // props
-      if (props != null) {
+      if (props) {
         for (const key in props) {
           if (!isReservedProp(key)) {
             hostPatchProp(el, key, null, props[key], isSVG)
           }
         }
-        if ((vnodeHook = props.onVnodeBeforeMount) != null) {
+        if ((vnodeHook = props.onVnodeBeforeMount)) {
           invokeVNodeHook(vnodeHook, parentComponent, vnode)
         }
       }
-      if (dirs != null) {
+      if (dirs) {
         invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount')
       }
 
       // scopeId
       if (__BUNDLER__) {
-        if (scopeId !== null) {
+        if (scopeId) {
           hostSetScopeId(el, scopeId)
         }
         const treeOwnerId = parentComponent && parentComponent.type.__scopeId
         // vnode's own scopeId and the current patched component's scopeId is
         // different - this is a slot content node.
-        if (treeOwnerId != null && treeOwnerId !== scopeId) {
+        if (treeOwnerId && treeOwnerId !== scopeId) {
           hostSetScopeId(el, treeOwnerId + '-s')
         }
       }
@@ -589,19 +589,19 @@ function baseCreateRenderer<
           parentComponent,
           parentSuspense,
           isSVG && type !== 'foreignObject',
-          optimized || vnode.dynamicChildren !== null
+          optimized || !!vnode.dynamicChildren
         )
       }
-      if (transition != null && !transition.persisted) {
+      if (transition && !transition.persisted) {
         transition.beforeEnter(el)
       }
     }
 
     hostInsert(el, container, anchor)
     if (
-      (vnodeHook = props && props.onVnodeMounted) != null ||
-      (transition != null && !transition.persisted) ||
-      dirs != null
+      (vnodeHook = props && props.onVnodeMounted) ||
+      (transition && !transition.persisted) ||
+      dirs
     ) {
       queuePostRenderEffect(() => {
         vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode)
@@ -652,10 +652,10 @@ function baseCreateRenderer<
     const newProps = n2.props || EMPTY_OBJ
     let vnodeHook: VNodeHook | undefined | null
 
-    if ((vnodeHook = newProps.onVnodeBeforeUpdate) != null) {
+    if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
       invokeVNodeHook(vnodeHook, parentComponent, n2, n1)
     }
-    if (dirs != null) {
+    if (dirs) {
       invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate')
     }
 
@@ -748,7 +748,7 @@ function baseCreateRenderer<
     }
 
     const areChildrenSVG = isSVG && n2.type !== 'foreignObject'
-    if (dynamicChildren != null) {
+    if (dynamicChildren) {
       patchBlockChildren(
         n1.dynamicChildren!,
         dynamicChildren,
@@ -770,7 +770,7 @@ function baseCreateRenderer<
       )
     }
 
-    if ((vnodeHook = newProps.onVnodeUpdated) != null || dirs != null) {
+    if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
       queuePostRenderEffect(() => {
         vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1)
         dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated')
@@ -906,7 +906,7 @@ function baseCreateRenderer<
         optimized
       )
     } else {
-      if (patchFlag & PatchFlags.STABLE_FRAGMENT && dynamicChildren != null) {
+      if (patchFlag & PatchFlags.STABLE_FRAGMENT && dynamicChildren) {
         // a stable fragment (template root or <template v-for>) doesn't need to
         // patch children order, but it may contain dynamicChildren.
         patchBlockChildren(
@@ -997,7 +997,7 @@ function baseCreateRenderer<
         n2.el = n1.el
       }
     }
-    if (n2.ref !== null && parentComponent !== null) {
+    if (n2.ref != null && parentComponent) {
       if (__DEV__ && !(n2.shapeFlag & ShapeFlags.STATEFUL_COMPONENT)) {
         pushWarningContext(n2)
         warn(
@@ -1023,7 +1023,7 @@ function baseCreateRenderer<
       parentComponent
     ))
 
-    if (__HMR__ && instance.type.__hmrId != null) {
+    if (__HMR__ && instance.type.__hmrId) {
       registerHMR(instance)
     }
 
@@ -1089,11 +1089,11 @@ function baseCreateRenderer<
         const { bm, m, a, parent } = instance
         const subTree = (instance.subTree = renderComponentRoot(instance))
         // beforeMount hook
-        if (bm !== null) {
+        if (bm) {
           invokeHooks(bm)
         }
         // onVnodeBeforeMount
-        if ((vnodeHook = props && props.onVnodeBeforeMount) != null) {
+        if ((vnodeHook = props && props.onVnodeBeforeMount)) {
           invokeVNodeHook(vnodeHook, parent, initialVNode)
         }
         if (el && hydrateNode) {
@@ -1117,18 +1117,18 @@ function baseCreateRenderer<
           initialVNode.el = subTree.el
         }
         // mounted hook
-        if (m !== null) {
+        if (m) {
           queuePostRenderEffect(m, parentSuspense)
         }
         // onVnodeMounted
-        if ((vnodeHook = props && props.onVnodeMounted) != null) {
+        if ((vnodeHook = props && props.onVnodeMounted)) {
           queuePostRenderEffect(() => {
             invokeVNodeHook(vnodeHook!, parent, initialVNode)
           }, parentSuspense)
         }
         // activated hook for keep-alive roots.
         if (
-          a !== null &&
+          a &&
           initialVNode.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
         ) {
           queuePostRenderEffect(a, parentSuspense)
@@ -1144,7 +1144,7 @@ function baseCreateRenderer<
           pushWarningContext(next || instance.vnode)
         }
 
-        if (next !== null) {
+        if (next) {
           updateComponentPreRender(instance, next)
         } else {
           next = vnode
@@ -1154,13 +1154,11 @@ function baseCreateRenderer<
         instance.subTree = nextTree
         next.el = vnode.el
         // beforeUpdate hook
-        if (bu !== null) {
+        if (bu) {
           invokeHooks(bu)
         }
         // onVnodeBeforeUpdate
-        if (
-          (vnodeHook = next.props && next.props.onVnodeBeforeUpdate) != null
-        ) {
+        if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
           invokeVNodeHook(vnodeHook, parent, next, vnode)
         }
         // reset refs
@@ -1187,11 +1185,11 @@ function baseCreateRenderer<
           updateHOCHostEl(instance, nextTree.el)
         }
         // updated hook
-        if (u !== null) {
+        if (u) {
           queuePostRenderEffect(u, parentSuspense)
         }
         // onVnodeUpdated
-        if ((vnodeHook = next.props && next.props.onVnodeUpdated) != null) {
+        if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
           queuePostRenderEffect(() => {
             invokeVNodeHook(vnodeHook!, parent, next!, vnode)
           }, parentSuspense)
@@ -1632,7 +1630,7 @@ function baseCreateRenderer<
       const needTransition =
         type !== MoveType.REORDER &&
         shapeFlag & ShapeFlags.ELEMENT &&
-        transition != null
+        transition
       if (needTransition) {
         if (type === MoveType.ENTER) {
           transition!.beforeEnter(el!)
@@ -1666,15 +1664,15 @@ function baseCreateRenderer<
     doRemove = false
   ) => {
     const { props, ref, children, dynamicChildren, shapeFlag, dirs } = vnode
-    const shouldInvokeDirs = dirs != null && shapeFlag & ShapeFlags.ELEMENT
+    const shouldInvokeDirs = shapeFlag & ShapeFlags.ELEMENT && dirs
     let vnodeHook: VNodeHook | undefined | null
 
     // unset ref
-    if (ref !== null && parentComponent !== null) {
+    if (ref != null && parentComponent) {
       setRef(ref, null, parentComponent, null)
     }
 
-    if ((vnodeHook = props && props.onVnodeBeforeUnmount) != null) {
+    if ((vnodeHook = props && props.onVnodeBeforeUnmount)) {
       invokeVNodeHook(vnodeHook, parentComponent, vnode)
     }
 
@@ -1694,7 +1692,7 @@ function baseCreateRenderer<
         invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount')
       }
 
-      if (dynamicChildren != null) {
+      if (dynamicChildren) {
         // fast path for block nodes: only need to unmount dynamic children.
         unmountChildren(dynamicChildren, parentComponent, parentSuspense)
       } else if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
@@ -1710,10 +1708,7 @@ function baseCreateRenderer<
       }
     }
 
-    if (
-      (vnodeHook = props && props.onVnodeUnmounted) != null ||
-      shouldInvokeDirs
-    ) {
+    if ((vnodeHook = props && props.onVnodeUnmounted) || shouldInvokeDirs) {
       queuePostRenderEffect(() => {
         vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode)
         shouldInvokeDirs &&
@@ -1731,18 +1726,14 @@ function baseCreateRenderer<
 
     const performRemove = () => {
       hostRemove(el!)
-      if (
-        transition != null &&
-        !transition.persisted &&
-        transition.afterLeave
-      ) {
+      if (transition && !transition.persisted && transition.afterLeave) {
         transition.afterLeave()
       }
     }
 
     if (
       vnode.shapeFlag & ShapeFlags.ELEMENT &&
-      transition != null &&
+      transition &&
       !transition.persisted
     ) {
       const { leave, delayLeave } = transition
@@ -1774,33 +1765,33 @@ function baseCreateRenderer<
     parentSuspense: HostSuspenseBoundary | null,
     doRemove?: boolean
   ) => {
-    if (__HMR__ && instance.type.__hmrId != null) {
+    if (__HMR__ && instance.type.__hmrId) {
       unregisterHMR(instance)
     }
 
     const { bum, effects, update, subTree, um, da, isDeactivated } = instance
     // beforeUnmount hook
-    if (bum !== null) {
+    if (bum) {
       invokeHooks(bum)
     }
-    if (effects !== null) {
+    if (effects) {
       for (let i = 0; i < effects.length; i++) {
         stop(effects[i])
       }
     }
     // update may be null if a component is unmounted before its async
     // setup has resolved.
-    if (update !== null) {
+    if (update) {
       stop(update)
       unmount(subTree, instance, parentSuspense, doRemove)
     }
     // unmounted hook
-    if (um !== null) {
+    if (um) {
       queuePostRenderEffect(um, parentSuspense)
     }
     // deactivated hook
     if (
-      da !== null &&
+      da &&
       !isDeactivated &&
       instance.vnode.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
     ) {
@@ -1815,10 +1806,10 @@ function baseCreateRenderer<
     // cause the suspense to resolve immediately if that was the last dep.
     if (
       __FEATURE_SUSPENSE__ &&
-      parentSuspense !== null &&
+      parentSuspense &&
       !parentSuspense.isResolved &&
       !parentSuspense.isUnmounted &&
-      instance.asyncDep !== null &&
+      instance.asyncDep &&
       !instance.asyncResolved
     ) {
       parentSuspense.deps--
@@ -1869,7 +1860,7 @@ function baseCreateRenderer<
     const renderContext = toRaw(owner.renderContext)
 
     // unset old ref
-    if (oldRef !== null && oldRef !== ref) {
+    if (oldRef != null && oldRef !== ref) {
       if (isString(oldRef)) {
         refs[oldRef] = null
         const oldSetupRef = renderContext[oldRef]
index 592aa8b33cc6cf9b49806af2aff2e33a270bf632..151cc866b67c98fff0323935d137611de60239da 100644 (file)
@@ -196,7 +196,7 @@ export function createBlock(
   currentBlock = blockStack[blockStack.length - 1] || null
   // a block is always going to be patched, so track it as a child of its
   // parent block
-  if (currentBlock !== null) {
+  if (currentBlock) {
     currentBlock.push(vnode)
   }
   return vnode
@@ -239,13 +239,13 @@ export function createVNode(
   }
 
   // class & style normalization.
-  if (props !== null) {
+  if (props) {
     // for reactive or proxy objects, we need to clone it to enable mutation.
     if (isReactive(props) || SetupProxySymbol in props) {
       props = extend({}, props)
     }
     let { class: klass, style } = props
-    if (klass != null && !isString(klass)) {
+    if (klass && !isString(klass)) {
       props.class = normalizeClass(klass)
     }
     if (isObject(style)) {
@@ -275,9 +275,9 @@ export function createVNode(
     _isVNode: true,
     type,
     props,
-    key: props !== null && props.key !== undefined ? props.key : null,
+    key: props && props.key !== undefined ? props.key : null,
     ref:
-      props !== null && props.ref !== undefined
+      props && props.ref !== undefined
         ? [currentRenderingInstance!, props.ref]
         : null,
     scopeId: currentScopeId,
@@ -304,7 +304,7 @@ export function createVNode(
   // the next vnode so that it can be properly unmounted later.
   if (
     shouldTrack > 0 &&
-    currentBlock !== null &&
+    currentBlock &&
     // the EVENTS flag is only for hydration and if it is the only flag, the
     // vnode should not be considered dynamic due to handler caching.
     patchFlag !== PatchFlags.HYDRATE_EVENTS &&
index 911d6215dce1595a303a984f0742d6d21d4275b0..15f95ccadd34b72e1ad1a99f99b6b054f2dbb94e 100644 (file)
@@ -14,7 +14,7 @@ export function patchDOMProp(
   parentSuspense: any,
   unmountChildren: any
 ) {
-  if ((key === 'innerHTML' || key === 'textContent') && prevChildren != null) {
+  if ((key === 'innerHTML' || key === 'textContent') && prevChildren) {
     unmountChildren(prevChildren, parentComponent, parentSuspense)
     el[key] = value == null ? '' : value
     return
index 6c981cd383cecbbde1d21d971e31da484c07a386..e19815abc157e00268ded3c026c2763734c0b7ab 100644 (file)
@@ -8,7 +8,7 @@ let tempSVGContainer: SVGElement
 
 export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
   insert: (child, parent, anchor) => {
-    if (anchor != null) {
+    if (anchor) {
       parent.insertBefore(child, anchor)
     } else {
       parent.appendChild(child)
@@ -17,7 +17,7 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
 
   remove: child => {
     const parent = child.parentNode
-    if (parent != null) {
+    if (parent) {
       parent.removeChild(child)
     }
   },
index 1352f7668c4fd1bf1d2047e7c5e7ce9e74dbdc2f..d86fdeaf445bff47f11952c77ce157cb32142a15 100644 (file)
@@ -139,7 +139,7 @@ function setText(node: TestText, text: string) {
 
 function insert(child: TestNode, parent: TestElement, ref?: TestNode | null) {
   let refIndex
-  if (ref != null) {
+  if (ref) {
     refIndex = parent.children.indexOf(ref)
     if (refIndex === -1) {
       console.error('ref: ', ref)
@@ -168,7 +168,7 @@ function insert(child: TestNode, parent: TestElement, ref?: TestNode | null) {
 
 function remove(child: TestNode, logOp: boolean = true) {
   const parent = child.parentNode
-  if (parent != null) {
+  if (parent) {
     if (logOp) {
       logNodeOp({
         type: NodeOpTypes.REMOVE,
index 6f12f44c49fdd53562fe624895fe86d85ca47d73..1253bbc0bfb6b9691ac5a1d92dab4cf3d0966953 100644 (file)
@@ -295,20 +295,20 @@ function renderElementVNode(
   let { props, children, shapeFlag, scopeId, dirs } = vnode
   let openTag = `<${tag}`
 
-  if (dirs !== null) {
+  if (dirs) {
     props = applySSRDirectives(vnode, props, dirs)
   }
 
-  if (props !== null) {
+  if (props) {
     openTag += ssrRenderAttrs(props, tag)
   }
 
-  if (scopeId !== null) {
+  if (scopeId) {
     openTag += ` ${scopeId}`
     const treeOwnerId = parentComponent && parentComponent.type.__scopeId
     // vnode's own scopeId and the current rendering component's scopeId is
     // different - this is a slot content node.
-    if (treeOwnerId != null && treeOwnerId !== scopeId) {
+    if (treeOwnerId && treeOwnerId !== scopeId) {
       openTag += ` ${treeOwnerId}-s`
     }
   }
@@ -316,7 +316,7 @@ function renderElementVNode(
   push(openTag + `>`)
   if (!isVoidTag(tag)) {
     let hasChildrenOverride = false
-    if (props !== null) {
+    if (props) {
       if (props.innerHTML) {
         hasChildrenOverride = true
         push(props.innerHTML)