vue 2.7.0 → 2.7.3
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 +88 -75
- package/dist/vue.common.prod.js +3 -3
- package/dist/vue.esm.browser.js +88 -76
- package/dist/vue.esm.browser.min.js +3 -3
- package/dist/vue.esm.js +89 -76
- package/dist/vue.js +89 -75
- package/dist/vue.min.js +3 -3
- package/dist/vue.runtime.common.dev.js +88 -75
- package/dist/vue.runtime.common.prod.js +3 -3
- package/dist/vue.runtime.esm.js +89 -76
- package/dist/vue.runtime.js +89 -75
- package/dist/vue.runtime.min.js +3 -3
- package/dist/vue.runtime.mjs +89 -76
- package/package.json +2 -2
- package/packages/compiler-sfc/dist/compiler-sfc.js +70 -67
- package/packages/compiler-sfc/package.json +1 -1
- package/packages/compiler-sfc/src/compileScript.ts +12 -15
- package/packages/compiler-sfc/src/parseComponent.ts +6 -1
- package/packages/compiler-sfc/src/templateCompilerModules/srcset.ts +1 -1
- package/packages/compiler-sfc/test/compileScript.spec.ts +12 -0
- package/src/core/observer/index.ts +55 -56
- package/src/core/util/next-tick.ts +2 -1
- package/src/core/vdom/modules/directives.ts +2 -2
- package/src/shared/constants.ts +3 -1
- package/src/shared/util.ts +1 -1
- package/src/v3/apiSetup.ts +4 -21
- package/src/v3/apiWatch.ts +2 -2
- package/src/v3/index.ts +1 -0
- package/src/v3/reactivity/reactive.ts +13 -2
- package/src/v3/reactivity/ref.ts +40 -2
- package/types/common.d.ts +6 -0
- package/types/index.d.ts +7 -4
- package/types/jsx.d.ts +16 -2
- package/types/options.d.ts +7 -1
- package/types/v3-component-options.d.ts +162 -33
- package/types/v3-component-props.d.ts +19 -20
- package/types/v3-component-public-instance.d.ts +230 -0
- package/types/v3-define-component.d.ts +70 -12
- package/types/v3-generated.d.ts +5 -1
- package/types/v3-setup-context.d.ts +0 -6
- package/types/vnode.d.ts +15 -0
- package/types/v3-component-proxy.d.ts +0 -189
|
@@ -39,7 +39,7 @@ import { walk } from 'estree-walker'
|
|
|
39
39
|
import { RawSourceMap } from 'source-map'
|
|
40
40
|
import { warnOnce } from './warn'
|
|
41
41
|
import { isReservedTag } from 'web/util'
|
|
42
|
-
import { dirRE } from 'compiler/parser'
|
|
42
|
+
import { bindRE, dirRE, onRE } from 'compiler/parser'
|
|
43
43
|
import { parseText } from 'compiler/parser/text-parser'
|
|
44
44
|
import { DEFAULT_FILENAME } from './parseComponent'
|
|
45
45
|
import {
|
|
@@ -278,8 +278,7 @@ export function compileScript(
|
|
|
278
278
|
local: string,
|
|
279
279
|
imported: string | false,
|
|
280
280
|
isType: boolean,
|
|
281
|
-
isFromSetup: boolean
|
|
282
|
-
needTemplateUsageCheck: boolean
|
|
281
|
+
isFromSetup: boolean
|
|
283
282
|
) {
|
|
284
283
|
if (source === 'vue' && imported) {
|
|
285
284
|
userImportAlias[imported] = local
|
|
@@ -287,14 +286,8 @@ export function compileScript(
|
|
|
287
286
|
|
|
288
287
|
// template usage check is only needed in non-inline mode, so we can skip
|
|
289
288
|
// the work if inlineTemplate is true.
|
|
290
|
-
let isUsedInTemplate =
|
|
291
|
-
if (
|
|
292
|
-
needTemplateUsageCheck &&
|
|
293
|
-
isTS &&
|
|
294
|
-
sfc.template &&
|
|
295
|
-
!sfc.template.src &&
|
|
296
|
-
!sfc.template.lang
|
|
297
|
-
) {
|
|
289
|
+
let isUsedInTemplate = true
|
|
290
|
+
if (isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
|
|
298
291
|
isUsedInTemplate = isImportUsed(local, sfc)
|
|
299
292
|
}
|
|
300
293
|
|
|
@@ -658,8 +651,7 @@ export function compileScript(
|
|
|
658
651
|
node.importKind === 'type' ||
|
|
659
652
|
(specifier.type === 'ImportSpecifier' &&
|
|
660
653
|
specifier.importKind === 'type'),
|
|
661
|
-
false
|
|
662
|
-
true
|
|
654
|
+
false
|
|
663
655
|
)
|
|
664
656
|
}
|
|
665
657
|
} else if (node.type === 'ExportDefaultDeclaration') {
|
|
@@ -872,7 +864,6 @@ export function compileScript(
|
|
|
872
864
|
node.importKind === 'type' ||
|
|
873
865
|
(specifier.type === 'ImportSpecifier' &&
|
|
874
866
|
specifier.importKind === 'type'),
|
|
875
|
-
true,
|
|
876
867
|
true
|
|
877
868
|
)
|
|
878
869
|
}
|
|
@@ -1809,7 +1800,11 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {
|
|
|
1809
1800
|
for (let i = 0; i < attrs.length; i++) {
|
|
1810
1801
|
const { name, value } = attrs[i]
|
|
1811
1802
|
if (dirRE.test(name)) {
|
|
1812
|
-
const baseName =
|
|
1803
|
+
const baseName = onRE.test(name)
|
|
1804
|
+
? 'on'
|
|
1805
|
+
: bindRE.test(name)
|
|
1806
|
+
? 'bind'
|
|
1807
|
+
: name.replace(dirRE, '')
|
|
1813
1808
|
if (!isBuiltInDir(baseName)) {
|
|
1814
1809
|
code += `,v${capitalize(camelize(baseName))}`
|
|
1815
1810
|
}
|
|
@@ -1838,6 +1833,8 @@ function processExp(exp: string, dir?: string): string {
|
|
|
1838
1833
|
if (/ as\s+\w|<.*>|:/.test(exp)) {
|
|
1839
1834
|
if (dir === 'slot') {
|
|
1840
1835
|
exp = `(${exp})=>{}`
|
|
1836
|
+
} else if (dir === 'on') {
|
|
1837
|
+
exp = `()=>{${exp}}`
|
|
1841
1838
|
} else if (dir === 'for') {
|
|
1842
1839
|
const inMatch = exp.match(forAliasRE)
|
|
1843
1840
|
if (inMatch) {
|
|
@@ -10,6 +10,7 @@ export const DEFAULT_FILENAME = 'anonymous.vue'
|
|
|
10
10
|
const splitRE = /\r?\n/g
|
|
11
11
|
const replaceRE = /./g
|
|
12
12
|
const isSpecialTag = makeMap('script,style,template', true)
|
|
13
|
+
const isNeedIndentLang = makeMap('pug,jade')
|
|
13
14
|
|
|
14
15
|
export interface SFCCustomBlock {
|
|
15
16
|
type: string
|
|
@@ -177,7 +178,11 @@ export function parseComponent(
|
|
|
177
178
|
if (depth === 1 && currentBlock) {
|
|
178
179
|
currentBlock.end = start
|
|
179
180
|
let text = source.slice(currentBlock.start, currentBlock.end)
|
|
180
|
-
if (
|
|
181
|
+
if (
|
|
182
|
+
options.deindent ||
|
|
183
|
+
// certain langs like pug are indent sensitive, preserve old behavior
|
|
184
|
+
(currentBlock.lang && isNeedIndentLang(currentBlock.lang))
|
|
185
|
+
) {
|
|
181
186
|
text = deindent(text)
|
|
182
187
|
}
|
|
183
188
|
// pad content so that linters and pre-processors can output correct
|
|
@@ -1562,5 +1562,17 @@ describe('SFC analyze <script> bindings', () => {
|
|
|
1562
1562
|
expect(content).toMatch(`name: 'Baz'`)
|
|
1563
1563
|
assertCode(content)
|
|
1564
1564
|
})
|
|
1565
|
+
|
|
1566
|
+
// #12591
|
|
1567
|
+
test('should not error when performing ts expression check for v-on inline statement', () => {
|
|
1568
|
+
compile(`
|
|
1569
|
+
<script setup lang="ts">
|
|
1570
|
+
import { foo } from './foo'
|
|
1571
|
+
</script>
|
|
1572
|
+
<template>
|
|
1573
|
+
<div @click="$emit('update:a');"></div>
|
|
1574
|
+
</tempalte>
|
|
1575
|
+
`)
|
|
1576
|
+
})
|
|
1565
1577
|
})
|
|
1566
1578
|
})
|
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
isUndef,
|
|
14
14
|
isValidArrayIndex,
|
|
15
15
|
isServerRendering,
|
|
16
|
-
hasChanged
|
|
16
|
+
hasChanged,
|
|
17
|
+
noop
|
|
17
18
|
} from '../util/index'
|
|
18
19
|
import { isReadonly, isRef, TrackOpTypes, TriggerOpTypes } from '../../v3'
|
|
19
20
|
|
|
@@ -31,6 +32,14 @@ export function toggleObserving(value: boolean) {
|
|
|
31
32
|
shouldObserve = value
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
// ssr mock dep
|
|
36
|
+
const mockDep = {
|
|
37
|
+
notify: noop,
|
|
38
|
+
depend: noop,
|
|
39
|
+
addSub: noop,
|
|
40
|
+
removeSub: noop
|
|
41
|
+
} as Dep
|
|
42
|
+
|
|
34
43
|
/**
|
|
35
44
|
* Observer class that is attached to each observed
|
|
36
45
|
* object. Once attached, the observer converts the target
|
|
@@ -41,78 +50,63 @@ export class Observer {
|
|
|
41
50
|
dep: Dep
|
|
42
51
|
vmCount: number // number of vms that have this object as root $data
|
|
43
52
|
|
|
44
|
-
constructor(public value: any, public shallow = false) {
|
|
53
|
+
constructor(public value: any, public shallow = false, public mock = false) {
|
|
45
54
|
// this.value = value
|
|
46
|
-
this.dep = new Dep()
|
|
55
|
+
this.dep = mock ? mockDep : new Dep()
|
|
47
56
|
this.vmCount = 0
|
|
48
57
|
def(value, '__ob__', this)
|
|
49
58
|
if (isArray(value)) {
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
if (!mock) {
|
|
60
|
+
if (hasProto) {
|
|
61
|
+
/* eslint-disable no-proto */
|
|
62
|
+
;(value as any).__proto__ = arrayMethods
|
|
63
|
+
/* eslint-enable no-proto */
|
|
64
|
+
} else {
|
|
65
|
+
for (let i = 0, l = arrayKeys.length; i < l; i++) {
|
|
66
|
+
const key = arrayKeys[i]
|
|
67
|
+
def(value, key, arrayMethods[key])
|
|
68
|
+
}
|
|
69
|
+
}
|
|
54
70
|
}
|
|
55
71
|
if (!shallow) {
|
|
56
72
|
this.observeArray(value)
|
|
57
73
|
}
|
|
58
74
|
} else {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const keys = Object.keys(obj)
|
|
70
|
-
for (let i = 0; i < keys.length; i++) {
|
|
71
|
-
const key = keys[i]
|
|
72
|
-
defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow)
|
|
75
|
+
/**
|
|
76
|
+
* Walk through all properties and convert them into
|
|
77
|
+
* getter/setters. This method should only be called when
|
|
78
|
+
* value type is Object.
|
|
79
|
+
*/
|
|
80
|
+
const keys = Object.keys(value)
|
|
81
|
+
for (let i = 0; i < keys.length; i++) {
|
|
82
|
+
const key = keys[i]
|
|
83
|
+
defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock)
|
|
84
|
+
}
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
/**
|
|
77
89
|
* Observe a list of Array items.
|
|
78
90
|
*/
|
|
79
|
-
observeArray(
|
|
80
|
-
for (let i = 0, l =
|
|
81
|
-
observe(
|
|
91
|
+
observeArray(value: any[]) {
|
|
92
|
+
for (let i = 0, l = value.length; i < l; i++) {
|
|
93
|
+
observe(value[i], false, this.mock)
|
|
82
94
|
}
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
// helpers
|
|
87
99
|
|
|
88
|
-
/**
|
|
89
|
-
* Augment a target Object or Array by intercepting
|
|
90
|
-
* the prototype chain using __proto__
|
|
91
|
-
*/
|
|
92
|
-
function protoAugment(target, src: Object) {
|
|
93
|
-
/* eslint-disable no-proto */
|
|
94
|
-
target.__proto__ = src
|
|
95
|
-
/* eslint-enable no-proto */
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Augment a target Object or Array by defining
|
|
100
|
-
* hidden properties.
|
|
101
|
-
*/
|
|
102
|
-
/* istanbul ignore next */
|
|
103
|
-
function copyAugment(target: Object, src: Object, keys: Array<string>) {
|
|
104
|
-
for (let i = 0, l = keys.length; i < l; i++) {
|
|
105
|
-
const key = keys[i]
|
|
106
|
-
def(target, key, src[key])
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
100
|
/**
|
|
111
101
|
* Attempt to create an observer instance for a value,
|
|
112
102
|
* returns the new observer if successfully observed,
|
|
113
103
|
* or the existing observer if the value already has one.
|
|
114
104
|
*/
|
|
115
|
-
export function observe(
|
|
105
|
+
export function observe(
|
|
106
|
+
value: any,
|
|
107
|
+
shallow?: boolean,
|
|
108
|
+
ssrMockReactivity?: boolean
|
|
109
|
+
): Observer | void {
|
|
116
110
|
if (!isObject(value) || isRef(value) || value instanceof VNode) {
|
|
117
111
|
return
|
|
118
112
|
}
|
|
@@ -121,12 +115,12 @@ export function observe(value: any, shallow?: boolean): Observer | void {
|
|
|
121
115
|
ob = value.__ob__
|
|
122
116
|
} else if (
|
|
123
117
|
shouldObserve &&
|
|
124
|
-
!isServerRendering() &&
|
|
118
|
+
(ssrMockReactivity || !isServerRendering()) &&
|
|
125
119
|
(isArray(value) || isPlainObject(value)) &&
|
|
126
120
|
Object.isExtensible(value) &&
|
|
127
|
-
!value.__v_skip
|
|
121
|
+
!value.__v_skip /* ReactiveFlags.SKIP */
|
|
128
122
|
) {
|
|
129
|
-
ob = new Observer(value, shallow)
|
|
123
|
+
ob = new Observer(value, shallow, ssrMockReactivity)
|
|
130
124
|
}
|
|
131
125
|
return ob
|
|
132
126
|
}
|
|
@@ -139,7 +133,8 @@ export function defineReactive(
|
|
|
139
133
|
key: string,
|
|
140
134
|
val?: any,
|
|
141
135
|
customSetter?: Function | null,
|
|
142
|
-
shallow?: boolean
|
|
136
|
+
shallow?: boolean,
|
|
137
|
+
mock?: boolean
|
|
143
138
|
) {
|
|
144
139
|
const dep = new Dep()
|
|
145
140
|
|
|
@@ -158,7 +153,7 @@ export function defineReactive(
|
|
|
158
153
|
val = obj[key]
|
|
159
154
|
}
|
|
160
155
|
|
|
161
|
-
let childOb = !shallow && observe(val)
|
|
156
|
+
let childOb = !shallow && observe(val, false, mock)
|
|
162
157
|
Object.defineProperty(obj, key, {
|
|
163
158
|
enumerable: true,
|
|
164
159
|
configurable: true,
|
|
@@ -181,7 +176,7 @@ export function defineReactive(
|
|
|
181
176
|
}
|
|
182
177
|
}
|
|
183
178
|
}
|
|
184
|
-
return isRef(value) ? value.value : value
|
|
179
|
+
return isRef(value) && !shallow ? value.value : value
|
|
185
180
|
},
|
|
186
181
|
set: function reactiveSetter(newVal) {
|
|
187
182
|
const value = getter ? getter.call(obj) : val
|
|
@@ -202,7 +197,7 @@ export function defineReactive(
|
|
|
202
197
|
} else {
|
|
203
198
|
val = newVal
|
|
204
199
|
}
|
|
205
|
-
childOb = !shallow && observe(newVal)
|
|
200
|
+
childOb = !shallow && observe(newVal, false, mock)
|
|
206
201
|
if (__DEV__) {
|
|
207
202
|
dep.notify({
|
|
208
203
|
type: TriggerOpTypes.SET,
|
|
@@ -241,16 +236,20 @@ export function set(
|
|
|
241
236
|
__DEV__ && warn(`Set operation on key "${key}" failed: target is readonly.`)
|
|
242
237
|
return
|
|
243
238
|
}
|
|
239
|
+
const ob = (target as any).__ob__
|
|
244
240
|
if (isArray(target) && isValidArrayIndex(key)) {
|
|
245
241
|
target.length = Math.max(target.length, key)
|
|
246
242
|
target.splice(key, 1, val)
|
|
243
|
+
// when mocking for SSR, array methods are not hijacked
|
|
244
|
+
if (!ob.shallow && ob.mock) {
|
|
245
|
+
observe(val, false, true)
|
|
246
|
+
}
|
|
247
247
|
return val
|
|
248
248
|
}
|
|
249
249
|
if (key in target && !(key in Object.prototype)) {
|
|
250
250
|
target[key] = val
|
|
251
251
|
return val
|
|
252
252
|
}
|
|
253
|
-
const ob = (target as any).__ob__
|
|
254
253
|
if ((target as any)._isVue || (ob && ob.vmCount)) {
|
|
255
254
|
__DEV__ &&
|
|
256
255
|
warn(
|
|
@@ -263,7 +262,7 @@ export function set(
|
|
|
263
262
|
target[key] = val
|
|
264
263
|
return val
|
|
265
264
|
}
|
|
266
|
-
defineReactive(ob.value, key, val)
|
|
265
|
+
defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock)
|
|
267
266
|
if (__DEV__) {
|
|
268
267
|
ob.dep.notify({
|
|
269
268
|
type: TriggerOpTypes.ADD,
|
|
@@ -86,7 +86,8 @@ if (typeof Promise !== 'undefined' && isNative(Promise)) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
export function nextTick(): Promise<void>
|
|
89
|
-
export function nextTick(cb: (...args: any[]) => any
|
|
89
|
+
export function nextTick<T>(this: T, cb: (this: T, ...args: any[]) => any): void
|
|
90
|
+
export function nextTick<T>(cb: (this: T, ...args: any[]) => any, ctx: T): void
|
|
90
91
|
/**
|
|
91
92
|
* @internal
|
|
92
93
|
*/
|
|
@@ -94,7 +94,7 @@ function normalizeDirectives(
|
|
|
94
94
|
// $flow-disable-line
|
|
95
95
|
return res
|
|
96
96
|
}
|
|
97
|
-
let i, dir
|
|
97
|
+
let i: number, dir: VNodeDirective
|
|
98
98
|
for (i = 0; i < dirs.length; i++) {
|
|
99
99
|
dir = dirs[i]
|
|
100
100
|
if (!dir.modifiers) {
|
|
@@ -103,7 +103,7 @@ function normalizeDirectives(
|
|
|
103
103
|
}
|
|
104
104
|
res[getRawDirName(dir)] = dir
|
|
105
105
|
if (vm._setupState && vm._setupState.__sfc) {
|
|
106
|
-
dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name)
|
|
106
|
+
dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name)
|
|
107
107
|
}
|
|
108
108
|
dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true)
|
|
109
109
|
}
|
package/src/shared/constants.ts
CHANGED
package/src/shared/util.ts
CHANGED
package/src/v3/apiSetup.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '../shared/util'
|
|
13
13
|
import { currentInstance, setCurrentInstance } from './currentInstance'
|
|
14
14
|
import { shallowReactive } from './reactivity/reactive'
|
|
15
|
-
import {
|
|
15
|
+
import { proxyWithRefUnwrap } from './reactivity/ref'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @internal
|
|
@@ -68,7 +68,9 @@ export function initSetup(vm: Component) {
|
|
|
68
68
|
// exposed for compiled render fn
|
|
69
69
|
const proxy = (vm._setupProxy = {})
|
|
70
70
|
for (const key in setupResult) {
|
|
71
|
-
|
|
71
|
+
if (key !== '__sfc') {
|
|
72
|
+
proxyWithRefUnwrap(proxy, setupResult, key)
|
|
73
|
+
}
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
} else if (__DEV__ && setupResult !== undefined) {
|
|
@@ -81,25 +83,6 @@ export function initSetup(vm: Component) {
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
export function proxyWithRefUnwrap(
|
|
85
|
-
target: any,
|
|
86
|
-
source: Record<string, any>,
|
|
87
|
-
key: string
|
|
88
|
-
) {
|
|
89
|
-
Object.defineProperty(target, key, {
|
|
90
|
-
enumerable: true,
|
|
91
|
-
configurable: true,
|
|
92
|
-
get: () => {
|
|
93
|
-
const raw = source[key]
|
|
94
|
-
return isRef(raw) ? raw.value : raw
|
|
95
|
-
},
|
|
96
|
-
set: newVal => {
|
|
97
|
-
const raw = source[key]
|
|
98
|
-
isRef(raw) ? (raw.value = newVal) : (source[key] = newVal)
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
86
|
function createSetupContext(vm: Component): SetupContext {
|
|
104
87
|
let exposeCalled = false
|
|
105
88
|
return {
|
package/src/v3/apiWatch.ts
CHANGED
|
@@ -221,7 +221,7 @@ function doWatch(
|
|
|
221
221
|
} else if (isFunction(source)) {
|
|
222
222
|
if (cb) {
|
|
223
223
|
// getter with cb
|
|
224
|
-
getter = () => call(source
|
|
224
|
+
getter = () => call(source, WATCHER_GETTER)
|
|
225
225
|
} else {
|
|
226
226
|
// no cb -> simple effect
|
|
227
227
|
getter = () => {
|
|
@@ -231,7 +231,7 @@ function doWatch(
|
|
|
231
231
|
if (cleanup) {
|
|
232
232
|
cleanup()
|
|
233
233
|
}
|
|
234
|
-
return call(source
|
|
234
|
+
return call(source, WATCHER, [onCleanup])
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
} else {
|
package/src/v3/index.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { observe, Observer } from 'core/observer'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
def,
|
|
4
|
+
isArray,
|
|
5
|
+
isPrimitive,
|
|
6
|
+
warn,
|
|
7
|
+
toRawType,
|
|
8
|
+
isServerRendering
|
|
9
|
+
} from 'core/util'
|
|
3
10
|
import type { Ref, UnwrapRefSimple, RawSymbol } from './ref'
|
|
4
11
|
|
|
5
12
|
export const enum ReactiveFlags {
|
|
@@ -67,7 +74,11 @@ function makeReactive(target: any, shallow: boolean) {
|
|
|
67
74
|
)
|
|
68
75
|
}
|
|
69
76
|
}
|
|
70
|
-
const ob = observe(
|
|
77
|
+
const ob = observe(
|
|
78
|
+
target,
|
|
79
|
+
shallow,
|
|
80
|
+
isServerRendering() /* ssr mock reactivity */
|
|
81
|
+
)
|
|
71
82
|
if (__DEV__ && !ob) {
|
|
72
83
|
if (target == null || isPrimitive(target)) {
|
|
73
84
|
warn(`value cannot be made reactive: ${String(target)}`)
|
package/src/v3/reactivity/ref.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from './reactive'
|
|
7
7
|
import type { IfAny } from 'types/utils'
|
|
8
8
|
import Dep from 'core/observer/dep'
|
|
9
|
-
import { warn, isArray, def } from 'core/util'
|
|
9
|
+
import { warn, isArray, def, isServerRendering } from 'core/util'
|
|
10
10
|
import { TrackOpTypes, TriggerOpTypes } from './operations'
|
|
11
11
|
|
|
12
12
|
declare const RefSymbol: unique symbol
|
|
@@ -69,7 +69,11 @@ function createRef(rawValue: unknown, shallow: boolean) {
|
|
|
69
69
|
const ref: any = {}
|
|
70
70
|
def(ref, RefFlag, true)
|
|
71
71
|
def(ref, ReactiveFlags.IS_SHALLOW, true)
|
|
72
|
-
|
|
72
|
+
def(
|
|
73
|
+
ref,
|
|
74
|
+
'dep',
|
|
75
|
+
defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering())
|
|
76
|
+
)
|
|
73
77
|
return ref
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -93,6 +97,40 @@ export function unref<T>(ref: T | Ref<T>): T {
|
|
|
93
97
|
return isRef(ref) ? (ref.value as any) : ref
|
|
94
98
|
}
|
|
95
99
|
|
|
100
|
+
export function proxyRefs<T extends object>(
|
|
101
|
+
objectWithRefs: T
|
|
102
|
+
): ShallowUnwrapRef<T> {
|
|
103
|
+
if (isReactive(objectWithRefs)) {
|
|
104
|
+
return objectWithRefs as any
|
|
105
|
+
}
|
|
106
|
+
const proxy = {}
|
|
107
|
+
const keys = Object.keys(objectWithRefs)
|
|
108
|
+
for (let i = 0; i < keys.length; i++) {
|
|
109
|
+
proxyWithRefUnwrap(proxy, objectWithRefs, keys[i])
|
|
110
|
+
}
|
|
111
|
+
return proxy as any
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function proxyWithRefUnwrap(
|
|
115
|
+
target: any,
|
|
116
|
+
source: Record<string, any>,
|
|
117
|
+
key: string
|
|
118
|
+
) {
|
|
119
|
+
Object.defineProperty(target, key, {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
get: () => unref(source[key]),
|
|
123
|
+
set: value => {
|
|
124
|
+
const oldValue = source[key]
|
|
125
|
+
if (isRef(oldValue) && !isRef(value)) {
|
|
126
|
+
oldValue.value = value
|
|
127
|
+
} else {
|
|
128
|
+
source[key] = value
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
96
134
|
export type CustomRefFactory<T> = (
|
|
97
135
|
track: () => void,
|
|
98
136
|
trigger: () => void
|
package/types/common.d.ts
CHANGED
|
@@ -13,3 +13,9 @@ type Equal<Left, Right> =
|
|
|
13
13
|
(<U>() => U extends Left ? 1 : 0) extends (<U>() => U extends Right ? 1 : 0) ? true : false;
|
|
14
14
|
|
|
15
15
|
export type HasDefined<T> = Equal<T, unknown> extends true ? false : true
|
|
16
|
+
|
|
17
|
+
// If the the type T accepts type "any", output type Y, otherwise output type N.
|
|
18
|
+
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
|
|
19
|
+
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
|
|
20
|
+
|
|
21
|
+
export type LooseRequired<T> = { [P in string & keyof T]: T[P] }
|
package/types/index.d.ts
CHANGED
|
@@ -30,7 +30,8 @@ export {
|
|
|
30
30
|
VNode,
|
|
31
31
|
VNodeComponentOptions,
|
|
32
32
|
VNodeData,
|
|
33
|
-
VNodeDirective
|
|
33
|
+
VNodeDirective,
|
|
34
|
+
ComponentCustomProps
|
|
34
35
|
} from './vnode'
|
|
35
36
|
|
|
36
37
|
export * from './v3-manual-apis'
|
|
@@ -47,13 +48,15 @@ export {
|
|
|
47
48
|
// v2 already has option with same name and it's for a single computed
|
|
48
49
|
ComputedOptions as ComponentComputedOptions,
|
|
49
50
|
MethodOptions as ComponentMethodOptions,
|
|
50
|
-
ComponentPropsOptions
|
|
51
|
+
ComponentPropsOptions,
|
|
52
|
+
ComponentCustomOptions
|
|
51
53
|
} from './v3-component-options'
|
|
52
54
|
export {
|
|
53
55
|
ComponentInstance,
|
|
54
56
|
ComponentPublicInstance,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
CreateComponentPublicInstance,
|
|
58
|
+
ComponentCustomProperties
|
|
59
|
+
} from './v3-component-public-instance'
|
|
57
60
|
export {
|
|
58
61
|
// PropType,
|
|
59
62
|
// PropOptions,
|
package/types/jsx.d.ts
CHANGED
|
@@ -1303,6 +1303,12 @@ type EventHandlers<E> = {
|
|
|
1303
1303
|
type ReservedProps = {
|
|
1304
1304
|
key?: string | number | symbol
|
|
1305
1305
|
ref?: VNodeData['ref']
|
|
1306
|
+
/**
|
|
1307
|
+
* @deprecated Old named slot syntax has been deprecated, use the new syntax
|
|
1308
|
+
* instead: `<template v-slot:name>`
|
|
1309
|
+
* https://v2.vuejs.org/v2/guide/components-slots.html#Named-Slots
|
|
1310
|
+
*/
|
|
1311
|
+
slot?: string
|
|
1306
1312
|
}
|
|
1307
1313
|
|
|
1308
1314
|
type ElementAttrs<T> = T & ReservedProps
|
|
@@ -1313,7 +1319,12 @@ type NativeElements = {
|
|
|
1313
1319
|
>
|
|
1314
1320
|
}
|
|
1315
1321
|
|
|
1316
|
-
import {
|
|
1322
|
+
import {
|
|
1323
|
+
VNode,
|
|
1324
|
+
VNodeData,
|
|
1325
|
+
ComponentCustomProps,
|
|
1326
|
+
AllowedComponentProps
|
|
1327
|
+
} from './vnode'
|
|
1317
1328
|
|
|
1318
1329
|
declare global {
|
|
1319
1330
|
namespace JSX {
|
|
@@ -1329,7 +1340,10 @@ declare global {
|
|
|
1329
1340
|
// @ts-ignore suppress ts:2374 = Duplicate string index signature.
|
|
1330
1341
|
[name: string]: any
|
|
1331
1342
|
}
|
|
1332
|
-
interface IntrinsicAttributes
|
|
1343
|
+
interface IntrinsicAttributes
|
|
1344
|
+
extends ReservedProps,
|
|
1345
|
+
AllowedComponentProps,
|
|
1346
|
+
ComponentCustomProps {}
|
|
1333
1347
|
}
|
|
1334
1348
|
}
|
|
1335
1349
|
|
package/types/options.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Vue, CreateElement, CombinedVueInstance } from './vue'
|
|
|
2
2
|
import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from './vnode'
|
|
3
3
|
import { SetupContext } from './v3-setup-context'
|
|
4
4
|
import { DebuggerEvent } from './v3-generated'
|
|
5
|
+
import { DefineComponent } from './v3-define-component'
|
|
5
6
|
|
|
6
7
|
type Constructor = {
|
|
7
8
|
new (...args: any[]): any
|
|
@@ -19,6 +20,7 @@ export type Component<
|
|
|
19
20
|
| typeof Vue
|
|
20
21
|
| FunctionalComponentOptions<Props>
|
|
21
22
|
| ComponentOptions<never, Data, Methods, Computed, Props, SetupBindings>
|
|
23
|
+
| DefineComponent<any, any, any, any, any>
|
|
22
24
|
|
|
23
25
|
type EsModule<T> = T | { default: T }
|
|
24
26
|
|
|
@@ -174,7 +176,10 @@ export interface ComponentOptions<
|
|
|
174
176
|
el?: Element | string
|
|
175
177
|
template?: string
|
|
176
178
|
// hack is for functional component type inference, should not be used in user code
|
|
177
|
-
render?(
|
|
179
|
+
render?(
|
|
180
|
+
createElement: CreateElement,
|
|
181
|
+
hack: RenderContext<Props>
|
|
182
|
+
): VNode | null | void
|
|
178
183
|
renderError?(createElement: CreateElement, err: Error): VNode
|
|
179
184
|
staticRenderFns?: ((createElement: CreateElement) => VNode)[]
|
|
180
185
|
|
|
@@ -198,6 +203,7 @@ export interface ComponentOptions<
|
|
|
198
203
|
[key: string]:
|
|
199
204
|
| Component<any, any, any, any>
|
|
200
205
|
| AsyncComponent<any, any, any, any>
|
|
206
|
+
| DefineComponent<any, any, any, any, any, any, any, any, any, any>
|
|
201
207
|
}
|
|
202
208
|
transitions?: { [key: string]: object }
|
|
203
209
|
filters?: { [key: string]: Function }
|