@nest-vue/vue-security-patched 2.7.16-patch.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -0
  3. package/compiler-sfc/index.d.ts +1 -0
  4. package/compiler-sfc/index.js +1 -0
  5. package/compiler-sfc/index.mjs +1 -0
  6. package/compiler-sfc/package.json +5 -0
  7. package/dist/vue.common.js +5 -0
  8. package/dist/vue.runtime.common.js +5 -0
  9. package/dist/vue.runtime.mjs +76 -0
  10. package/package.json +136 -0
  11. package/packages/compiler-sfc/api-extractor.json +64 -0
  12. package/packages/compiler-sfc/dist/compiler-sfc.js +17146 -0
  13. package/packages/compiler-sfc/node_modules/.bin/lessc +17 -0
  14. package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
  15. package/packages/compiler-sfc/node_modules/.bin/prettier +17 -0
  16. package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
  17. package/packages/compiler-sfc/node_modules/.bin/stylus +17 -0
  18. package/packages/compiler-sfc/package.json +37 -0
  19. package/packages/compiler-sfc/src/babelUtils.ts +423 -0
  20. package/packages/compiler-sfc/src/compileScript.ts +1916 -0
  21. package/packages/compiler-sfc/src/compileStyle.ts +147 -0
  22. package/packages/compiler-sfc/src/compileTemplate.ts +205 -0
  23. package/packages/compiler-sfc/src/cssVars.ts +179 -0
  24. package/packages/compiler-sfc/src/index.ts +31 -0
  25. package/packages/compiler-sfc/src/parse.ts +129 -0
  26. package/packages/compiler-sfc/src/parseComponent.ts +220 -0
  27. package/packages/compiler-sfc/src/prefixIdentifiers.ts +82 -0
  28. package/packages/compiler-sfc/src/rewriteDefault.ts +121 -0
  29. package/packages/compiler-sfc/src/stylePlugins/scoped.ts +203 -0
  30. package/packages/compiler-sfc/src/stylePlugins/trim.ts +18 -0
  31. package/packages/compiler-sfc/src/stylePreprocessors.ts +135 -0
  32. package/packages/compiler-sfc/src/templateCompilerModules/assetUrl.ts +84 -0
  33. package/packages/compiler-sfc/src/templateCompilerModules/srcset.ts +76 -0
  34. package/packages/compiler-sfc/src/templateCompilerModules/utils.ts +86 -0
  35. package/packages/compiler-sfc/src/types.ts +69 -0
  36. package/packages/compiler-sfc/src/warn.ts +16 -0
  37. package/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap +971 -0
  38. package/packages/compiler-sfc/test/__snapshots__/cssVars.spec.ts.snap +189 -0
  39. package/packages/compiler-sfc/test/compileScript.spec.ts +1635 -0
  40. package/packages/compiler-sfc/test/compileStyle.spec.ts +203 -0
  41. package/packages/compiler-sfc/test/compileTemplate.spec.ts +258 -0
  42. package/packages/compiler-sfc/test/cssVars.spec.ts +247 -0
  43. package/packages/compiler-sfc/test/parseComponent.spec.ts +269 -0
  44. package/packages/compiler-sfc/test/prefixIdentifiers.spec.ts +97 -0
  45. package/packages/compiler-sfc/test/rewriteDefault.spec.ts +311 -0
  46. package/packages/compiler-sfc/test/stylePluginScoped.spec.ts +137 -0
  47. package/packages/compiler-sfc/test/tsconfig.json +7 -0
  48. package/packages/compiler-sfc/test/util.ts +35 -0
  49. package/src/compiler/codeframe.ts +52 -0
  50. package/src/compiler/codegen/events.ts +170 -0
  51. package/src/compiler/codegen/index.ts +668 -0
  52. package/src/compiler/create-compiler.ts +83 -0
  53. package/src/compiler/directives/bind.ts +9 -0
  54. package/src/compiler/directives/index.ts +9 -0
  55. package/src/compiler/directives/model.ts +145 -0
  56. package/src/compiler/directives/on.ts +9 -0
  57. package/src/compiler/error-detector.ts +158 -0
  58. package/src/compiler/helpers.ts +243 -0
  59. package/src/compiler/index.ts +24 -0
  60. package/src/compiler/optimizer.ts +135 -0
  61. package/src/compiler/parser/entity-decoder.ts +9 -0
  62. package/src/compiler/parser/filter-parser.ts +116 -0
  63. package/src/compiler/parser/html-parser.ts +345 -0
  64. package/src/compiler/parser/index.ts +999 -0
  65. package/src/compiler/parser/text-parser.ts +52 -0
  66. package/src/compiler/to-function.ts +119 -0
  67. package/src/core/components/index.ts +5 -0
  68. package/src/core/components/keep-alive.ts +171 -0
  69. package/src/core/config.ts +128 -0
  70. package/src/core/global-api/assets.ts +35 -0
  71. package/src/core/global-api/extend.ts +94 -0
  72. package/src/core/global-api/index.ts +68 -0
  73. package/src/core/global-api/mixin.ts +9 -0
  74. package/src/core/global-api/use.ts +23 -0
  75. package/src/core/index.ts +27 -0
  76. package/src/core/instance/events.ts +160 -0
  77. package/src/core/instance/index.ts +27 -0
  78. package/src/core/instance/init.ts +143 -0
  79. package/src/core/instance/inject.ts +80 -0
  80. package/src/core/instance/lifecycle.ts +421 -0
  81. package/src/core/instance/proxy.ts +97 -0
  82. package/src/core/instance/render-helpers/bind-dynamic-keys.ts +36 -0
  83. package/src/core/instance/render-helpers/bind-object-listeners.ts +18 -0
  84. package/src/core/instance/render-helpers/bind-object-props.ts +59 -0
  85. package/src/core/instance/render-helpers/check-keycodes.ts +33 -0
  86. package/src/core/instance/render-helpers/index.ts +31 -0
  87. package/src/core/instance/render-helpers/render-list.ts +49 -0
  88. package/src/core/instance/render-helpers/render-slot.ts +39 -0
  89. package/src/core/instance/render-helpers/render-static.ts +57 -0
  90. package/src/core/instance/render-helpers/resolve-filter.ts +8 -0
  91. package/src/core/instance/render-helpers/resolve-scoped-slots.ts +30 -0
  92. package/src/core/instance/render-helpers/resolve-slots.ts +51 -0
  93. package/src/core/instance/render.ts +172 -0
  94. package/src/core/instance/state.ts +393 -0
  95. package/src/core/observer/array.ts +54 -0
  96. package/src/core/observer/dep.ts +108 -0
  97. package/src/core/observer/index.ts +339 -0
  98. package/src/core/observer/scheduler.ts +199 -0
  99. package/src/core/observer/traverse.ts +47 -0
  100. package/src/core/observer/watcher.ts +278 -0
  101. package/src/core/util/debug.ts +105 -0
  102. package/src/core/util/env.ts +93 -0
  103. package/src/core/util/error.ts +81 -0
  104. package/src/core/util/index.ts +9 -0
  105. package/src/core/util/lang.ts +45 -0
  106. package/src/core/util/next-tick.ts +117 -0
  107. package/src/core/util/options.ts +489 -0
  108. package/src/core/util/perf.ts +28 -0
  109. package/src/core/util/props.ts +254 -0
  110. package/src/core/vdom/create-component.ts +275 -0
  111. package/src/core/vdom/create-element.ts +172 -0
  112. package/src/core/vdom/create-functional-component.ts +180 -0
  113. package/src/core/vdom/helpers/extract-props.ts +75 -0
  114. package/src/core/vdom/helpers/get-first-component-child.ts +16 -0
  115. package/src/core/vdom/helpers/index.ts +7 -0
  116. package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
  117. package/src/core/vdom/helpers/merge-hook.ts +40 -0
  118. package/src/core/vdom/helpers/normalize-children.ts +99 -0
  119. package/src/core/vdom/helpers/normalize-scoped-slots.ts +97 -0
  120. package/src/core/vdom/helpers/resolve-async-component.ts +157 -0
  121. package/src/core/vdom/helpers/update-listeners.ts +101 -0
  122. package/src/core/vdom/modules/directives.ts +137 -0
  123. package/src/core/vdom/modules/index.ts +4 -0
  124. package/src/core/vdom/modules/template-ref.ts +94 -0
  125. package/src/core/vdom/patch.ts +907 -0
  126. package/src/core/vdom/vnode.ts +119 -0
  127. package/src/global.d.ts +17 -0
  128. package/src/platforms/web/compiler/directives/html.ts +8 -0
  129. package/src/platforms/web/compiler/directives/index.ts +9 -0
  130. package/src/platforms/web/compiler/directives/model.ts +181 -0
  131. package/src/platforms/web/compiler/directives/text.ts +8 -0
  132. package/src/platforms/web/compiler/index.ts +6 -0
  133. package/src/platforms/web/compiler/modules/class.ts +44 -0
  134. package/src/platforms/web/compiler/modules/index.ts +5 -0
  135. package/src/platforms/web/compiler/modules/model.ts +89 -0
  136. package/src/platforms/web/compiler/modules/style.ts +47 -0
  137. package/src/platforms/web/compiler/options.ts +25 -0
  138. package/src/platforms/web/compiler/util.ts +22 -0
  139. package/src/platforms/web/entry-compiler.ts +4 -0
  140. package/src/platforms/web/entry-runtime-esm.ts +5 -0
  141. package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
  142. package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
  143. package/src/platforms/web/entry-runtime.ts +7 -0
  144. package/src/platforms/web/runtime/class-util.ts +61 -0
  145. package/src/platforms/web/runtime/components/index.ts +7 -0
  146. package/src/platforms/web/runtime/components/transition-group.ts +204 -0
  147. package/src/platforms/web/runtime/components/transition.ts +205 -0
  148. package/src/platforms/web/runtime/directives/index.ts +7 -0
  149. package/src/platforms/web/runtime/directives/model.ts +148 -0
  150. package/src/platforms/web/runtime/directives/show.ts +61 -0
  151. package/src/platforms/web/runtime/index.ts +75 -0
  152. package/src/platforms/web/runtime/modules/attrs.ts +115 -0
  153. package/src/platforms/web/runtime/modules/class.ts +37 -0
  154. package/src/platforms/web/runtime/modules/dom-props.ts +123 -0
  155. package/src/platforms/web/runtime/modules/events.ts +127 -0
  156. package/src/platforms/web/runtime/modules/index.ts +8 -0
  157. package/src/platforms/web/runtime/modules/style.ts +102 -0
  158. package/src/platforms/web/runtime/modules/transition.ts +341 -0
  159. package/src/platforms/web/runtime/node-ops.ts +66 -0
  160. package/src/platforms/web/runtime/patch.ts +10 -0
  161. package/src/platforms/web/runtime/transition-util.ts +215 -0
  162. package/src/platforms/web/runtime-with-compiler.ts +110 -0
  163. package/src/platforms/web/util/attrs.ts +58 -0
  164. package/src/platforms/web/util/class.ts +87 -0
  165. package/src/platforms/web/util/compat.ts +16 -0
  166. package/src/platforms/web/util/element.ts +76 -0
  167. package/src/platforms/web/util/index.ts +21 -0
  168. package/src/platforms/web/util/style.ts +71 -0
  169. package/src/shared/constants.ts +20 -0
  170. package/src/shared/util.ts +378 -0
  171. package/src/types/compiler.ts +207 -0
  172. package/src/types/component.ts +212 -0
  173. package/src/types/global-api.ts +37 -0
  174. package/src/types/modules.d.ts +15 -0
  175. package/src/types/options.ts +114 -0
  176. package/src/types/ssr.ts +27 -0
  177. package/src/types/utils.ts +3 -0
  178. package/src/types/vnode.ts +127 -0
  179. package/src/v3/apiAsyncComponent.ts +117 -0
  180. package/src/v3/apiInject.ts +71 -0
  181. package/src/v3/apiLifecycle.ts +68 -0
  182. package/src/v3/apiSetup.ts +246 -0
  183. package/src/v3/apiWatch.ts +353 -0
  184. package/src/v3/currentInstance.ts +23 -0
  185. package/src/v3/debug.ts +21 -0
  186. package/src/v3/h.ts +18 -0
  187. package/src/v3/index.ts +96 -0
  188. package/src/v3/reactivity/computed.ts +100 -0
  189. package/src/v3/reactivity/effect.ts +20 -0
  190. package/src/v3/reactivity/effectScope.ts +137 -0
  191. package/src/v3/reactivity/operations.ts +14 -0
  192. package/src/v3/reactivity/reactive.ts +137 -0
  193. package/src/v3/reactivity/readonly.ts +127 -0
  194. package/src/v3/reactivity/ref.ts +293 -0
  195. package/src/v3/sfc-helpers/useCssModule.ts +24 -0
  196. package/src/v3/sfc-helpers/useCssVars.ts +34 -0
  197. package/types/built-in-components.d.ts +63 -0
  198. package/types/common.d.ts +21 -0
  199. package/types/index.d.ts +81 -0
  200. package/types/jsx.d.ts +1353 -0
  201. package/types/options.d.ts +349 -0
  202. package/types/plugin.d.ts +8 -0
  203. package/types/umd.d.ts +68 -0
  204. package/types/v3-component-options.d.ts +252 -0
  205. package/types/v3-component-props.d.ts +99 -0
  206. package/types/v3-component-public-instance.d.ts +232 -0
  207. package/types/v3-define-async-component.d.ts +26 -0
  208. package/types/v3-define-component.d.ts +201 -0
  209. package/types/v3-directive.d.ts +29 -0
  210. package/types/v3-manual-apis.d.ts +10 -0
  211. package/types/v3-setup-context.d.ts +41 -0
  212. package/types/v3-setup-helpers.d.ts +154 -0
  213. package/types/vnode.d.ts +117 -0
  214. package/types/vue.d.ts +446 -0
@@ -0,0 +1,137 @@
1
+ import Watcher from 'core/observer/watcher'
2
+ import { warn } from 'core/util'
3
+
4
+ export let activeEffectScope: EffectScope | undefined
5
+
6
+ export class EffectScope {
7
+ /**
8
+ * @internal
9
+ */
10
+ active = true
11
+ /**
12
+ * @internal
13
+ */
14
+ effects: Watcher[] = []
15
+ /**
16
+ * @internal
17
+ */
18
+ cleanups: (() => void)[] = []
19
+ /**
20
+ * @internal
21
+ */
22
+ parent: EffectScope | undefined
23
+ /**
24
+ * record undetached scopes
25
+ * @internal
26
+ */
27
+ scopes: EffectScope[] | undefined
28
+ /**
29
+ * indicates this being a component root scope
30
+ * @internal
31
+ */
32
+ _vm?: boolean
33
+ /**
34
+ * track a child scope's index in its parent's scopes array for optimized
35
+ * removal
36
+ */
37
+ private index: number | undefined
38
+
39
+ constructor(public detached = false) {
40
+ this.parent = activeEffectScope
41
+ if (!detached && activeEffectScope) {
42
+ this.index =
43
+ (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
44
+ this
45
+ ) - 1
46
+ }
47
+ }
48
+
49
+ run<T>(fn: () => T): T | undefined {
50
+ if (this.active) {
51
+ const currentEffectScope = activeEffectScope
52
+ try {
53
+ activeEffectScope = this
54
+ return fn()
55
+ } finally {
56
+ activeEffectScope = currentEffectScope
57
+ }
58
+ } else if (__DEV__) {
59
+ warn(`cannot run an inactive effect scope.`)
60
+ }
61
+ }
62
+
63
+ /**
64
+ * This should only be called on non-detached scopes
65
+ * @internal
66
+ */
67
+ on() {
68
+ activeEffectScope = this
69
+ }
70
+
71
+ /**
72
+ * This should only be called on non-detached scopes
73
+ * @internal
74
+ */
75
+ off() {
76
+ activeEffectScope = this.parent
77
+ }
78
+
79
+ stop(fromParent?: boolean) {
80
+ if (this.active) {
81
+ let i, l
82
+ for (i = 0, l = this.effects.length; i < l; i++) {
83
+ this.effects[i].teardown()
84
+ }
85
+ for (i = 0, l = this.cleanups.length; i < l; i++) {
86
+ this.cleanups[i]()
87
+ }
88
+ if (this.scopes) {
89
+ for (i = 0, l = this.scopes.length; i < l; i++) {
90
+ this.scopes[i].stop(true)
91
+ }
92
+ }
93
+ // nested scope, dereference from parent to avoid memory leaks
94
+ if (!this.detached && this.parent && !fromParent) {
95
+ // optimized O(1) removal
96
+ const last = this.parent.scopes!.pop()
97
+ if (last && last !== this) {
98
+ this.parent.scopes![this.index!] = last
99
+ last.index = this.index!
100
+ }
101
+ }
102
+ this.parent = undefined
103
+ this.active = false
104
+ }
105
+ }
106
+ }
107
+
108
+ export function effectScope(detached?: boolean) {
109
+ return new EffectScope(detached)
110
+ }
111
+
112
+ /**
113
+ * @internal
114
+ */
115
+ export function recordEffectScope(
116
+ effect: Watcher,
117
+ scope: EffectScope | undefined = activeEffectScope
118
+ ) {
119
+ if (scope && scope.active) {
120
+ scope.effects.push(effect)
121
+ }
122
+ }
123
+
124
+ export function getCurrentScope() {
125
+ return activeEffectScope
126
+ }
127
+
128
+ export function onScopeDispose(fn: () => void) {
129
+ if (activeEffectScope) {
130
+ activeEffectScope.cleanups.push(fn)
131
+ } else if (__DEV__) {
132
+ warn(
133
+ `onScopeDispose() is called when there is no active effect scope` +
134
+ ` to be associated with.`
135
+ )
136
+ }
137
+ }
@@ -0,0 +1,14 @@
1
+ // using literal strings instead of numbers so that it's easier to inspect
2
+ // debugger events
3
+
4
+ export const enum TrackOpTypes {
5
+ GET = 'get',
6
+ TOUCH = 'touch'
7
+ }
8
+
9
+ export const enum TriggerOpTypes {
10
+ SET = 'set',
11
+ ADD = 'add',
12
+ DELETE = 'delete',
13
+ ARRAY_MUTATION = 'array mutation'
14
+ }
@@ -0,0 +1,137 @@
1
+ import { observe, Observer } from 'core/observer'
2
+ import {
3
+ def,
4
+ isArray,
5
+ isPrimitive,
6
+ warn,
7
+ toRawType,
8
+ isServerRendering
9
+ } from 'core/util'
10
+ import type { Ref, UnwrapRefSimple, RawSymbol } from './ref'
11
+
12
+ export const enum ReactiveFlags {
13
+ SKIP = '__v_skip',
14
+ IS_READONLY = '__v_isReadonly',
15
+ IS_SHALLOW = '__v_isShallow',
16
+ RAW = '__v_raw'
17
+ }
18
+
19
+ export interface Target {
20
+ __ob__?: Observer
21
+ [ReactiveFlags.SKIP]?: boolean
22
+ [ReactiveFlags.IS_READONLY]?: boolean
23
+ [ReactiveFlags.IS_SHALLOW]?: boolean
24
+ [ReactiveFlags.RAW]?: any
25
+ }
26
+
27
+ // only unwrap nested ref
28
+ export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>
29
+
30
+ export function reactive<T extends object>(target: T): UnwrapNestedRefs<T>
31
+ export function reactive(target: object) {
32
+ makeReactive(target, false)
33
+ return target
34
+ }
35
+
36
+ export declare const ShallowReactiveMarker: unique symbol
37
+
38
+ export type ShallowReactive<T> = T & { [ShallowReactiveMarker]?: true }
39
+
40
+ /**
41
+ * Return a shallowly-reactive copy of the original object, where only the root
42
+ * level properties are reactive. It also does not auto-unwrap refs (even at the
43
+ * root level).
44
+ */
45
+ export function shallowReactive<T extends object>(
46
+ target: T
47
+ ): ShallowReactive<T> {
48
+ makeReactive(target, true)
49
+ def(target, ReactiveFlags.IS_SHALLOW, true)
50
+ return target
51
+ }
52
+
53
+ function makeReactive(target: any, shallow: boolean) {
54
+ // if trying to observe a readonly proxy, return the readonly version.
55
+ if (!isReadonly(target)) {
56
+ if (__DEV__) {
57
+ if (isArray(target)) {
58
+ warn(
59
+ `Avoid using Array as root value for ${
60
+ shallow ? `shallowReactive()` : `reactive()`
61
+ } as it cannot be tracked in watch() or watchEffect(). Use ${
62
+ shallow ? `shallowRef()` : `ref()`
63
+ } instead. This is a Vue-2-only limitation.`
64
+ )
65
+ }
66
+ const existingOb = target && target.__ob__
67
+ if (existingOb && existingOb.shallow !== shallow) {
68
+ warn(
69
+ `Target is already a ${
70
+ existingOb.shallow ? `` : `non-`
71
+ }shallow reactive object, and cannot be converted to ${
72
+ shallow ? `` : `non-`
73
+ }shallow.`
74
+ )
75
+ }
76
+ }
77
+ const ob = observe(
78
+ target,
79
+ shallow,
80
+ isServerRendering() /* ssr mock reactivity */
81
+ )
82
+ if (__DEV__ && !ob) {
83
+ if (target == null || isPrimitive(target)) {
84
+ warn(`value cannot be made reactive: ${String(target)}`)
85
+ }
86
+ if (isCollectionType(target)) {
87
+ warn(
88
+ `Vue 2 does not support reactive collection types such as Map or Set.`
89
+ )
90
+ }
91
+ }
92
+ }
93
+ }
94
+
95
+ export function isReactive(value: unknown): boolean {
96
+ if (isReadonly(value)) {
97
+ return isReactive((value as Target)[ReactiveFlags.RAW])
98
+ }
99
+ return !!(value && (value as Target).__ob__)
100
+ }
101
+
102
+ export function isShallow(value: unknown): boolean {
103
+ return !!(value && (value as Target).__v_isShallow)
104
+ }
105
+
106
+ export function isReadonly(value: unknown): boolean {
107
+ return !!(value && (value as Target).__v_isReadonly)
108
+ }
109
+
110
+ export function isProxy(value: unknown): boolean {
111
+ return isReactive(value) || isReadonly(value)
112
+ }
113
+
114
+ export function toRaw<T>(observed: T): T {
115
+ const raw = observed && (observed as Target)[ReactiveFlags.RAW]
116
+ return raw ? toRaw(raw) : observed
117
+ }
118
+
119
+ export function markRaw<T extends object>(
120
+ value: T
121
+ ): T & { [RawSymbol]?: true } {
122
+ // non-extensible objects won't be observed anyway
123
+ if (Object.isExtensible(value)) {
124
+ def(value, ReactiveFlags.SKIP, true)
125
+ }
126
+ return value
127
+ }
128
+
129
+ /**
130
+ * @internal
131
+ */
132
+ export function isCollectionType(value: unknown): boolean {
133
+ const type = toRawType(value)
134
+ return (
135
+ type === 'Map' || type === 'WeakMap' || type === 'Set' || type === 'WeakSet'
136
+ )
137
+ }
@@ -0,0 +1,127 @@
1
+ import { def, warn, isPlainObject, isArray } from 'core/util'
2
+ import {
3
+ isCollectionType,
4
+ isReadonly,
5
+ isShallow,
6
+ ReactiveFlags,
7
+ UnwrapNestedRefs
8
+ } from './reactive'
9
+ import { isRef, Ref, RefFlag } from './ref'
10
+
11
+ type Primitive = string | number | boolean | bigint | symbol | undefined | null
12
+ type Builtin = Primitive | Function | Date | Error | RegExp
13
+ export type DeepReadonly<T> = T extends Builtin
14
+ ? T
15
+ : T extends Map<infer K, infer V>
16
+ ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
17
+ : T extends ReadonlyMap<infer K, infer V>
18
+ ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
19
+ : T extends WeakMap<infer K, infer V>
20
+ ? WeakMap<DeepReadonly<K>, DeepReadonly<V>>
21
+ : T extends Set<infer U>
22
+ ? ReadonlySet<DeepReadonly<U>>
23
+ : T extends ReadonlySet<infer U>
24
+ ? ReadonlySet<DeepReadonly<U>>
25
+ : T extends WeakSet<infer U>
26
+ ? WeakSet<DeepReadonly<U>>
27
+ : T extends Promise<infer U>
28
+ ? Promise<DeepReadonly<U>>
29
+ : T extends Ref<infer U>
30
+ ? Readonly<Ref<DeepReadonly<U>>>
31
+ : T extends {}
32
+ ? { readonly [K in keyof T]: DeepReadonly<T[K]> }
33
+ : Readonly<T>
34
+
35
+ const rawToReadonlyFlag = `__v_rawToReadonly`
36
+ const rawToShallowReadonlyFlag = `__v_rawToShallowReadonly`
37
+
38
+ export function readonly<T extends object>(
39
+ target: T
40
+ ): DeepReadonly<UnwrapNestedRefs<T>> {
41
+ return createReadonly(target, false)
42
+ }
43
+
44
+ function createReadonly(target: any, shallow: boolean) {
45
+ if (!isPlainObject(target)) {
46
+ if (__DEV__) {
47
+ if (isArray(target)) {
48
+ warn(`Vue 2 does not support readonly arrays.`)
49
+ } else if (isCollectionType(target)) {
50
+ warn(
51
+ `Vue 2 does not support readonly collection types such as Map or Set.`
52
+ )
53
+ } else {
54
+ warn(`value cannot be made readonly: ${typeof target}`)
55
+ }
56
+ }
57
+ return target as any
58
+ }
59
+
60
+ if (__DEV__ && !Object.isExtensible(target)) {
61
+ warn(
62
+ `Vue 2 does not support creating readonly proxy for non-extensible object.`
63
+ )
64
+ }
65
+
66
+ // already a readonly object
67
+ if (isReadonly(target)) {
68
+ return target as any
69
+ }
70
+
71
+ // already has a readonly proxy
72
+ const existingFlag = shallow ? rawToShallowReadonlyFlag : rawToReadonlyFlag
73
+ const existingProxy = target[existingFlag]
74
+ if (existingProxy) {
75
+ return existingProxy
76
+ }
77
+
78
+ const proxy = Object.create(Object.getPrototypeOf(target))
79
+ def(target, existingFlag, proxy)
80
+
81
+ def(proxy, ReactiveFlags.IS_READONLY, true)
82
+ def(proxy, ReactiveFlags.RAW, target)
83
+
84
+ if (isRef(target)) {
85
+ def(proxy, RefFlag, true)
86
+ }
87
+ if (shallow || isShallow(target)) {
88
+ def(proxy, ReactiveFlags.IS_SHALLOW, true)
89
+ }
90
+
91
+ const keys = Object.keys(target)
92
+ for (let i = 0; i < keys.length; i++) {
93
+ defineReadonlyProperty(proxy, target, keys[i], shallow)
94
+ }
95
+
96
+ return proxy as any
97
+ }
98
+
99
+ function defineReadonlyProperty(
100
+ proxy: any,
101
+ target: any,
102
+ key: string,
103
+ shallow: boolean
104
+ ) {
105
+ Object.defineProperty(proxy, key, {
106
+ enumerable: true,
107
+ configurable: true,
108
+ get() {
109
+ const val = target[key]
110
+ return shallow || !isPlainObject(val) ? val : readonly(val)
111
+ },
112
+ set() {
113
+ __DEV__ &&
114
+ warn(`Set operation on key "${key}" failed: target is readonly.`)
115
+ }
116
+ })
117
+ }
118
+
119
+ /**
120
+ * Returns a reactive-copy of the original object, where only the root level
121
+ * properties are readonly, and does NOT unwrap refs nor recursively convert
122
+ * returned properties.
123
+ * This is used for creating the props proxy object for stateful components.
124
+ */
125
+ export function shallowReadonly<T extends object>(target: T): Readonly<T> {
126
+ return createReadonly(target, true)
127
+ }
@@ -0,0 +1,293 @@
1
+ import { defineReactive } from 'core/observer/index'
2
+ import {
3
+ isReactive,
4
+ ReactiveFlags,
5
+ type ShallowReactiveMarker
6
+ } from './reactive'
7
+ import type { IfAny } from 'types/utils'
8
+ import Dep from 'core/observer/dep'
9
+ import { warn, isArray, def, isServerRendering } from 'core/util'
10
+ import { TrackOpTypes, TriggerOpTypes } from './operations'
11
+
12
+ declare const RefSymbol: unique symbol
13
+ export declare const RawSymbol: unique symbol
14
+
15
+ /**
16
+ * @internal
17
+ */
18
+ export const RefFlag = `__v_isRef`
19
+
20
+ export interface Ref<T = any> {
21
+ value: T
22
+ /**
23
+ * Type differentiator only.
24
+ * We need this to be in public d.ts but don't want it to show up in IDE
25
+ * autocomplete, so we use a private Symbol instead.
26
+ */
27
+ [RefSymbol]: true
28
+ /**
29
+ * @internal
30
+ */
31
+ dep?: Dep
32
+ /**
33
+ * @internal
34
+ */
35
+ [RefFlag]: true
36
+ }
37
+
38
+ export function isRef<T>(r: Ref<T> | unknown): r is Ref<T>
39
+ export function isRef(r: any): r is Ref {
40
+ return !!(r && (r as Ref).__v_isRef === true)
41
+ }
42
+
43
+ export function ref<T extends Ref>(value: T): T
44
+ export function ref<T>(value: T): Ref<UnwrapRef<T>>
45
+ export function ref<T = any>(): Ref<T | undefined>
46
+ export function ref(value?: unknown) {
47
+ return createRef(value, false)
48
+ }
49
+
50
+ declare const ShallowRefMarker: unique symbol
51
+
52
+ export type ShallowRef<T = any> = Ref<T> & { [ShallowRefMarker]?: true }
53
+
54
+ export function shallowRef<T>(value: T | Ref<T>): Ref<T> | ShallowRef<T>
55
+ export function shallowRef<T extends Ref>(value: T): T
56
+ export function shallowRef<T>(value: T): ShallowRef<T>
57
+ export function shallowRef<T = any>(): ShallowRef<T | undefined>
58
+ export function shallowRef(value?: unknown) {
59
+ return createRef(value, true)
60
+ }
61
+
62
+ function createRef(rawValue: unknown, shallow: boolean) {
63
+ if (isRef(rawValue)) {
64
+ return rawValue
65
+ }
66
+ const ref: any = {}
67
+ def(ref, RefFlag, true)
68
+ def(ref, ReactiveFlags.IS_SHALLOW, shallow)
69
+ def(
70
+ ref,
71
+ 'dep',
72
+ defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering())
73
+ )
74
+ return ref
75
+ }
76
+
77
+ export function triggerRef(ref: Ref) {
78
+ if (__DEV__ && !ref.dep) {
79
+ warn(`received object is not a triggerable ref.`)
80
+ }
81
+ if (__DEV__) {
82
+ ref.dep &&
83
+ ref.dep.notify({
84
+ type: TriggerOpTypes.SET,
85
+ target: ref,
86
+ key: 'value'
87
+ })
88
+ } else {
89
+ ref.dep && ref.dep.notify()
90
+ }
91
+ }
92
+
93
+ export function unref<T>(ref: T | Ref<T>): T {
94
+ return isRef(ref) ? (ref.value as any) : ref
95
+ }
96
+
97
+ export function proxyRefs<T extends object>(
98
+ objectWithRefs: T
99
+ ): ShallowUnwrapRef<T> {
100
+ if (isReactive(objectWithRefs)) {
101
+ return objectWithRefs as any
102
+ }
103
+ const proxy = {}
104
+ const keys = Object.keys(objectWithRefs)
105
+ for (let i = 0; i < keys.length; i++) {
106
+ proxyWithRefUnwrap(proxy, objectWithRefs, keys[i])
107
+ }
108
+ return proxy as any
109
+ }
110
+
111
+ export function proxyWithRefUnwrap(
112
+ target: any,
113
+ source: Record<string, any>,
114
+ key: string
115
+ ) {
116
+ Object.defineProperty(target, key, {
117
+ enumerable: true,
118
+ configurable: true,
119
+ get: () => {
120
+ const val = source[key]
121
+ if (isRef(val)) {
122
+ return val.value
123
+ } else {
124
+ const ob = val && val.__ob__
125
+ if (ob) ob.dep.depend()
126
+ return val
127
+ }
128
+ },
129
+ set: value => {
130
+ const oldValue = source[key]
131
+ if (isRef(oldValue) && !isRef(value)) {
132
+ oldValue.value = value
133
+ } else {
134
+ source[key] = value
135
+ }
136
+ }
137
+ })
138
+ }
139
+
140
+ export type CustomRefFactory<T> = (
141
+ track: () => void,
142
+ trigger: () => void
143
+ ) => {
144
+ get: () => T
145
+ set: (value: T) => void
146
+ }
147
+
148
+ export function customRef<T>(factory: CustomRefFactory<T>): Ref<T> {
149
+ const dep = new Dep()
150
+ const { get, set } = factory(
151
+ () => {
152
+ if (__DEV__) {
153
+ dep.depend({
154
+ target: ref,
155
+ type: TrackOpTypes.GET,
156
+ key: 'value'
157
+ })
158
+ } else {
159
+ dep.depend()
160
+ }
161
+ },
162
+ () => {
163
+ if (__DEV__) {
164
+ dep.notify({
165
+ target: ref,
166
+ type: TriggerOpTypes.SET,
167
+ key: 'value'
168
+ })
169
+ } else {
170
+ dep.notify()
171
+ }
172
+ }
173
+ )
174
+ const ref = {
175
+ get value() {
176
+ return get()
177
+ },
178
+ set value(newVal) {
179
+ set(newVal)
180
+ }
181
+ } as any
182
+ def(ref, RefFlag, true)
183
+ return ref
184
+ }
185
+
186
+ export type ToRefs<T = any> = {
187
+ [K in keyof T]: ToRef<T[K]>
188
+ }
189
+
190
+ export function toRefs<T extends object>(object: T): ToRefs<T> {
191
+ if (__DEV__ && !isReactive(object)) {
192
+ warn(`toRefs() expects a reactive object but received a plain one.`)
193
+ }
194
+ const ret: any = isArray(object) ? new Array(object.length) : {}
195
+ for (const key in object) {
196
+ ret[key] = toRef(object, key)
197
+ }
198
+ return ret
199
+ }
200
+
201
+ export type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>
202
+
203
+ export function toRef<T extends object, K extends keyof T>(
204
+ object: T,
205
+ key: K
206
+ ): ToRef<T[K]>
207
+
208
+ export function toRef<T extends object, K extends keyof T>(
209
+ object: T,
210
+ key: K,
211
+ defaultValue: T[K]
212
+ ): ToRef<Exclude<T[K], undefined>>
213
+
214
+ export function toRef<T extends object, K extends keyof T>(
215
+ object: T,
216
+ key: K,
217
+ defaultValue?: T[K]
218
+ ): ToRef<T[K]> {
219
+ const val = object[key]
220
+ if (isRef(val)) {
221
+ return val as any
222
+ }
223
+ const ref = {
224
+ get value() {
225
+ const val = object[key]
226
+ return val === undefined ? (defaultValue as T[K]) : val
227
+ },
228
+ set value(newVal) {
229
+ object[key] = newVal
230
+ }
231
+ } as any
232
+ def(ref, RefFlag, true)
233
+ return ref
234
+ }
235
+
236
+ /**
237
+ * This is a special exported interface for other packages to declare
238
+ * additional types that should bail out for ref unwrapping. For example
239
+ * \@vue/runtime-dom can declare it like so in its d.ts:
240
+ *
241
+ * ``` ts
242
+ * declare module 'vue' {
243
+ * export interface RefUnwrapBailTypes {
244
+ * runtimeDOMBailTypes: Node | Window
245
+ * }
246
+ * }
247
+ * ```
248
+ *
249
+ * Note that api-extractor somehow refuses to include `declare module`
250
+ * augmentations in its generated d.ts, so we have to manually append them
251
+ * to the final generated d.ts in our build process.
252
+ */
253
+ export interface RefUnwrapBailTypes {
254
+ runtimeDOMBailTypes: Node | Window
255
+ }
256
+
257
+ export type ShallowUnwrapRef<T> = {
258
+ [K in keyof T]: T[K] extends Ref<infer V>
259
+ ? V
260
+ : // if `V` is `unknown` that means it does not extend `Ref` and is undefined
261
+ T[K] extends Ref<infer V> | undefined
262
+ ? unknown extends V
263
+ ? undefined
264
+ : V | undefined
265
+ : T[K]
266
+ }
267
+
268
+ export type UnwrapRef<T> = T extends ShallowRef<infer V>
269
+ ? V
270
+ : T extends Ref<infer V>
271
+ ? UnwrapRefSimple<V>
272
+ : UnwrapRefSimple<T>
273
+
274
+ type BaseTypes = string | number | boolean
275
+ type CollectionTypes = IterableCollections | WeakCollections
276
+ type IterableCollections = Map<any, any> | Set<any>
277
+ type WeakCollections = WeakMap<any, any> | WeakSet<any>
278
+
279
+ export type UnwrapRefSimple<T> = T extends
280
+ | Function
281
+ | CollectionTypes
282
+ | BaseTypes
283
+ | Ref
284
+ | RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
285
+ | { [RawSymbol]?: true }
286
+ ? T
287
+ : T extends Array<any>
288
+ ? { [K in keyof T]: UnwrapRefSimple<T[K]> }
289
+ : T extends object & { [ShallowReactiveMarker]?: never }
290
+ ? {
291
+ [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>
292
+ }
293
+ : T