@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.
- package/LICENSE +21 -0
- package/README.md +122 -0
- package/compiler-sfc/index.d.ts +1 -0
- package/compiler-sfc/index.js +1 -0
- package/compiler-sfc/index.mjs +1 -0
- package/compiler-sfc/package.json +5 -0
- package/dist/vue.common.js +5 -0
- package/dist/vue.runtime.common.js +5 -0
- package/dist/vue.runtime.mjs +76 -0
- package/package.json +136 -0
- package/packages/compiler-sfc/api-extractor.json +64 -0
- package/packages/compiler-sfc/dist/compiler-sfc.js +17146 -0
- package/packages/compiler-sfc/node_modules/.bin/lessc +17 -0
- package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
- package/packages/compiler-sfc/node_modules/.bin/prettier +17 -0
- package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
- package/packages/compiler-sfc/node_modules/.bin/stylus +17 -0
- package/packages/compiler-sfc/package.json +37 -0
- package/packages/compiler-sfc/src/babelUtils.ts +423 -0
- package/packages/compiler-sfc/src/compileScript.ts +1916 -0
- package/packages/compiler-sfc/src/compileStyle.ts +147 -0
- package/packages/compiler-sfc/src/compileTemplate.ts +205 -0
- package/packages/compiler-sfc/src/cssVars.ts +179 -0
- package/packages/compiler-sfc/src/index.ts +31 -0
- package/packages/compiler-sfc/src/parse.ts +129 -0
- package/packages/compiler-sfc/src/parseComponent.ts +220 -0
- package/packages/compiler-sfc/src/prefixIdentifiers.ts +82 -0
- package/packages/compiler-sfc/src/rewriteDefault.ts +121 -0
- package/packages/compiler-sfc/src/stylePlugins/scoped.ts +203 -0
- package/packages/compiler-sfc/src/stylePlugins/trim.ts +18 -0
- package/packages/compiler-sfc/src/stylePreprocessors.ts +135 -0
- package/packages/compiler-sfc/src/templateCompilerModules/assetUrl.ts +84 -0
- package/packages/compiler-sfc/src/templateCompilerModules/srcset.ts +76 -0
- package/packages/compiler-sfc/src/templateCompilerModules/utils.ts +86 -0
- package/packages/compiler-sfc/src/types.ts +69 -0
- package/packages/compiler-sfc/src/warn.ts +16 -0
- package/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap +971 -0
- package/packages/compiler-sfc/test/__snapshots__/cssVars.spec.ts.snap +189 -0
- package/packages/compiler-sfc/test/compileScript.spec.ts +1635 -0
- package/packages/compiler-sfc/test/compileStyle.spec.ts +203 -0
- package/packages/compiler-sfc/test/compileTemplate.spec.ts +258 -0
- package/packages/compiler-sfc/test/cssVars.spec.ts +247 -0
- package/packages/compiler-sfc/test/parseComponent.spec.ts +269 -0
- package/packages/compiler-sfc/test/prefixIdentifiers.spec.ts +97 -0
- package/packages/compiler-sfc/test/rewriteDefault.spec.ts +311 -0
- package/packages/compiler-sfc/test/stylePluginScoped.spec.ts +137 -0
- package/packages/compiler-sfc/test/tsconfig.json +7 -0
- package/packages/compiler-sfc/test/util.ts +35 -0
- package/src/compiler/codeframe.ts +52 -0
- package/src/compiler/codegen/events.ts +170 -0
- package/src/compiler/codegen/index.ts +668 -0
- package/src/compiler/create-compiler.ts +83 -0
- package/src/compiler/directives/bind.ts +9 -0
- package/src/compiler/directives/index.ts +9 -0
- package/src/compiler/directives/model.ts +145 -0
- package/src/compiler/directives/on.ts +9 -0
- package/src/compiler/error-detector.ts +158 -0
- package/src/compiler/helpers.ts +243 -0
- package/src/compiler/index.ts +24 -0
- package/src/compiler/optimizer.ts +135 -0
- package/src/compiler/parser/entity-decoder.ts +9 -0
- package/src/compiler/parser/filter-parser.ts +116 -0
- package/src/compiler/parser/html-parser.ts +345 -0
- package/src/compiler/parser/index.ts +999 -0
- package/src/compiler/parser/text-parser.ts +52 -0
- package/src/compiler/to-function.ts +119 -0
- package/src/core/components/index.ts +5 -0
- package/src/core/components/keep-alive.ts +171 -0
- package/src/core/config.ts +128 -0
- package/src/core/global-api/assets.ts +35 -0
- package/src/core/global-api/extend.ts +94 -0
- package/src/core/global-api/index.ts +68 -0
- package/src/core/global-api/mixin.ts +9 -0
- package/src/core/global-api/use.ts +23 -0
- package/src/core/index.ts +27 -0
- package/src/core/instance/events.ts +160 -0
- package/src/core/instance/index.ts +27 -0
- package/src/core/instance/init.ts +143 -0
- package/src/core/instance/inject.ts +80 -0
- package/src/core/instance/lifecycle.ts +421 -0
- package/src/core/instance/proxy.ts +97 -0
- package/src/core/instance/render-helpers/bind-dynamic-keys.ts +36 -0
- package/src/core/instance/render-helpers/bind-object-listeners.ts +18 -0
- package/src/core/instance/render-helpers/bind-object-props.ts +59 -0
- package/src/core/instance/render-helpers/check-keycodes.ts +33 -0
- package/src/core/instance/render-helpers/index.ts +31 -0
- package/src/core/instance/render-helpers/render-list.ts +49 -0
- package/src/core/instance/render-helpers/render-slot.ts +39 -0
- package/src/core/instance/render-helpers/render-static.ts +57 -0
- package/src/core/instance/render-helpers/resolve-filter.ts +8 -0
- package/src/core/instance/render-helpers/resolve-scoped-slots.ts +30 -0
- package/src/core/instance/render-helpers/resolve-slots.ts +51 -0
- package/src/core/instance/render.ts +172 -0
- package/src/core/instance/state.ts +393 -0
- package/src/core/observer/array.ts +54 -0
- package/src/core/observer/dep.ts +108 -0
- package/src/core/observer/index.ts +339 -0
- package/src/core/observer/scheduler.ts +199 -0
- package/src/core/observer/traverse.ts +47 -0
- package/src/core/observer/watcher.ts +278 -0
- package/src/core/util/debug.ts +105 -0
- package/src/core/util/env.ts +93 -0
- package/src/core/util/error.ts +81 -0
- package/src/core/util/index.ts +9 -0
- package/src/core/util/lang.ts +45 -0
- package/src/core/util/next-tick.ts +117 -0
- package/src/core/util/options.ts +489 -0
- package/src/core/util/perf.ts +28 -0
- package/src/core/util/props.ts +254 -0
- package/src/core/vdom/create-component.ts +275 -0
- package/src/core/vdom/create-element.ts +172 -0
- package/src/core/vdom/create-functional-component.ts +180 -0
- package/src/core/vdom/helpers/extract-props.ts +75 -0
- package/src/core/vdom/helpers/get-first-component-child.ts +16 -0
- package/src/core/vdom/helpers/index.ts +7 -0
- package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
- package/src/core/vdom/helpers/merge-hook.ts +40 -0
- package/src/core/vdom/helpers/normalize-children.ts +99 -0
- package/src/core/vdom/helpers/normalize-scoped-slots.ts +97 -0
- package/src/core/vdom/helpers/resolve-async-component.ts +157 -0
- package/src/core/vdom/helpers/update-listeners.ts +101 -0
- package/src/core/vdom/modules/directives.ts +137 -0
- package/src/core/vdom/modules/index.ts +4 -0
- package/src/core/vdom/modules/template-ref.ts +94 -0
- package/src/core/vdom/patch.ts +907 -0
- package/src/core/vdom/vnode.ts +119 -0
- package/src/global.d.ts +17 -0
- package/src/platforms/web/compiler/directives/html.ts +8 -0
- package/src/platforms/web/compiler/directives/index.ts +9 -0
- package/src/platforms/web/compiler/directives/model.ts +181 -0
- package/src/platforms/web/compiler/directives/text.ts +8 -0
- package/src/platforms/web/compiler/index.ts +6 -0
- package/src/platforms/web/compiler/modules/class.ts +44 -0
- package/src/platforms/web/compiler/modules/index.ts +5 -0
- package/src/platforms/web/compiler/modules/model.ts +89 -0
- package/src/platforms/web/compiler/modules/style.ts +47 -0
- package/src/platforms/web/compiler/options.ts +25 -0
- package/src/platforms/web/compiler/util.ts +22 -0
- package/src/platforms/web/entry-compiler.ts +4 -0
- package/src/platforms/web/entry-runtime-esm.ts +5 -0
- package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
- package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
- package/src/platforms/web/entry-runtime.ts +7 -0
- package/src/platforms/web/runtime/class-util.ts +61 -0
- package/src/platforms/web/runtime/components/index.ts +7 -0
- package/src/platforms/web/runtime/components/transition-group.ts +204 -0
- package/src/platforms/web/runtime/components/transition.ts +205 -0
- package/src/platforms/web/runtime/directives/index.ts +7 -0
- package/src/platforms/web/runtime/directives/model.ts +148 -0
- package/src/platforms/web/runtime/directives/show.ts +61 -0
- package/src/platforms/web/runtime/index.ts +75 -0
- package/src/platforms/web/runtime/modules/attrs.ts +115 -0
- package/src/platforms/web/runtime/modules/class.ts +37 -0
- package/src/platforms/web/runtime/modules/dom-props.ts +123 -0
- package/src/platforms/web/runtime/modules/events.ts +127 -0
- package/src/platforms/web/runtime/modules/index.ts +8 -0
- package/src/platforms/web/runtime/modules/style.ts +102 -0
- package/src/platforms/web/runtime/modules/transition.ts +341 -0
- package/src/platforms/web/runtime/node-ops.ts +66 -0
- package/src/platforms/web/runtime/patch.ts +10 -0
- package/src/platforms/web/runtime/transition-util.ts +215 -0
- package/src/platforms/web/runtime-with-compiler.ts +110 -0
- package/src/platforms/web/util/attrs.ts +58 -0
- package/src/platforms/web/util/class.ts +87 -0
- package/src/platforms/web/util/compat.ts +16 -0
- package/src/platforms/web/util/element.ts +76 -0
- package/src/platforms/web/util/index.ts +21 -0
- package/src/platforms/web/util/style.ts +71 -0
- package/src/shared/constants.ts +20 -0
- package/src/shared/util.ts +378 -0
- package/src/types/compiler.ts +207 -0
- package/src/types/component.ts +212 -0
- package/src/types/global-api.ts +37 -0
- package/src/types/modules.d.ts +15 -0
- package/src/types/options.ts +114 -0
- package/src/types/ssr.ts +27 -0
- package/src/types/utils.ts +3 -0
- package/src/types/vnode.ts +127 -0
- package/src/v3/apiAsyncComponent.ts +117 -0
- package/src/v3/apiInject.ts +71 -0
- package/src/v3/apiLifecycle.ts +68 -0
- package/src/v3/apiSetup.ts +246 -0
- package/src/v3/apiWatch.ts +353 -0
- package/src/v3/currentInstance.ts +23 -0
- package/src/v3/debug.ts +21 -0
- package/src/v3/h.ts +18 -0
- package/src/v3/index.ts +96 -0
- package/src/v3/reactivity/computed.ts +100 -0
- package/src/v3/reactivity/effect.ts +20 -0
- package/src/v3/reactivity/effectScope.ts +137 -0
- package/src/v3/reactivity/operations.ts +14 -0
- package/src/v3/reactivity/reactive.ts +137 -0
- package/src/v3/reactivity/readonly.ts +127 -0
- package/src/v3/reactivity/ref.ts +293 -0
- package/src/v3/sfc-helpers/useCssModule.ts +24 -0
- package/src/v3/sfc-helpers/useCssVars.ts +34 -0
- package/types/built-in-components.d.ts +63 -0
- package/types/common.d.ts +21 -0
- package/types/index.d.ts +81 -0
- package/types/jsx.d.ts +1353 -0
- package/types/options.d.ts +349 -0
- package/types/plugin.d.ts +8 -0
- package/types/umd.d.ts +68 -0
- package/types/v3-component-options.d.ts +252 -0
- package/types/v3-component-props.d.ts +99 -0
- package/types/v3-component-public-instance.d.ts +232 -0
- package/types/v3-define-async-component.d.ts +26 -0
- package/types/v3-define-component.d.ts +201 -0
- package/types/v3-directive.d.ts +29 -0
- package/types/v3-manual-apis.d.ts +10 -0
- package/types/v3-setup-context.d.ts +41 -0
- package/types/v3-setup-helpers.d.ts +154 -0
- package/types/vnode.d.ts +117 -0
- package/types/vue.d.ts +446 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isFunction, warn } from 'core/util'
|
|
2
|
+
import { currentInstance } from './currentInstance'
|
|
3
|
+
import type { Component } from 'types/component'
|
|
4
|
+
|
|
5
|
+
export interface InjectionKey<T> extends Symbol {}
|
|
6
|
+
|
|
7
|
+
export function provide<T>(key: InjectionKey<T> | string | number, value: T) {
|
|
8
|
+
if (!currentInstance) {
|
|
9
|
+
if (__DEV__) {
|
|
10
|
+
warn(`provide() can only be used inside setup().`)
|
|
11
|
+
}
|
|
12
|
+
} else {
|
|
13
|
+
// TS doesn't allow symbol as index type
|
|
14
|
+
resolveProvided(currentInstance)[key as string] = value
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function resolveProvided(vm: Component): Record<string, any> {
|
|
19
|
+
// by default an instance inherits its parent's provides object
|
|
20
|
+
// but when it needs to provide values of its own, it creates its
|
|
21
|
+
// own provides object using parent provides object as prototype.
|
|
22
|
+
// this way in `inject` we can simply look up injections from direct
|
|
23
|
+
// parent and let the prototype chain do the work.
|
|
24
|
+
const existing = vm._provided
|
|
25
|
+
const parentProvides = vm.$parent && vm.$parent._provided
|
|
26
|
+
if (parentProvides === existing) {
|
|
27
|
+
return (vm._provided = Object.create(parentProvides))
|
|
28
|
+
} else {
|
|
29
|
+
return existing
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function inject<T>(key: InjectionKey<T> | string): T | undefined
|
|
34
|
+
export function inject<T>(
|
|
35
|
+
key: InjectionKey<T> | string,
|
|
36
|
+
defaultValue: T,
|
|
37
|
+
treatDefaultAsFactory?: false
|
|
38
|
+
): T
|
|
39
|
+
export function inject<T>(
|
|
40
|
+
key: InjectionKey<T> | string,
|
|
41
|
+
defaultValue: T | (() => T),
|
|
42
|
+
treatDefaultAsFactory: true
|
|
43
|
+
): T
|
|
44
|
+
export function inject(
|
|
45
|
+
key: InjectionKey<any> | string,
|
|
46
|
+
defaultValue?: unknown,
|
|
47
|
+
treatDefaultAsFactory = false
|
|
48
|
+
) {
|
|
49
|
+
// fallback to `currentRenderingInstance` so that this can be called in
|
|
50
|
+
// a functional component
|
|
51
|
+
const instance = currentInstance
|
|
52
|
+
if (instance) {
|
|
53
|
+
// #2400
|
|
54
|
+
// to support `app.use` plugins,
|
|
55
|
+
// fallback to appContext's `provides` if the instance is at root
|
|
56
|
+
const provides = instance.$parent && instance.$parent._provided
|
|
57
|
+
|
|
58
|
+
if (provides && (key as string | symbol) in provides) {
|
|
59
|
+
// TS doesn't allow symbol as index type
|
|
60
|
+
return provides[key as string]
|
|
61
|
+
} else if (arguments.length > 1) {
|
|
62
|
+
return treatDefaultAsFactory && isFunction(defaultValue)
|
|
63
|
+
? defaultValue.call(instance)
|
|
64
|
+
: defaultValue
|
|
65
|
+
} else if (__DEV__) {
|
|
66
|
+
warn(`injection "${String(key)}" not found.`)
|
|
67
|
+
}
|
|
68
|
+
} else if (__DEV__) {
|
|
69
|
+
warn(`inject() can only be used inside setup() or functional components.`)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DebuggerEvent } from './debug'
|
|
2
|
+
import { Component } from 'types/component'
|
|
3
|
+
import { mergeLifecycleHook, warn } from '../core/util'
|
|
4
|
+
import { currentInstance } from './currentInstance'
|
|
5
|
+
|
|
6
|
+
function createLifeCycle<T extends (...args: any[]) => any = () => void>(
|
|
7
|
+
hookName: string
|
|
8
|
+
) {
|
|
9
|
+
return (fn: T, target: any = currentInstance) => {
|
|
10
|
+
if (!target) {
|
|
11
|
+
__DEV__ &&
|
|
12
|
+
warn(
|
|
13
|
+
`${formatName(
|
|
14
|
+
hookName
|
|
15
|
+
)} is called when there is no active component instance to be ` +
|
|
16
|
+
`associated with. ` +
|
|
17
|
+
`Lifecycle injection APIs can only be used during execution of setup().`
|
|
18
|
+
)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
return injectHook(target, hookName, fn)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function formatName(name: string) {
|
|
26
|
+
if (name === 'beforeDestroy') {
|
|
27
|
+
name = 'beforeUnmount'
|
|
28
|
+
} else if (name === 'destroyed') {
|
|
29
|
+
name = 'unmounted'
|
|
30
|
+
}
|
|
31
|
+
return `on${name[0].toUpperCase() + name.slice(1)}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function injectHook(instance: Component, hookName: string, fn: () => void) {
|
|
35
|
+
const options = instance.$options
|
|
36
|
+
options[hookName] = mergeLifecycleHook(options[hookName], fn)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const onBeforeMount = createLifeCycle('beforeMount')
|
|
40
|
+
export const onMounted = createLifeCycle('mounted')
|
|
41
|
+
export const onBeforeUpdate = createLifeCycle('beforeUpdate')
|
|
42
|
+
export const onUpdated = createLifeCycle('updated')
|
|
43
|
+
export const onBeforeUnmount = createLifeCycle('beforeDestroy')
|
|
44
|
+
export const onUnmounted = createLifeCycle('destroyed')
|
|
45
|
+
export const onActivated = createLifeCycle('activated')
|
|
46
|
+
export const onDeactivated = createLifeCycle('deactivated')
|
|
47
|
+
export const onServerPrefetch = createLifeCycle('serverPrefetch')
|
|
48
|
+
|
|
49
|
+
export const onRenderTracked =
|
|
50
|
+
createLifeCycle<(e: DebuggerEvent) => any>('renderTracked')
|
|
51
|
+
export const onRenderTriggered =
|
|
52
|
+
createLifeCycle<(e: DebuggerEvent) => any>('renderTriggered')
|
|
53
|
+
|
|
54
|
+
export type ErrorCapturedHook<TError = unknown> = (
|
|
55
|
+
err: TError,
|
|
56
|
+
instance: any,
|
|
57
|
+
info: string
|
|
58
|
+
) => boolean | void
|
|
59
|
+
|
|
60
|
+
const injectErrorCapturedHook =
|
|
61
|
+
createLifeCycle<ErrorCapturedHook<any>>('errorCaptured')
|
|
62
|
+
|
|
63
|
+
export function onErrorCaptured<TError = Error>(
|
|
64
|
+
hook: ErrorCapturedHook<TError>,
|
|
65
|
+
target: any = currentInstance
|
|
66
|
+
) {
|
|
67
|
+
injectErrorCapturedHook(hook, target)
|
|
68
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { Component } from 'types/component'
|
|
2
|
+
import { PropOptions } from 'types/options'
|
|
3
|
+
import { popTarget, pushTarget } from '../core/observer/dep'
|
|
4
|
+
import { def, invokeWithErrorHandling, isReserved, warn } from '../core/util'
|
|
5
|
+
import VNode from '../core/vdom/vnode'
|
|
6
|
+
import {
|
|
7
|
+
bind,
|
|
8
|
+
emptyObject,
|
|
9
|
+
isArray,
|
|
10
|
+
isFunction,
|
|
11
|
+
isObject
|
|
12
|
+
} from '../shared/util'
|
|
13
|
+
import { currentInstance, setCurrentInstance } from './currentInstance'
|
|
14
|
+
import { shallowReactive } from './reactivity/reactive'
|
|
15
|
+
import { proxyWithRefUnwrap } from './reactivity/ref'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export interface SetupContext {
|
|
21
|
+
attrs: Record<string, any>
|
|
22
|
+
listeners: Record<string, Function | Function[]>
|
|
23
|
+
slots: Record<string, () => VNode[]>
|
|
24
|
+
emit: (event: string, ...args: any[]) => any
|
|
25
|
+
expose: (exposed: Record<string, any>) => void
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function initSetup(vm: Component) {
|
|
29
|
+
const options = vm.$options
|
|
30
|
+
const setup = options.setup
|
|
31
|
+
if (setup) {
|
|
32
|
+
const ctx = (vm._setupContext = createSetupContext(vm))
|
|
33
|
+
|
|
34
|
+
setCurrentInstance(vm)
|
|
35
|
+
pushTarget()
|
|
36
|
+
const setupResult = invokeWithErrorHandling(
|
|
37
|
+
setup,
|
|
38
|
+
null,
|
|
39
|
+
[vm._props || shallowReactive({}), ctx],
|
|
40
|
+
vm,
|
|
41
|
+
`setup`
|
|
42
|
+
)
|
|
43
|
+
popTarget()
|
|
44
|
+
setCurrentInstance()
|
|
45
|
+
|
|
46
|
+
if (isFunction(setupResult)) {
|
|
47
|
+
// render function
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
options.render = setupResult
|
|
50
|
+
} else if (isObject(setupResult)) {
|
|
51
|
+
// bindings
|
|
52
|
+
if (__DEV__ && setupResult instanceof VNode) {
|
|
53
|
+
warn(
|
|
54
|
+
`setup() should not return VNodes directly - ` +
|
|
55
|
+
`return a render function instead.`
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
vm._setupState = setupResult
|
|
59
|
+
// __sfc indicates compiled bindings from <script setup>
|
|
60
|
+
if (!setupResult.__sfc) {
|
|
61
|
+
for (const key in setupResult) {
|
|
62
|
+
if (!isReserved(key)) {
|
|
63
|
+
proxyWithRefUnwrap(vm, setupResult, key)
|
|
64
|
+
} else if (__DEV__) {
|
|
65
|
+
warn(`Avoid using variables that start with _ or $ in setup().`)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
// exposed for compiled render fn
|
|
70
|
+
const proxy = (vm._setupProxy = {})
|
|
71
|
+
for (const key in setupResult) {
|
|
72
|
+
if (key !== '__sfc') {
|
|
73
|
+
proxyWithRefUnwrap(proxy, setupResult, key)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} else if (__DEV__ && setupResult !== undefined) {
|
|
78
|
+
warn(
|
|
79
|
+
`setup() should return an object. Received: ${
|
|
80
|
+
setupResult === null ? 'null' : typeof setupResult
|
|
81
|
+
}`
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function createSetupContext(vm: Component): SetupContext {
|
|
88
|
+
let exposeCalled = false
|
|
89
|
+
return {
|
|
90
|
+
get attrs() {
|
|
91
|
+
if (!vm._attrsProxy) {
|
|
92
|
+
const proxy = (vm._attrsProxy = {})
|
|
93
|
+
def(proxy, '_v_attr_proxy', true)
|
|
94
|
+
syncSetupProxy(proxy, vm.$attrs, emptyObject, vm, '$attrs')
|
|
95
|
+
}
|
|
96
|
+
return vm._attrsProxy
|
|
97
|
+
},
|
|
98
|
+
get listeners() {
|
|
99
|
+
if (!vm._listenersProxy) {
|
|
100
|
+
const proxy = (vm._listenersProxy = {})
|
|
101
|
+
syncSetupProxy(proxy, vm.$listeners, emptyObject, vm, '$listeners')
|
|
102
|
+
}
|
|
103
|
+
return vm._listenersProxy
|
|
104
|
+
},
|
|
105
|
+
get slots() {
|
|
106
|
+
return initSlotsProxy(vm)
|
|
107
|
+
},
|
|
108
|
+
emit: bind(vm.$emit, vm) as any,
|
|
109
|
+
expose(exposed?: Record<string, any>) {
|
|
110
|
+
if (__DEV__) {
|
|
111
|
+
if (exposeCalled) {
|
|
112
|
+
warn(`expose() should be called only once per setup().`, vm)
|
|
113
|
+
}
|
|
114
|
+
exposeCalled = true
|
|
115
|
+
}
|
|
116
|
+
if (exposed) {
|
|
117
|
+
Object.keys(exposed).forEach(key =>
|
|
118
|
+
proxyWithRefUnwrap(vm, exposed, key)
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function syncSetupProxy(
|
|
126
|
+
to: any,
|
|
127
|
+
from: any,
|
|
128
|
+
prev: any,
|
|
129
|
+
instance: Component,
|
|
130
|
+
type: string
|
|
131
|
+
) {
|
|
132
|
+
let changed = false
|
|
133
|
+
for (const key in from) {
|
|
134
|
+
if (!(key in to)) {
|
|
135
|
+
changed = true
|
|
136
|
+
defineProxyAttr(to, key, instance, type)
|
|
137
|
+
} else if (from[key] !== prev[key]) {
|
|
138
|
+
changed = true
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const key in to) {
|
|
142
|
+
if (!(key in from)) {
|
|
143
|
+
changed = true
|
|
144
|
+
delete to[key]
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return changed
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function defineProxyAttr(
|
|
151
|
+
proxy: any,
|
|
152
|
+
key: string,
|
|
153
|
+
instance: Component,
|
|
154
|
+
type: string
|
|
155
|
+
) {
|
|
156
|
+
Object.defineProperty(proxy, key, {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
configurable: true,
|
|
159
|
+
get() {
|
|
160
|
+
return instance[type][key]
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function initSlotsProxy(vm: Component) {
|
|
166
|
+
if (!vm._slotsProxy) {
|
|
167
|
+
syncSetupSlots((vm._slotsProxy = {}), vm.$scopedSlots)
|
|
168
|
+
}
|
|
169
|
+
return vm._slotsProxy
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function syncSetupSlots(to: any, from: any) {
|
|
173
|
+
for (const key in from) {
|
|
174
|
+
to[key] = from[key]
|
|
175
|
+
}
|
|
176
|
+
for (const key in to) {
|
|
177
|
+
if (!(key in from)) {
|
|
178
|
+
delete to[key]
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @internal use manual type def because public setup context type relies on
|
|
185
|
+
* legacy VNode types
|
|
186
|
+
*/
|
|
187
|
+
export function useSlots(): SetupContext['slots'] {
|
|
188
|
+
return getContext().slots
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @internal use manual type def because public setup context type relies on
|
|
193
|
+
* legacy VNode types
|
|
194
|
+
*/
|
|
195
|
+
export function useAttrs(): SetupContext['attrs'] {
|
|
196
|
+
return getContext().attrs
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Vue 2 only
|
|
201
|
+
* @internal use manual type def because public setup context type relies on
|
|
202
|
+
* legacy VNode types
|
|
203
|
+
*/
|
|
204
|
+
export function useListeners(): SetupContext['listeners'] {
|
|
205
|
+
return getContext().listeners
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function getContext(): SetupContext {
|
|
209
|
+
if (__DEV__ && !currentInstance) {
|
|
210
|
+
warn(`useContext() called without active instance.`)
|
|
211
|
+
}
|
|
212
|
+
const vm = currentInstance!
|
|
213
|
+
return vm._setupContext || (vm._setupContext = createSetupContext(vm))
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Runtime helper for merging default declarations. Imported by compiled code
|
|
218
|
+
* only.
|
|
219
|
+
* @internal
|
|
220
|
+
*/
|
|
221
|
+
export function mergeDefaults(
|
|
222
|
+
raw: string[] | Record<string, PropOptions>,
|
|
223
|
+
defaults: Record<string, any>
|
|
224
|
+
): Record<string, PropOptions> {
|
|
225
|
+
const props = isArray(raw)
|
|
226
|
+
? raw.reduce(
|
|
227
|
+
(normalized, p) => ((normalized[p] = {}), normalized),
|
|
228
|
+
{} as Record<string, PropOptions>
|
|
229
|
+
)
|
|
230
|
+
: raw
|
|
231
|
+
for (const key in defaults) {
|
|
232
|
+
const opt = props[key]
|
|
233
|
+
if (opt) {
|
|
234
|
+
if (isArray(opt) || isFunction(opt)) {
|
|
235
|
+
props[key] = { type: opt, default: defaults[key] }
|
|
236
|
+
} else {
|
|
237
|
+
opt.default = defaults[key]
|
|
238
|
+
}
|
|
239
|
+
} else if (opt === null) {
|
|
240
|
+
props[key] = { default: defaults[key] }
|
|
241
|
+
} else if (__DEV__) {
|
|
242
|
+
warn(`props default key "${key}" has no corresponding declaration.`)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return props
|
|
246
|
+
}
|