vue 2.7.7 → 2.7.8
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/dist/vue.common.dev.js +66 -32
- package/dist/vue.common.prod.js +3 -3
- package/dist/vue.esm.browser.js +66 -33
- package/dist/vue.esm.browser.min.js +3 -3
- package/dist/vue.esm.js +66 -33
- package/dist/vue.js +66 -32
- package/dist/vue.min.js +3 -3
- package/dist/vue.runtime.common.dev.js +42 -25
- package/dist/vue.runtime.common.prod.js +3 -3
- package/dist/vue.runtime.esm.js +42 -26
- package/dist/vue.runtime.js +42 -25
- package/dist/vue.runtime.min.js +3 -3
- package/package.json +2 -2
- package/packages/compiler-sfc/dist/compiler-sfc.js +39 -21
- package/packages/compiler-sfc/package.json +2 -3
- package/packages/compiler-sfc/src/compileTemplate.ts +1 -2
- package/src/compiler/codegen/index.ts +28 -8
- package/src/core/instance/lifecycle.ts +18 -10
- package/src/core/observer/index.ts +1 -1
- package/src/types/component.ts +1 -0
- package/src/v3/apiSetup.ts +38 -17
- package/src/v3/index.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/v3-component-public-instance.d.ts +0 -2
- package/types/v3-generated.d.ts +2 -0
- package/types/v3-manual-apis.d.ts +2 -2
- package/types/v3-setup-context.d.ts +4 -0
- package/types/vue.d.ts +6 -9
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
ASTText,
|
|
14
14
|
CompilerOptions
|
|
15
15
|
} from 'types/compiler'
|
|
16
|
-
import { BindingMetadata } from 'sfc/types'
|
|
16
|
+
import { BindingMetadata, BindingTypes } from 'sfc/types'
|
|
17
17
|
|
|
18
18
|
type TransformFunction = (el: ASTElement, code: string) => string
|
|
19
19
|
type DataGenFunction = (el: ASTElement) => string
|
|
@@ -104,10 +104,7 @@ export function genElement(el: ASTElement, state: CodegenState): string {
|
|
|
104
104
|
// check if this is a component in <script setup>
|
|
105
105
|
const bindings = state.options.bindings
|
|
106
106
|
if (maybeComponent && bindings && bindings.__isScriptSetup !== false) {
|
|
107
|
-
tag =
|
|
108
|
-
checkBindingType(bindings, el.tag) ||
|
|
109
|
-
checkBindingType(bindings, camelize(el.tag)) ||
|
|
110
|
-
checkBindingType(bindings, capitalize(camelize(el.tag)))
|
|
107
|
+
tag = checkBindingType(bindings, el.tag)
|
|
111
108
|
}
|
|
112
109
|
if (!tag) tag = `'${el.tag}'`
|
|
113
110
|
|
|
@@ -127,9 +124,32 @@ export function genElement(el: ASTElement, state: CodegenState): string {
|
|
|
127
124
|
}
|
|
128
125
|
|
|
129
126
|
function checkBindingType(bindings: BindingMetadata, key: string) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
const camelName = camelize(key)
|
|
128
|
+
const PascalName = capitalize(camelName)
|
|
129
|
+
const checkType = (type) => {
|
|
130
|
+
if (bindings[key] === type) {
|
|
131
|
+
return key
|
|
132
|
+
}
|
|
133
|
+
if (bindings[camelName] === type) {
|
|
134
|
+
return camelName
|
|
135
|
+
}
|
|
136
|
+
if (bindings[PascalName] === type) {
|
|
137
|
+
return PascalName
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const fromConst =
|
|
141
|
+
checkType(BindingTypes.SETUP_CONST) ||
|
|
142
|
+
checkType(BindingTypes.SETUP_REACTIVE_CONST)
|
|
143
|
+
if (fromConst) {
|
|
144
|
+
return fromConst
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const fromMaybeRef =
|
|
148
|
+
checkType(BindingTypes.SETUP_LET) ||
|
|
149
|
+
checkType(BindingTypes.SETUP_REF) ||
|
|
150
|
+
checkType(BindingTypes.SETUP_MAYBE_REF)
|
|
151
|
+
if (fromMaybeRef) {
|
|
152
|
+
return fromMaybeRef
|
|
133
153
|
}
|
|
134
154
|
}
|
|
135
155
|
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
invokeWithErrorHandling
|
|
19
19
|
} from '../util/index'
|
|
20
20
|
import { currentInstance, setCurrentInstance } from 'v3/currentInstance'
|
|
21
|
-
import {
|
|
21
|
+
import { syncSetupProxy } from 'v3/apiSetup'
|
|
22
22
|
|
|
23
23
|
export let activeInstance: any = null
|
|
24
24
|
export let isUpdatingChildComponent: boolean = false
|
|
@@ -288,11 +288,12 @@ export function updateChildComponent(
|
|
|
288
288
|
// force update if attrs are accessed and has changed since it may be
|
|
289
289
|
// passed to a child component.
|
|
290
290
|
if (
|
|
291
|
-
|
|
291
|
+
syncSetupProxy(
|
|
292
292
|
vm._attrsProxy,
|
|
293
293
|
attrs,
|
|
294
294
|
(prevVNode.data && prevVNode.data.attrs) || emptyObject,
|
|
295
|
-
vm
|
|
295
|
+
vm,
|
|
296
|
+
'$attrs'
|
|
296
297
|
)
|
|
297
298
|
) {
|
|
298
299
|
needsForceUpdate = true
|
|
@@ -300,7 +301,20 @@ export function updateChildComponent(
|
|
|
300
301
|
}
|
|
301
302
|
vm.$attrs = attrs
|
|
302
303
|
|
|
303
|
-
|
|
304
|
+
// update listeners
|
|
305
|
+
listeners = listeners || emptyObject
|
|
306
|
+
const prevListeners = vm.$options._parentListeners
|
|
307
|
+
if (vm._listenersProxy) {
|
|
308
|
+
syncSetupProxy(
|
|
309
|
+
vm._listenersProxy,
|
|
310
|
+
listeners,
|
|
311
|
+
prevListeners || emptyObject,
|
|
312
|
+
vm,
|
|
313
|
+
'$listeners'
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
vm.$listeners = vm.$options._parentListeners = listeners
|
|
317
|
+
updateComponentListeners(vm, listeners, prevListeners)
|
|
304
318
|
|
|
305
319
|
// update props
|
|
306
320
|
if (propsData && vm.$options.props) {
|
|
@@ -317,12 +331,6 @@ export function updateChildComponent(
|
|
|
317
331
|
vm.$options.propsData = propsData
|
|
318
332
|
}
|
|
319
333
|
|
|
320
|
-
// update listeners
|
|
321
|
-
listeners = listeners || emptyObject
|
|
322
|
-
const oldListeners = vm.$options._parentListeners
|
|
323
|
-
vm.$options._parentListeners = listeners
|
|
324
|
-
updateComponentListeners(vm, listeners, oldListeners)
|
|
325
|
-
|
|
326
334
|
// resolve slots + force update if has children
|
|
327
335
|
if (needsForceUpdate) {
|
|
328
336
|
vm.$slots = resolveSlots(renderChildren, parentVnode.context)
|
|
@@ -191,7 +191,7 @@ export function defineReactive(
|
|
|
191
191
|
} else if (getter) {
|
|
192
192
|
// #7981: for accessor properties without setter
|
|
193
193
|
return
|
|
194
|
-
} else if (isRef(value) && !isRef(newVal)) {
|
|
194
|
+
} else if (!shallow && isRef(value) && !isRef(newVal)) {
|
|
195
195
|
value.value = newVal
|
|
196
196
|
return
|
|
197
197
|
} else {
|
package/src/types/component.ts
CHANGED
|
@@ -111,6 +111,7 @@ export declare class Component {
|
|
|
111
111
|
_setupProxy?: Record<string, any>
|
|
112
112
|
_setupContext?: SetupContext
|
|
113
113
|
_attrsProxy?: Record<string, any>
|
|
114
|
+
_listenersProxy?: Record<string, Function | Function[]>
|
|
114
115
|
_slotsProxy?: Record<string, () => VNode[]>
|
|
115
116
|
_preWatchers?: Watcher[]
|
|
116
117
|
|
package/src/v3/apiSetup.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { proxyWithRefUnwrap } from './reactivity/ref'
|
|
|
19
19
|
*/
|
|
20
20
|
export interface SetupContext {
|
|
21
21
|
attrs: Record<string, any>
|
|
22
|
+
listeners: Record<string, Function | Function[]>
|
|
22
23
|
slots: Record<string, () => VNode[]>
|
|
23
24
|
emit: (event: string, ...args: any[]) => any
|
|
24
25
|
expose: (exposed: Record<string, any>) => void
|
|
@@ -87,7 +88,19 @@ function createSetupContext(vm: Component): SetupContext {
|
|
|
87
88
|
let exposeCalled = false
|
|
88
89
|
return {
|
|
89
90
|
get attrs() {
|
|
90
|
-
|
|
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
|
|
91
104
|
},
|
|
92
105
|
get slots() {
|
|
93
106
|
return initSlotsProxy(vm)
|
|
@@ -109,26 +122,18 @@ function createSetupContext(vm: Component): SetupContext {
|
|
|
109
122
|
}
|
|
110
123
|
}
|
|
111
124
|
|
|
112
|
-
function
|
|
113
|
-
if (!vm._attrsProxy) {
|
|
114
|
-
const proxy = (vm._attrsProxy = {})
|
|
115
|
-
def(proxy, '_v_attr_proxy', true)
|
|
116
|
-
syncSetupAttrs(proxy, vm.$attrs, emptyObject, vm)
|
|
117
|
-
}
|
|
118
|
-
return vm._attrsProxy
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function syncSetupAttrs(
|
|
125
|
+
export function syncSetupProxy(
|
|
122
126
|
to: any,
|
|
123
127
|
from: any,
|
|
124
128
|
prev: any,
|
|
125
|
-
instance: Component
|
|
129
|
+
instance: Component,
|
|
130
|
+
type: string
|
|
126
131
|
) {
|
|
127
132
|
let changed = false
|
|
128
133
|
for (const key in from) {
|
|
129
134
|
if (!(key in to)) {
|
|
130
135
|
changed = true
|
|
131
|
-
defineProxyAttr(to, key, instance)
|
|
136
|
+
defineProxyAttr(to, key, instance, type)
|
|
132
137
|
} else if (from[key] !== prev[key]) {
|
|
133
138
|
changed = true
|
|
134
139
|
}
|
|
@@ -142,12 +147,17 @@ export function syncSetupAttrs(
|
|
|
142
147
|
return changed
|
|
143
148
|
}
|
|
144
149
|
|
|
145
|
-
function defineProxyAttr(
|
|
150
|
+
function defineProxyAttr(
|
|
151
|
+
proxy: any,
|
|
152
|
+
key: string,
|
|
153
|
+
instance: Component,
|
|
154
|
+
type: string
|
|
155
|
+
) {
|
|
146
156
|
Object.defineProperty(proxy, key, {
|
|
147
157
|
enumerable: true,
|
|
148
158
|
configurable: true,
|
|
149
159
|
get() {
|
|
150
|
-
return instance
|
|
160
|
+
return instance[type][key]
|
|
151
161
|
}
|
|
152
162
|
})
|
|
153
163
|
}
|
|
@@ -171,19 +181,30 @@ export function syncSetupSlots(to: any, from: any) {
|
|
|
171
181
|
}
|
|
172
182
|
|
|
173
183
|
/**
|
|
174
|
-
* @internal use manual type def
|
|
184
|
+
* @internal use manual type def because public setup context type relies on
|
|
185
|
+
* legacy VNode types
|
|
175
186
|
*/
|
|
176
187
|
export function useSlots(): SetupContext['slots'] {
|
|
177
188
|
return getContext().slots
|
|
178
189
|
}
|
|
179
190
|
|
|
180
191
|
/**
|
|
181
|
-
* @internal use manual type def
|
|
192
|
+
* @internal use manual type def because public setup context type relies on
|
|
193
|
+
* legacy VNode types
|
|
182
194
|
*/
|
|
183
195
|
export function useAttrs(): SetupContext['attrs'] {
|
|
184
196
|
return getContext().attrs
|
|
185
197
|
}
|
|
186
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
|
+
|
|
187
208
|
function getContext(): SetupContext {
|
|
188
209
|
if (__DEV__ && !currentInstance) {
|
|
189
210
|
warn(`useContext() called without active instance.`)
|
package/src/v3/index.ts
CHANGED
|
@@ -77,7 +77,7 @@ export { provide, inject, InjectionKey } from './apiInject'
|
|
|
77
77
|
|
|
78
78
|
export { h } from './h'
|
|
79
79
|
export { getCurrentInstance } from './currentInstance'
|
|
80
|
-
export { useSlots, useAttrs, mergeDefaults } from './apiSetup'
|
|
80
|
+
export { useSlots, useAttrs, useListeners, mergeDefaults } from './apiSetup'
|
|
81
81
|
export { nextTick } from 'core/util/next-tick'
|
|
82
82
|
export { set, del } from 'core/observer'
|
|
83
83
|
|
package/types/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export * from './v3-setup-helpers'
|
|
|
42
42
|
export { Data } from './common'
|
|
43
43
|
export { SetupContext } from './v3-setup-context'
|
|
44
44
|
export { defineComponent } from './v3-define-component'
|
|
45
|
-
|
|
45
|
+
export { defineAsyncComponent } from './v3-define-async-component'
|
|
46
46
|
export {
|
|
47
47
|
SetupFunction,
|
|
48
48
|
// v2 already has option with same name and it's for a single computed
|
|
@@ -179,9 +179,7 @@ interface Vue3Instance<
|
|
|
179
179
|
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
|
|
180
180
|
: P & PublicProps
|
|
181
181
|
>,
|
|
182
|
-
ComponentPublicInstance | null,
|
|
183
182
|
ComponentPublicInstance,
|
|
184
|
-
ComponentPublicInstance[],
|
|
185
183
|
Options & MergedComponentOptionsOverride,
|
|
186
184
|
EmitFn<E>
|
|
187
185
|
> {}
|
package/types/v3-generated.d.ts
CHANGED
|
@@ -364,6 +364,8 @@ export declare function useCssModule(name?: string): Record<string, string>;
|
|
|
364
364
|
*/
|
|
365
365
|
export declare function useCssVars(getter: (vm: Record<string, any>, setupProxy: Record<string, any>) => Record<string, string>): void;
|
|
366
366
|
|
|
367
|
+
/* Excluded from this release type: useListeners */
|
|
368
|
+
|
|
367
369
|
/* Excluded from this release type: useSlots */
|
|
368
370
|
|
|
369
371
|
/**
|
|
@@ -5,6 +5,6 @@ export function getCurrentInstance(): { proxy: Vue } | null
|
|
|
5
5
|
|
|
6
6
|
export const h: CreateElement
|
|
7
7
|
|
|
8
|
-
export function useAttrs(): SetupContext['attrs']
|
|
9
|
-
|
|
10
8
|
export function useSlots(): SetupContext['slots']
|
|
9
|
+
export function useAttrs(): SetupContext['attrs']
|
|
10
|
+
export function useListeners(): SetupContext['listeners']
|
|
@@ -31,6 +31,10 @@ export type EmitFn<
|
|
|
31
31
|
|
|
32
32
|
export interface SetupContext<E extends EmitsOptions = {}> {
|
|
33
33
|
attrs: Data
|
|
34
|
+
/**
|
|
35
|
+
* Equivalent of `this.$listeners`, which is Vue 2 only.
|
|
36
|
+
*/
|
|
37
|
+
listeners: Record<string, Function | Function[]>
|
|
34
38
|
slots: Slots
|
|
35
39
|
emit: EmitFn<E>
|
|
36
40
|
expose(exposed?: Record<string, any>): void
|
package/types/vue.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ import { VNode, VNodeData, VNodeChildren, NormalizedScopedSlot } from './vnode'
|
|
|
14
14
|
import { PluginFunction, PluginObject } from './plugin'
|
|
15
15
|
import { DefineComponent } from './v3-define-component'
|
|
16
16
|
import { nextTick } from './v3-generated'
|
|
17
|
-
import { ComponentPublicInstance } from './v3-component-public-instance'
|
|
18
17
|
|
|
19
18
|
export interface CreateElement {
|
|
20
19
|
(
|
|
@@ -41,18 +40,16 @@ type NeverFallback<T, D> = [T] extends [never] ? D : T
|
|
|
41
40
|
export interface Vue<
|
|
42
41
|
Data = Record<string, any>,
|
|
43
42
|
Props = Record<string, any>,
|
|
44
|
-
|
|
45
|
-
Root = never,
|
|
46
|
-
Children = never,
|
|
43
|
+
Instance = never,
|
|
47
44
|
Options = never,
|
|
48
45
|
Emit = (event: string, ...args: any[]) => Vue
|
|
49
46
|
> {
|
|
50
47
|
// properties with different types in defineComponent()
|
|
51
48
|
readonly $data: Data
|
|
52
49
|
readonly $props: Props
|
|
53
|
-
readonly $parent: NeverFallback<
|
|
54
|
-
readonly $root: NeverFallback<
|
|
55
|
-
readonly $children: NeverFallback<
|
|
50
|
+
readonly $parent: NeverFallback<Instance, Vue> | null
|
|
51
|
+
readonly $root: NeverFallback<Instance, Vue>
|
|
52
|
+
readonly $children: NeverFallback<Instance, Vue>[]
|
|
56
53
|
readonly $options: NeverFallback<Options, ComponentOptions<Vue>>
|
|
57
54
|
$emit: Emit
|
|
58
55
|
|
|
@@ -60,10 +57,10 @@ export interface Vue<
|
|
|
60
57
|
readonly $el: Element
|
|
61
58
|
readonly $refs: {
|
|
62
59
|
[key: string]:
|
|
60
|
+
| NeverFallback<Instance, Vue>
|
|
63
61
|
| Vue
|
|
64
62
|
| Element
|
|
65
|
-
|
|
|
66
|
-
| (Vue | Element | ComponentPublicInstance)[]
|
|
63
|
+
| (NeverFallback<Instance, Vue> | Vue | Element)[]
|
|
67
64
|
| undefined
|
|
68
65
|
}
|
|
69
66
|
readonly $slots: { [key: string]: VNode[] | undefined }
|