refactor: merge bitwise flag checks (#4324)

This commit is contained in:
Hazlank 2021-08-16 14:13:04 -05:00 committed by GitHub
parent e936898abd
commit 6db15a27cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 15 deletions

View File

@ -128,10 +128,7 @@ export function renderComponentRoot(
const keys = Object.keys(fallthroughAttrs) const keys = Object.keys(fallthroughAttrs)
const { shapeFlag } = root const { shapeFlag } = root
if (keys.length) { if (keys.length) {
if ( if (shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.COMPONENT)) {
shapeFlag & ShapeFlags.ELEMENT ||
shapeFlag & ShapeFlags.COMPONENT
) {
if (propsOptions && keys.some(isModelListener)) { if (propsOptions && keys.some(isModelListener)) {
// If a v-model listener (onUpdate:xxx) has a corresponding declared // If a v-model listener (onUpdate:xxx) has a corresponding declared
// prop, it indicates this component expects to handle v-model and // prop, it indicates this component expects to handle v-model and
@ -186,8 +183,7 @@ export function renderComponentRoot(
__COMPAT__ && __COMPAT__ &&
isCompatEnabled(DeprecationTypes.INSTANCE_ATTRS_CLASS_STYLE, instance) && isCompatEnabled(DeprecationTypes.INSTANCE_ATTRS_CLASS_STYLE, instance) &&
vnode.shapeFlag & ShapeFlags.STATEFUL_COMPONENT && vnode.shapeFlag & ShapeFlags.STATEFUL_COMPONENT &&
(root.shapeFlag & ShapeFlags.ELEMENT || root.shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.COMPONENT)
root.shapeFlag & ShapeFlags.COMPONENT)
) { ) {
const { class: cls, style } = vnode.props || {} const { class: cls, style } = vnode.props || {}
if (cls || style) { if (cls || style) {
@ -316,8 +312,7 @@ const filterModelListeners = (attrs: Data, props: NormalizedProps): Data => {
const isElementRoot = (vnode: VNode) => { const isElementRoot = (vnode: VNode) => {
return ( return (
vnode.shapeFlag & ShapeFlags.COMPONENT || vnode.shapeFlag & (ShapeFlags.COMPONENT | ShapeFlags.ELEMENT) ||
vnode.shapeFlag & ShapeFlags.ELEMENT ||
vnode.type === Comment // potential v-if branch switch vnode.type === Comment // potential v-if branch switch
) )
} }

View File

@ -280,8 +280,7 @@ export function createHydrationFunctions(
if ( if (
forcePatchValue || forcePatchValue ||
!optimized || !optimized ||
patchFlag & PatchFlags.FULL_PROPS || patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.HYDRATE_EVENTS)
patchFlag & PatchFlags.HYDRATE_EVENTS
) { ) {
for (const key in props) { for (const key in props) {
if ( if (

View File

@ -984,8 +984,7 @@ function baseCreateRenderer(
// which also requires the correct parent container // which also requires the correct parent container
!isSameVNodeType(oldVNode, newVNode) || !isSameVNodeType(oldVNode, newVNode) ||
// - In the case of a component, it could contain anything. // - In the case of a component, it could contain anything.
oldVNode.shapeFlag & ShapeFlags.COMPONENT || oldVNode.shapeFlag & (ShapeFlags.COMPONENT | ShapeFlags.TELEPORT))
oldVNode.shapeFlag & ShapeFlags.TELEPORT)
? hostParentNode(oldVNode.el)! ? hostParentNode(oldVNode.el)!
: // In other cases, the parent container is not actually used so we : // In other cases, the parent container is not actually used so we
// just pass the block element here to avoid a DOM parentNode call. // just pass the block element here to avoid a DOM parentNode call.
@ -2129,8 +2128,8 @@ function baseCreateRenderer(
) )
} else if ( } else if (
(type === Fragment && (type === Fragment &&
(patchFlag & PatchFlags.KEYED_FRAGMENT || patchFlag &
patchFlag & PatchFlags.UNKEYED_FRAGMENT)) || (PatchFlags.KEYED_FRAGMENT | PatchFlags.UNKEYED_FRAGMENT)) ||
(!optimized && shapeFlag & ShapeFlags.ARRAY_CHILDREN) (!optimized && shapeFlag & ShapeFlags.ARRAY_CHILDREN)
) { ) {
unmountChildren(children as VNode[], parentComponent, parentSuspense) unmountChildren(children as VNode[], parentComponent, parentSuspense)

View File

@ -730,7 +730,7 @@ export function normalizeChildren(vnode: VNode, children: unknown) {
} else if (isArray(children)) { } else if (isArray(children)) {
type = ShapeFlags.ARRAY_CHILDREN type = ShapeFlags.ARRAY_CHILDREN
} else if (typeof children === 'object') { } else if (typeof children === 'object') {
if (shapeFlag & ShapeFlags.ELEMENT || shapeFlag & ShapeFlags.TELEPORT) { if (shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.TELEPORT)) {
// Normalize slot to plain children for plain element and Teleport // Normalize slot to plain children for plain element and Teleport
const slot = (children as any).default const slot = (children as any).default
if (slot) { if (slot) {