1
- // Patch flags are optimization hints generated by the compiler.
2
- // when a block with dynamicChildren is encountered during diff, the algorithm
3
- // enters "optimized mode". In this mode, we know that the vdom is produced by
4
- // a render function generated by the compiler, so the algorithm only needs to
5
- // handle updates explicitly marked by these patch flags.
6
-
7
- // Patch flags can be combined using the | bitwise operator and can be checked
8
- // using the & operator, e.g.
9
- //
10
- // const flag = TEXT | CLASS
11
- // if (flag & TEXT) { ... }
12
- //
13
- // Check the `patchElement` function in './renderer.ts' to see how the
14
- // flags are handled during diff.
15
-
1
+ /**
2
+ * Patch flags are optimization hints generated by the compiler.
3
+ * when a block with dynamicChildren is encountered during diff, the algorithm
4
+ * enters "optimized mode". In this mode, we know that the vdom is produced by
5
+ * a render function generated by the compiler, so the algorithm only needs to
6
+ * handle updates explicitly marked by these patch flags.
7
+ *
8
+ * Patch flags can be combined using the | bitwise operator and can be checked
9
+ * using the & operator, e.g.
10
+ *
11
+ * ```js
12
+ * const flag = TEXT | CLASS
13
+ * if (flag & TEXT) { ... }
14
+ * ```
15
+ *
16
+ * Check the `patchElement` function in './renderer.ts' to see how the
17
+ * flags are handled during diff.
18
+ */
16
19
export const enum PatchFlags {
17
- // Indicates an element with dynamic textContent (children fast path)
20
+ /**
21
+ * Indicates an element with dynamic textContent (children fast path)
22
+ */
18
23
TEXT = 1 ,
19
24
20
- // Indicates an element with dynamic class binding.
25
+ /**
26
+ * Indicates an element with dynamic class binding.
27
+ */
21
28
CLASS = 1 << 1 ,
22
29
23
- // Indicates an element with dynamic style
24
- // The compiler pre-compiles static string styles into static objects
25
- // + detects and hoists inline static objects
26
- // e.g. style="color: red" and :style="{ color: 'red' }" both get hoisted as
27
- // const style = { color: 'red' }
28
- // render() { return e('div', { style }) }
30
+ /**
31
+ * Indicates an element with dynamic style
32
+ * The compiler pre-compiles static string styles into static objects
33
+ * + detects and hoists inline static objects
34
+ * e.g. style="color: red" and :style="{ color: 'red' }" both get hoisted as
35
+ * const style = { color: 'red' }
36
+ * render() { return e('div', { style }) }
37
+ */
29
38
STYLE = 1 << 2 ,
30
39
31
- // Indicates an element that has non-class/style dynamic props.
32
- // Can also be on a component that has any dynamic props (includes
33
- // class/style). when this flag is present, the vnode also has a dynamicProps
34
- // array that contains the keys of the props that may change so the runtime
35
- // can diff them faster (without having to worry about removed props)
40
+ /**
41
+ * Indicates an element that has non-class/style dynamic props.
42
+ * Can also be on a component that has any dynamic props (includes
43
+ * class/style). when this flag is present, the vnode also has a dynamicProps
44
+ * array that contains the keys of the props that may change so the runtime
45
+ * can diff them faster (without having to worry about removed props)
46
+ */
36
47
PROPS = 1 << 3 ,
37
48
38
- // Indicates an element with props with dynamic keys. When keys change, a full
39
- // diff is always needed to remove the old key. This flag is mutually
40
- // exclusive with CLASS, STYLE and PROPS.
49
+ /**
50
+ * Indicates an element with props with dynamic keys. When keys change, a full
51
+ * diff is always needed to remove the old key. This flag is mutually
52
+ * exclusive with CLASS, STYLE and PROPS.
53
+ */
41
54
FULL_PROPS = 1 << 4 ,
42
55
43
- // Indicates an element with event listeners (which need to be attached
44
- // during hydration)
56
+ /**
57
+ * Indicates an element with event listeners (which need to be attached
58
+ * during hydration)
59
+ */
45
60
HYDRATE_EVENTS = 1 << 5 ,
46
61
47
- // Indicates a fragment whose children order doesn't change.
62
+ /**
63
+ * Indicates a fragment whose children order doesn't change.
64
+ */
48
65
STABLE_FRAGMENT = 1 << 6 ,
49
66
50
- // Indicates a fragment with keyed or partially keyed children
67
+ /**
68
+ * Indicates a fragment with keyed or partially keyed children
69
+ */
51
70
KEYED_FRAGMENT = 1 << 7 ,
52
71
53
- // Indicates a fragment with unkeyed children.
72
+ /**
73
+ * Indicates a fragment with unkeyed children.
74
+ */
54
75
UNKEYED_FRAGMENT = 1 << 8 ,
55
76
56
- // Indicates an element that only needs non-props patching, e.g. ref or
57
- // directives (onVnodeXXX hooks). since every patched vnode checks for refs
58
- // and onVnodeXXX hooks, it simply marks the vnode so that a parent block
59
- // will track it.
77
+ /**
78
+ * Indicates an element that only needs non-props patching, e.g. ref or
79
+ * directives (onVnodeXXX hooks). since every patched vnode checks for refs
80
+ * and onVnodeXXX hooks, it simply marks the vnode so that a parent block
81
+ * will track it.
82
+ */
60
83
NEED_PATCH = 1 << 9 ,
61
84
62
- // Indicates a component with dynamic slots (e.g. slot that references a v-for
63
- // iterated value, or dynamic slot names).
64
- // Components with this flag are always force updated.
85
+ /**
86
+ * Indicates a component with dynamic slots (e.g. slot that references a v-for
87
+ * iterated value, or dynamic slot names).
88
+ * Components with this flag are always force updated.
89
+ */
65
90
DYNAMIC_SLOTS = 1 << 10 ,
66
91
67
- // SPECIAL FLAGS -------------------------------------------------------------
68
-
69
- // Special flags are negative integers. They are never matched against using
70
- // bitwise operators (bitwise matching should only happen in branches where
71
- // patchFlag > 0), and are mutually exclusive. When checking for a special
72
- // flag, simply check patchFlag === FLAG.
73
-
74
- // Indicates a hoisted static vnode. This is a hint for hydration to skip
75
- // the entire sub tree since static content never needs to be updated.
92
+ /**
93
+ * Indicates a fragment that was created only because the user has placed
94
+ * comments at the root level of a template. This is a dev-only flag since
95
+ * comments are stripped in production.
96
+ */
97
+ DEV_ROOT_FRAGMENT = 1 << 11 ,
98
+
99
+ /**
100
+ * SPECIAL FLAGS -------------------------------------------------------------
101
+ * Special flags are negative integers. They are never matched against using
102
+ * bitwise operators (bitwise matching should only happen in branches where
103
+ * patchFlag > 0), and are mutually exclusive. When checking for a special
104
+ * flag, simply check patchFlag === FLAG.
105
+ */
106
+
107
+ /**
108
+ * Indicates a hoisted static vnode. This is a hint for hydration to skip
109
+ * the entire sub tree since static content never needs to be updated.
110
+ */
76
111
HOISTED = - 1 ,
77
-
78
- // A special flag that indicates that the diffing algorithm should bail out
79
- // of optimized mode. For example, on block fragments created by renderSlot()
80
- // when encountering non-compiler generated slots (i.e. manually written
81
- // render functions, which should always be fully diffed)
82
- // OR manually cloneVNodes
112
+ /**
113
+ * A special flag that indicates that the diffing algorithm should bail out
114
+ * of optimized mode. For example, on block fragments created by renderSlot()
115
+ * when encountering non-compiler generated slots (i.e. manually written
116
+ * render functions, which should always be fully diffed)
117
+ * OR manually cloneVNodes
118
+ */
83
119
BAIL = - 2
84
120
}
85
121
86
- // dev only flag -> name mapping
122
+ /**
123
+ * dev only flag -> name mapping
124
+ */
87
125
export const PatchFlagNames = {
88
126
[ PatchFlags . TEXT ] : `TEXT` ,
89
127
[ PatchFlags . CLASS ] : `CLASS` ,
@@ -94,8 +132,9 @@ export const PatchFlagNames = {
94
132
[ PatchFlags . STABLE_FRAGMENT ] : `STABLE_FRAGMENT` ,
95
133
[ PatchFlags . KEYED_FRAGMENT ] : `KEYED_FRAGMENT` ,
96
134
[ PatchFlags . UNKEYED_FRAGMENT ] : `UNKEYED_FRAGMENT` ,
97
- [ PatchFlags . DYNAMIC_SLOTS ] : `DYNAMIC_SLOTS` ,
98
135
[ PatchFlags . NEED_PATCH ] : `NEED_PATCH` ,
136
+ [ PatchFlags . DYNAMIC_SLOTS ] : `DYNAMIC_SLOTS` ,
137
+ [ PatchFlags . DEV_ROOT_FRAGMENT ] : `DEV_ROOT_FRAGMENT` ,
99
138
[ PatchFlags . HOISTED ] : `HOISTED` ,
100
139
[ PatchFlags . BAIL ] : `BAIL`
101
140
}
0 commit comments