Skip to content

Commit 6db15a2

Browse files
authored
refactor: merge bitwise flag checks (#4324)
1 parent e936898 commit 6db15a2

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

packages/runtime-core/src/componentRenderUtils.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ export function renderComponentRoot(
128128
const keys = Object.keys(fallthroughAttrs)
129129
const { shapeFlag } = root
130130
if (keys.length) {
131-
if (
132-
shapeFlag & ShapeFlags.ELEMENT ||
133-
shapeFlag & ShapeFlags.COMPONENT
134-
) {
131+
if (shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.COMPONENT)) {
135132
if (propsOptions && keys.some(isModelListener)) {
136133
// If a v-model listener (onUpdate:xxx) has a corresponding declared
137134
// prop, it indicates this component expects to handle v-model and
@@ -186,8 +183,7 @@ export function renderComponentRoot(
186183
__COMPAT__ &&
187184
isCompatEnabled(DeprecationTypes.INSTANCE_ATTRS_CLASS_STYLE, instance) &&
188185
vnode.shapeFlag & ShapeFlags.STATEFUL_COMPONENT &&
189-
(root.shapeFlag & ShapeFlags.ELEMENT ||
190-
root.shapeFlag & ShapeFlags.COMPONENT)
186+
root.shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.COMPONENT)
191187
) {
192188
const { class: cls, style } = vnode.props || {}
193189
if (cls || style) {
@@ -316,8 +312,7 @@ const filterModelListeners = (attrs: Data, props: NormalizedProps): Data => {
316312

317313
const isElementRoot = (vnode: VNode) => {
318314
return (
319-
vnode.shapeFlag & ShapeFlags.COMPONENT ||
320-
vnode.shapeFlag & ShapeFlags.ELEMENT ||
315+
vnode.shapeFlag & (ShapeFlags.COMPONENT | ShapeFlags.ELEMENT) ||
321316
vnode.type === Comment // potential v-if branch switch
322317
)
323318
}

packages/runtime-core/src/hydration.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ export function createHydrationFunctions(
280280
if (
281281
forcePatchValue ||
282282
!optimized ||
283-
patchFlag & PatchFlags.FULL_PROPS ||
284-
patchFlag & PatchFlags.HYDRATE_EVENTS
283+
patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.HYDRATE_EVENTS)
285284
) {
286285
for (const key in props) {
287286
if (

packages/runtime-core/src/renderer.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,7 @@ function baseCreateRenderer(
984984
// which also requires the correct parent container
985985
!isSameVNodeType(oldVNode, newVNode) ||
986986
// - In the case of a component, it could contain anything.
987-
oldVNode.shapeFlag & ShapeFlags.COMPONENT ||
988-
oldVNode.shapeFlag & ShapeFlags.TELEPORT)
987+
oldVNode.shapeFlag & (ShapeFlags.COMPONENT | ShapeFlags.TELEPORT))
989988
? hostParentNode(oldVNode.el)!
990989
: // In other cases, the parent container is not actually used so we
991990
// just pass the block element here to avoid a DOM parentNode call.
@@ -2129,8 +2128,8 @@ function baseCreateRenderer(
21292128
)
21302129
} else if (
21312130
(type === Fragment &&
2132-
(patchFlag & PatchFlags.KEYED_FRAGMENT ||
2133-
patchFlag & PatchFlags.UNKEYED_FRAGMENT)) ||
2131+
patchFlag &
2132+
(PatchFlags.KEYED_FRAGMENT | PatchFlags.UNKEYED_FRAGMENT)) ||
21342133
(!optimized && shapeFlag & ShapeFlags.ARRAY_CHILDREN)
21352134
) {
21362135
unmountChildren(children as VNode[], parentComponent, parentSuspense)

packages/runtime-core/src/vnode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ export function normalizeChildren(vnode: VNode, children: unknown) {
730730
} else if (isArray(children)) {
731731
type = ShapeFlags.ARRAY_CHILDREN
732732
} else if (typeof children === 'object') {
733-
if (shapeFlag & ShapeFlags.ELEMENT || shapeFlag & ShapeFlags.TELEPORT) {
733+
if (shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.TELEPORT)) {
734734
// Normalize slot to plain children for plain element and Teleport
735735
const slot = (children as any).default
736736
if (slot) {

0 commit comments

Comments
 (0)