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
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vue.js v2.7.1
2
+ * Vue.js v2.7.4
3
3
  * (c) 2014-2022 Evan You
4
4
  * Released under the MIT License.
5
5
  */
@@ -326,7 +326,9 @@ const LIFECYCLE_HOOKS = [
326
326
  'activated',
327
327
  'deactivated',
328
328
  'errorCaptured',
329
- 'serverPrefetch'
329
+ 'serverPrefetch',
330
+ 'renderTracked',
331
+ 'renderTriggered'
330
332
  ];
331
333
 
332
334
  var config = {
@@ -834,7 +836,7 @@ function makeReactive(target, shallow) {
834
836
  warn(`Target is already a ${existingOb.shallow ? `` : `non-`}shallow reactive object, and cannot be converted to ${shallow ? `` : `non-`}shallow.`);
835
837
  }
836
838
  }
837
- const ob = observe(target, shallow);
839
+ const ob = observe(target, shallow, isServerRendering() /* ssr mock reactivity */);
838
840
  if (!ob) {
839
841
  if (target == null || isPrimitive(target)) {
840
842
  warn(`value cannot be made reactive: ${String(target)}`);
@@ -896,7 +898,7 @@ function createRef(rawValue, shallow) {
896
898
  const ref = {};
897
899
  def(ref, RefFlag, true);
898
900
  def(ref, "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */, true);
899
- ref.dep = defineReactive(ref, 'value', rawValue, null, shallow);
901
+ def(ref, 'dep', defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering()));
900
902
  return ref;
901
903
  }
902
904
  function triggerRef(ref) {
@@ -1766,7 +1768,7 @@ function renderStatic(index, isInFor) {
1766
1768
  return tree;
1767
1769
  }
1768
1770
  // otherwise, render a fresh tree.
1769
- tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, null, this // for render fns generated for functional component templates
1771
+ tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, this._c, this // for render fns generated for functional component templates
1770
1772
  );
1771
1773
  markStatic(tree, `__static__${index}`, false);
1772
1774
  return tree;
@@ -3811,8 +3813,8 @@ function doWatch(source, cb, { immediate, deep, flush = 'pre', onTrack, onTrigge
3811
3813
  else {
3812
3814
  // pre
3813
3815
  watcher.update = () => {
3814
- if (instance && instance === currentInstance) {
3815
- // pre-watcher triggered inside setup()
3816
+ if (instance && instance === currentInstance && !instance._isMounted) {
3817
+ // pre-watcher triggered before
3816
3818
  const buffer = instance._preWatchers || (instance._preWatchers = []);
3817
3819
  if (buffer.indexOf(watcher) < 0)
3818
3820
  buffer.push(watcher);
@@ -4078,6 +4080,77 @@ function useCssVars(getter) {
4078
4080
  });
4079
4081
  }
4080
4082
 
4083
+ /**
4084
+ * v3-compatible async component API.
4085
+ * @internal the type is manually declared in <root>/types/v3-define-async-component.d.ts
4086
+ * because it relies on existing manual types
4087
+ */
4088
+ function defineAsyncComponent(source) {
4089
+ if (isFunction(source)) {
4090
+ source = { loader: source };
4091
+ }
4092
+ const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
4093
+ suspensible = false, // in Vue 3 default is true
4094
+ onError: userOnError } = source;
4095
+ if (suspensible) {
4096
+ warn(`The suspensiblbe option for async components is not supported in Vue2. It is ignored.`);
4097
+ }
4098
+ let pendingRequest = null;
4099
+ let retries = 0;
4100
+ const retry = () => {
4101
+ retries++;
4102
+ pendingRequest = null;
4103
+ return load();
4104
+ };
4105
+ const load = () => {
4106
+ let thisRequest;
4107
+ return (pendingRequest ||
4108
+ (thisRequest = pendingRequest =
4109
+ loader()
4110
+ .catch(err => {
4111
+ err = err instanceof Error ? err : new Error(String(err));
4112
+ if (userOnError) {
4113
+ return new Promise((resolve, reject) => {
4114
+ const userRetry = () => resolve(retry());
4115
+ const userFail = () => reject(err);
4116
+ userOnError(err, userRetry, userFail, retries + 1);
4117
+ });
4118
+ }
4119
+ else {
4120
+ throw err;
4121
+ }
4122
+ })
4123
+ .then((comp) => {
4124
+ if (thisRequest !== pendingRequest && pendingRequest) {
4125
+ return pendingRequest;
4126
+ }
4127
+ if (!comp) {
4128
+ warn(`Async component loader resolved to undefined. ` +
4129
+ `If you are using retry(), make sure to return its return value.`);
4130
+ }
4131
+ // interop module default
4132
+ if (comp &&
4133
+ (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
4134
+ comp = comp.default;
4135
+ }
4136
+ if (comp && !isObject(comp) && !isFunction(comp)) {
4137
+ throw new Error(`Invalid async component load result: ${comp}`);
4138
+ }
4139
+ return comp;
4140
+ })));
4141
+ };
4142
+ return () => {
4143
+ const component = load();
4144
+ return {
4145
+ component,
4146
+ delay,
4147
+ timeout,
4148
+ error: errorComponent,
4149
+ loading: loadingComponent
4150
+ };
4151
+ };
4152
+ }
4153
+
4081
4154
  function createLifeCycle(hookName) {
4082
4155
  return (fn, target = currentInstance) => {
4083
4156
  if (!target) {
@@ -4115,7 +4188,10 @@ const onServerPrefetch = createLifeCycle('serverPrefetch');
4115
4188
  const onRenderTracked = createLifeCycle('renderTracked');
4116
4189
  const onRenderTriggered = createLifeCycle('renderTriggered');
4117
4190
 
4118
- const version = '2.7.1';
4191
+ /**
4192
+ * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
4193
+ */
4194
+ const version = '2.7.4';
4119
4195
  /**
4120
4196
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
4121
4197
  */
@@ -4167,6 +4243,7 @@ var vca = /*#__PURE__*/Object.freeze({
4167
4243
  del: del,
4168
4244
  useCssModule: useCssModule,
4169
4245
  useCssVars: useCssVars,
4246
+ defineAsyncComponent: defineAsyncComponent,
4170
4247
  onBeforeMount: onBeforeMount,
4171
4248
  onMounted: onMounted,
4172
4249
  onBeforeUpdate: onBeforeUpdate,
@@ -4191,6 +4268,13 @@ let shouldObserve = true;
4191
4268
  function toggleObserving(value) {
4192
4269
  shouldObserve = value;
4193
4270
  }
4271
+ // ssr mock dep
4272
+ const mockDep = {
4273
+ notify: noop,
4274
+ depend: noop,
4275
+ addSub: noop,
4276
+ removeSub: noop
4277
+ };
4194
4278
  /**
4195
4279
  * Observer class that is attached to each observed
4196
4280
  * object. Once attached, the observer converts the target
@@ -4198,76 +4282,60 @@ function toggleObserving(value) {
4198
4282
  * collect dependencies and dispatch updates.
4199
4283
  */
4200
4284
  class Observer {
4201
- constructor(value, shallow = false) {
4285
+ constructor(value, shallow = false, mock = false) {
4202
4286
  this.value = value;
4203
4287
  this.shallow = shallow;
4288
+ this.mock = mock;
4204
4289
  // this.value = value
4205
- this.dep = new Dep();
4290
+ this.dep = mock ? mockDep : new Dep();
4206
4291
  this.vmCount = 0;
4207
4292
  def(value, '__ob__', this);
4208
4293
  if (isArray(value)) {
4209
- if (hasProto) {
4210
- protoAugment(value, arrayMethods);
4211
- }
4212
- else {
4213
- copyAugment(value, arrayMethods, arrayKeys);
4294
+ if (!mock) {
4295
+ if (hasProto) {
4296
+ value.__proto__ = arrayMethods;
4297
+ /* eslint-enable no-proto */
4298
+ }
4299
+ else {
4300
+ for (let i = 0, l = arrayKeys.length; i < l; i++) {
4301
+ const key = arrayKeys[i];
4302
+ def(value, key, arrayMethods[key]);
4303
+ }
4304
+ }
4214
4305
  }
4215
4306
  if (!shallow) {
4216
4307
  this.observeArray(value);
4217
4308
  }
4218
4309
  }
4219
4310
  else {
4220
- this.walk(value, shallow);
4221
- }
4222
- }
4223
- /**
4224
- * Walk through all properties and convert them into
4225
- * getter/setters. This method should only be called when
4226
- * value type is Object.
4227
- */
4228
- walk(obj, shallow) {
4229
- const keys = Object.keys(obj);
4230
- for (let i = 0; i < keys.length; i++) {
4231
- const key = keys[i];
4232
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
4311
+ /**
4312
+ * Walk through all properties and convert them into
4313
+ * getter/setters. This method should only be called when
4314
+ * value type is Object.
4315
+ */
4316
+ const keys = Object.keys(value);
4317
+ for (let i = 0; i < keys.length; i++) {
4318
+ const key = keys[i];
4319
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
4320
+ }
4233
4321
  }
4234
4322
  }
4235
4323
  /**
4236
4324
  * Observe a list of Array items.
4237
4325
  */
4238
- observeArray(items) {
4239
- for (let i = 0, l = items.length; i < l; i++) {
4240
- observe(items[i]);
4326
+ observeArray(value) {
4327
+ for (let i = 0, l = value.length; i < l; i++) {
4328
+ observe(value[i], false, this.mock);
4241
4329
  }
4242
4330
  }
4243
4331
  }
4244
4332
  // helpers
4245
- /**
4246
- * Augment a target Object or Array by intercepting
4247
- * the prototype chain using __proto__
4248
- */
4249
- function protoAugment(target, src) {
4250
- /* eslint-disable no-proto */
4251
- target.__proto__ = src;
4252
- /* eslint-enable no-proto */
4253
- }
4254
- /**
4255
- * Augment a target Object or Array by defining
4256
- * hidden properties.
4257
- */
4258
- /* istanbul ignore next */
4259
- function copyAugment(target, src, keys) {
4260
- for (let i = 0, l = keys.length; i < l; i++) {
4261
- const key = keys[i];
4262
- def(target, key, src[key]);
4263
- }
4264
- }
4265
4333
  /**
4266
4334
  * Attempt to create an observer instance for a value,
4267
4335
  * returns the new observer if successfully observed,
4268
4336
  * or the existing observer if the value already has one.
4269
4337
  */
4270
- function observe(value, shallow) {
4338
+ function observe(value, shallow, ssrMockReactivity) {
4271
4339
  if (!isObject(value) || isRef(value) || value instanceof VNode) {
4272
4340
  return;
4273
4341
  }
@@ -4276,18 +4344,18 @@ function observe(value, shallow) {
4276
4344
  ob = value.__ob__;
4277
4345
  }
4278
4346
  else if (shouldObserve &&
4279
- !isServerRendering() &&
4347
+ (ssrMockReactivity || !isServerRendering()) &&
4280
4348
  (isArray(value) || isPlainObject(value)) &&
4281
4349
  Object.isExtensible(value) &&
4282
- !value.__v_skip) {
4283
- ob = new Observer(value, shallow);
4350
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
4351
+ ob = new Observer(value, shallow, ssrMockReactivity);
4284
4352
  }
4285
4353
  return ob;
4286
4354
  }
4287
4355
  /**
4288
4356
  * Define a reactive property on an Object.
4289
4357
  */
4290
- function defineReactive(obj, key, val, customSetter, shallow) {
4358
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
4291
4359
  const dep = new Dep();
4292
4360
  const property = Object.getOwnPropertyDescriptor(obj, key);
4293
4361
  if (property && property.configurable === false) {
@@ -4300,7 +4368,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4300
4368
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
4301
4369
  val = obj[key];
4302
4370
  }
4303
- let childOb = !shallow && observe(val);
4371
+ let childOb = !shallow && observe(val, false, mock);
4304
4372
  Object.defineProperty(obj, key, {
4305
4373
  enumerable: true,
4306
4374
  configurable: true,
@@ -4345,7 +4413,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4345
4413
  else {
4346
4414
  val = newVal;
4347
4415
  }
4348
- childOb = !shallow && observe(newVal);
4416
+ childOb = !shallow && observe(newVal, false, mock);
4349
4417
  {
4350
4418
  dep.notify({
4351
4419
  type: "set" /* TriggerOpTypes.SET */,
@@ -4367,16 +4435,20 @@ function set(target, key, val) {
4367
4435
  warn(`Set operation on key "${key}" failed: target is readonly.`);
4368
4436
  return;
4369
4437
  }
4438
+ const ob = target.__ob__;
4370
4439
  if (isArray(target) && isValidArrayIndex(key)) {
4371
4440
  target.length = Math.max(target.length, key);
4372
4441
  target.splice(key, 1, val);
4442
+ // when mocking for SSR, array methods are not hijacked
4443
+ if (ob && !ob.shallow && ob.mock) {
4444
+ observe(val, false, true);
4445
+ }
4373
4446
  return val;
4374
4447
  }
4375
4448
  if (key in target && !(key in Object.prototype)) {
4376
4449
  target[key] = val;
4377
4450
  return val;
4378
4451
  }
4379
- const ob = target.__ob__;
4380
4452
  if (target._isVue || (ob && ob.vmCount)) {
4381
4453
  warn('Avoid adding reactive properties to a Vue instance or its root $data ' +
4382
4454
  'at runtime - declare it upfront in the data option.');
@@ -4386,7 +4458,7 @@ function set(target, key, val) {
4386
4458
  target[key] = val;
4387
4459
  return val;
4388
4460
  }
4389
- defineReactive(ob.value, key, val);
4461
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
4390
4462
  {
4391
4463
  ob.dep.notify({
4392
4464
  type: "add" /* TriggerOpTypes.ADD */,
@@ -6980,7 +7052,7 @@ function normalizeDirectives(dirs, vm) {
6980
7052
  }
6981
7053
  res[getRawDirName(dir)] = dir;
6982
7054
  if (vm._setupState && vm._setupState.__sfc) {
6983
- dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name);
7055
+ dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
6984
7056
  }
6985
7057
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
6986
7058
  }