vue 2.7.1 → 2.7.4

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 (42) hide show
  1. package/dist/vue.common.dev.js +133 -61
  2. package/dist/vue.common.prod.js +3 -3
  3. package/dist/vue.esm.browser.js +133 -62
  4. package/dist/vue.esm.browser.min.js +3 -3
  5. package/dist/vue.esm.js +135 -62
  6. package/dist/vue.js +135 -61
  7. package/dist/vue.min.js +3 -3
  8. package/dist/vue.runtime.common.dev.js +133 -61
  9. package/dist/vue.runtime.common.prod.js +3 -3
  10. package/dist/vue.runtime.esm.js +135 -62
  11. package/dist/vue.runtime.js +135 -61
  12. package/dist/vue.runtime.min.js +3 -3
  13. package/dist/vue.runtime.mjs +72 -8604
  14. package/package.json +2 -2
  15. package/packages/compiler-sfc/dist/compiler-sfc.js +56 -55
  16. package/packages/compiler-sfc/package.json +1 -1
  17. package/packages/compiler-sfc/src/parseComponent.ts +9 -1
  18. package/packages/compiler-sfc/test/parseComponent.spec.ts +6 -7
  19. package/src/core/instance/render-helpers/render-static.ts +1 -1
  20. package/src/core/observer/index.ts +54 -55
  21. package/src/core/util/next-tick.ts +2 -1
  22. package/src/core/vdom/modules/directives.ts +2 -2
  23. package/src/shared/constants.ts +3 -1
  24. package/src/v3/apiAsyncComponent.ts +117 -0
  25. package/src/v3/apiWatch.ts +2 -2
  26. package/src/v3/index.ts +6 -0
  27. package/src/v3/reactivity/reactive.ts +13 -2
  28. package/src/v3/reactivity/ref.ts +6 -2
  29. package/types/common.d.ts +6 -0
  30. package/types/index.d.ts +7 -4
  31. package/types/jsx.d.ts +16 -2
  32. package/types/options.d.ts +8 -2
  33. package/types/v3-component-options.d.ts +162 -33
  34. package/types/v3-component-props.d.ts +19 -20
  35. package/types/v3-component-public-instance.d.ts +234 -0
  36. package/types/v3-define-async-component.d.ts +26 -0
  37. package/types/v3-define-component.d.ts +94 -12
  38. package/types/v3-generated.d.ts +26 -1
  39. package/types/v3-setup-context.d.ts +0 -6
  40. package/types/vnode.d.ts +15 -0
  41. package/types/vue.d.ts +17 -10
  42. package/types/v3-component-proxy.d.ts +0 -189
@@ -320,8 +320,8 @@ function doWatch(
320
320
  } else {
321
321
  // pre
322
322
  watcher.update = () => {
323
- if (instance && instance === currentInstance) {
324
- // pre-watcher triggered inside setup()
323
+ if (instance && instance === currentInstance && !instance._isMounted) {
324
+ // pre-watcher triggered before
325
325
  const buffer = instance._preWatchers || (instance._preWatchers = [])
326
326
  if (buffer.indexOf(watcher) < 0) buffer.push(watcher)
327
327
  } else {
package/src/v3/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
3
+ */
4
+
1
5
  export const version: string = '__VERSION__'
2
6
 
3
7
  export {
@@ -87,4 +91,6 @@ export function defineComponent(options: any) {
87
91
  return options
88
92
  }
89
93
 
94
+ export { defineAsyncComponent } from './apiAsyncComponent'
95
+
90
96
  export * from './apiLifecycle'
@@ -1,5 +1,12 @@
1
1
  import { observe, Observer } from 'core/observer'
2
- import { def, isArray, isPrimitive, warn, toRawType } from 'core/util'
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(target, shallow)
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)}`)
@@ -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
- ref.dep = defineReactive(ref, 'value', rawValue, null, shallow)
72
+ def(
73
+ ref,
74
+ 'dep',
75
+ defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering())
76
+ )
73
77
  return ref
74
78
  }
75
79
 
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
- ComponentRenderProxy
56
- } from './v3-component-proxy'
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 { VNode, VNodeData } from './vnode'
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 extends ReservedProps {}
1343
+ interface IntrinsicAttributes
1344
+ extends ReservedProps,
1345
+ AllowedComponentProps,
1346
+ ComponentCustomProps {}
1333
1347
  }
1334
1348
  }
1335
1349
 
@@ -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, any, 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?(createElement: CreateElement, hack: RenderContext<Props>): VNode
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
 
@@ -196,7 +201,8 @@ export interface ComponentOptions<
196
201
  directives?: { [key: string]: DirectiveFunction | DirectiveOptions }
197
202
  components?: {
198
203
  [key: string]:
199
- | Component<any, any, any, any>
204
+ | {}
205
+ | Component<any, any, any, any, any>
200
206
  | AsyncComponent<any, any, any, any>
201
207
  }
202
208
  transitions?: { [key: string]: object }
@@ -2,11 +2,33 @@ import { Vue } from './vue'
2
2
  import { VNode } from './vnode'
3
3
  import { ComponentOptions as Vue2ComponentOptions } from './options'
4
4
  import { EmitsOptions, SetupContext } from './v3-setup-context'
5
- import { Data } from './common'
6
- import { ComponentPropsOptions, ExtractPropTypes } from './v3-component-props'
7
- import { ComponentRenderProxy } from './v3-component-proxy'
5
+ import { Data, LooseRequired, UnionToIntersection } from './common'
6
+ import {
7
+ ComponentPropsOptions,
8
+ ExtractDefaultPropTypes,
9
+ ExtractPropTypes
10
+ } from './v3-component-props'
11
+ import { CreateComponentPublicInstance } from './v3-component-public-instance'
8
12
  export { ComponentPropsOptions } from './v3-component-props'
9
13
 
14
+ /**
15
+ * Interface for declaring custom options.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * declare module 'vue' {
20
+ * interface ComponentCustomOptions {
21
+ * beforeRouteUpdate?(
22
+ * to: Route,
23
+ * from: Route,
24
+ * next: () => void
25
+ * ): void
26
+ * }
27
+ * }
28
+ * ```
29
+ */
30
+ export interface ComponentCustomOptions {}
31
+
10
32
  export type ComputedGetter<T> = (ctx?: any) => T
11
33
  export type ComputedSetter<T> = (v: T) => void
12
34
 
@@ -34,24 +56,76 @@ export type SetupFunction<
34
56
  ctx: SetupContext<Emits>
35
57
  ) => RawBindings | (() => VNode | null) | void
36
58
 
37
- interface ComponentOptionsBase<
59
+ type ExtractOptionProp<T> = T extends ComponentOptionsBase<
60
+ infer P, // Props
61
+ any, // RawBindings
62
+ any, // D
63
+ any, // C
64
+ any, // M
65
+ any, // Mixin
66
+ any, // Extends
67
+ any, // EmitsOptions
68
+ any // Defaults
69
+ >
70
+ ? unknown extends P
71
+ ? {}
72
+ : P
73
+ : {}
74
+
75
+ export interface ComponentOptionsBase<
38
76
  Props,
39
- D = Data,
40
- C extends ComputedOptions = {},
41
- M extends MethodOptions = {}
77
+ RawBindings,
78
+ D,
79
+ C extends ComputedOptions,
80
+ M extends MethodOptions,
81
+ Mixin extends ComponentOptionsMixin,
82
+ Extends extends ComponentOptionsMixin,
83
+ Emits extends EmitsOptions,
84
+ EmitNames extends string = string,
85
+ Defaults = {}
42
86
  > extends Omit<
43
- Vue2ComponentOptions<Vue, D, M, C, Props>,
44
- 'data' | 'computed' | 'method' | 'setup' | 'props'
45
- > {
46
- // allow any custom options
47
- [key: string]: any
48
-
87
+ Vue2ComponentOptions<Vue, D, M, C, Props>,
88
+ 'data' | 'computed' | 'methods' | 'setup' | 'props' | 'mixins' | 'extends'
89
+ >,
90
+ ComponentCustomOptions {
49
91
  // rewrite options api types
50
- data?: (this: Props & Vue, vm: Props) => D
92
+ data?: (
93
+ this: CreateComponentPublicInstance<Props, {}, {}, {}, M, Mixin, Extends>,
94
+ vm: CreateComponentPublicInstance<Props, {}, {}, {}, M, Mixin, Extends>
95
+ ) => D
51
96
  computed?: C
52
97
  methods?: M
98
+ mixins?: Mixin[]
99
+ extends?: Extends
100
+ emits?: (Emits | EmitNames[]) & ThisType<void>
101
+ setup?: SetupFunction<
102
+ Readonly<
103
+ LooseRequired<
104
+ Props &
105
+ UnionToIntersection<ExtractOptionProp<Mixin>> &
106
+ UnionToIntersection<ExtractOptionProp<Extends>>
107
+ >
108
+ >,
109
+ RawBindings,
110
+ Emits
111
+ >
112
+
113
+ __defaults?: Defaults
53
114
  }
54
115
 
116
+ export type ComponentOptionsMixin = ComponentOptionsBase<
117
+ any,
118
+ any,
119
+ any,
120
+ any,
121
+ any,
122
+ any,
123
+ any,
124
+ any,
125
+ any,
126
+ any
127
+ >
128
+
55
129
  export type ExtractComputedReturns<T extends any> = {
56
130
  [key in keyof T]: T[key] extends { get: (...args: any[]) => infer TReturn }
57
131
  ? TReturn
@@ -66,17 +140,36 @@ export type ComponentOptionsWithProps<
66
140
  D = Data,
67
141
  C extends ComputedOptions = {},
68
142
  M extends MethodOptions = {},
69
- Mixin = {},
70
- Extends = {},
143
+ Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
144
+ Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
71
145
  Emits extends EmitsOptions = {},
72
146
  EmitsNames extends string = string,
73
- Props = ExtractPropTypes<PropsOptions>
74
- > = ComponentOptionsBase<Props, D, C, M> & {
147
+ Props = ExtractPropTypes<PropsOptions>,
148
+ Defaults = ExtractDefaultPropTypes<PropsOptions>
149
+ > = ComponentOptionsBase<
150
+ Props,
151
+ RawBindings,
152
+ D,
153
+ C,
154
+ M,
155
+ Mixin,
156
+ Extends,
157
+ Emits,
158
+ EmitsNames,
159
+ Defaults
160
+ > & {
75
161
  props?: PropsOptions
76
- emits?: (Emits | EmitsNames[]) & ThisType<void>
77
- setup?: SetupFunction<Props, RawBindings, Emits>
78
162
  } & ThisType<
79
- ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits>
163
+ CreateComponentPublicInstance<
164
+ Props,
165
+ RawBindings,
166
+ D,
167
+ C,
168
+ M,
169
+ Mixin,
170
+ Extends,
171
+ Emits
172
+ >
80
173
  >
81
174
 
82
175
  export type ComponentOptionsWithArrayProps<
@@ -85,17 +178,35 @@ export type ComponentOptionsWithArrayProps<
85
178
  D = Data,
86
179
  C extends ComputedOptions = {},
87
180
  M extends MethodOptions = {},
88
- Mixin = {},
89
- Extends = {},
181
+ Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
182
+ Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
90
183
  Emits extends EmitsOptions = {},
91
184
  EmitsNames extends string = string,
92
185
  Props = Readonly<{ [key in PropNames]?: any }>
93
- > = ComponentOptionsBase<Props, D, C, M> & {
186
+ > = ComponentOptionsBase<
187
+ Props,
188
+ RawBindings,
189
+ D,
190
+ C,
191
+ M,
192
+ Mixin,
193
+ Extends,
194
+ Emits,
195
+ EmitsNames,
196
+ {}
197
+ > & {
94
198
  props?: PropNames[]
95
- emits?: (Emits | EmitsNames[]) & ThisType<void>
96
- setup?: SetupFunction<Props, RawBindings, Emits>
97
199
  } & ThisType<
98
- ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits>
200
+ CreateComponentPublicInstance<
201
+ Props,
202
+ RawBindings,
203
+ D,
204
+ C,
205
+ M,
206
+ Mixin,
207
+ Extends,
208
+ Emits
209
+ >
99
210
  >
100
211
 
101
212
  export type ComponentOptionsWithoutProps<
@@ -104,16 +215,34 @@ export type ComponentOptionsWithoutProps<
104
215
  D = Data,
105
216
  C extends ComputedOptions = {},
106
217
  M extends MethodOptions = {},
107
- Mixin = {},
108
- Extends = {},
218
+ Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
219
+ Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
109
220
  Emits extends EmitsOptions = {},
110
221
  EmitsNames extends string = string
111
- > = ComponentOptionsBase<Props, D, C, M> & {
222
+ > = ComponentOptionsBase<
223
+ Props,
224
+ RawBindings,
225
+ D,
226
+ C,
227
+ M,
228
+ Mixin,
229
+ Extends,
230
+ Emits,
231
+ EmitsNames,
232
+ {}
233
+ > & {
112
234
  props?: undefined
113
- emits?: (Emits | EmitsNames[]) & ThisType<void>
114
- setup?: SetupFunction<Props, RawBindings, Emits>
115
235
  } & ThisType<
116
- ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits>
236
+ CreateComponentPublicInstance<
237
+ Props,
238
+ RawBindings,
239
+ D,
240
+ C,
241
+ M,
242
+ Mixin,
243
+ Extends,
244
+ Emits
245
+ >
117
246
  >
118
247
 
119
248
  export type WithLegacyAPI<T, D, C, M, Props> = T &
@@ -1,4 +1,4 @@
1
- import { Data } from './common'
1
+ import { Data, IfAny } from './common'
2
2
 
3
3
  export type ComponentPropsOptions<P = Data> =
4
4
  | ComponentObjectPropsOptions<P>
@@ -48,26 +48,25 @@ type ExtractCorrectPropType<T> = T extends Function
48
48
  ? ExtractFunctionPropType<T>
49
49
  : Exclude<T, Function>
50
50
 
51
- // prettier-ignore
52
- type InferPropType<T> = T extends null
51
+ type InferPropType<T> = [T] extends [null]
53
52
  ? any // null & true would fail to infer
54
- : T extends { type: null | true }
55
- ? any // As TS issue https://github.com/Microsoft/TypeScript/issues/14829 // somehow `ObjectConstructor` when inferred from { (): T } becomes `any` // `BooleanConstructor` when inferred from PropConstructor(with PropMethod) becomes `Boolean`
56
- : T extends ObjectConstructor | { type: ObjectConstructor }
57
- ? Record<string, any>
58
- : T extends BooleanConstructor | { type: BooleanConstructor }
59
- ? boolean
60
- : T extends DateConstructor | { type: DateConstructor}
61
- ? Date
62
- : T extends FunctionConstructor
63
- ? Function
64
- : T extends Prop<infer V, infer D>
65
- ? unknown extends V
66
- ? D extends null | undefined
67
- ? V
68
- : D
69
- : ExtractCorrectPropType<V>
70
- : T
53
+ : [T] extends [{ type: null | true }]
54
+ ? any // As TS issue https://github.com/Microsoft/TypeScript/issues/14829 // somehow `ObjectConstructor` when inferred from { (): T } becomes `any` // `BooleanConstructor` when inferred from PropConstructor(with PropMethod) becomes `Boolean`
55
+ : [T] extends [ObjectConstructor | { type: ObjectConstructor }]
56
+ ? Record<string, any>
57
+ : [T] extends [BooleanConstructor | { type: BooleanConstructor }]
58
+ ? boolean
59
+ : [T] extends [DateConstructor | { type: DateConstructor }]
60
+ ? Date
61
+ : [T] extends [(infer U)[] | { type: (infer U)[] }]
62
+ ? U extends DateConstructor
63
+ ? Date | InferPropType<U>
64
+ : InferPropType<U>
65
+ : [T] extends [Prop<infer V, infer D>]
66
+ ? unknown extends V
67
+ ? IfAny<V, V, D>
68
+ : V
69
+ : T
71
70
 
72
71
  export type ExtractPropTypes<O> = {
73
72
  // use `keyof Pick<O, RequiredKeys<O>>` instead of `RequiredKeys<O>` to support IDE features