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
  */
@@ -334,7 +334,9 @@ const LIFECYCLE_HOOKS = [
334
334
  'activated',
335
335
  'deactivated',
336
336
  'errorCaptured',
337
- 'serverPrefetch'
337
+ 'serverPrefetch',
338
+ 'renderTracked',
339
+ 'renderTriggered'
338
340
  ];
339
341
 
340
342
  var config = {
@@ -842,7 +844,7 @@ function makeReactive(target, shallow) {
842
844
  warn$2(`Target is already a ${existingOb.shallow ? `` : `non-`}shallow reactive object, and cannot be converted to ${shallow ? `` : `non-`}shallow.`);
843
845
  }
844
846
  }
845
- const ob = observe(target, shallow);
847
+ const ob = observe(target, shallow, isServerRendering() /* ssr mock reactivity */);
846
848
  if (!ob) {
847
849
  if (target == null || isPrimitive(target)) {
848
850
  warn$2(`value cannot be made reactive: ${String(target)}`);
@@ -904,7 +906,7 @@ function createRef(rawValue, shallow) {
904
906
  const ref = {};
905
907
  def(ref, RefFlag, true);
906
908
  def(ref, "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */, true);
907
- ref.dep = defineReactive(ref, 'value', rawValue, null, shallow);
909
+ def(ref, 'dep', defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering()));
908
910
  return ref;
909
911
  }
910
912
  function triggerRef(ref) {
@@ -2524,7 +2526,7 @@ function renderStatic(index, isInFor) {
2524
2526
  return tree;
2525
2527
  }
2526
2528
  // otherwise, render a fresh tree.
2527
- tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, null, this // for render fns generated for functional component templates
2529
+ tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, this._c, this // for render fns generated for functional component templates
2528
2530
  );
2529
2531
  markStatic$1(tree, `__static__${index}`, false);
2530
2532
  return tree;
@@ -4297,8 +4299,8 @@ function doWatch(source, cb, { immediate, deep, flush = 'pre', onTrack, onTrigge
4297
4299
  else {
4298
4300
  // pre
4299
4301
  watcher.update = () => {
4300
- if (instance && instance === currentInstance) {
4301
- // pre-watcher triggered inside setup()
4302
+ if (instance && instance === currentInstance && !instance._isMounted) {
4303
+ // pre-watcher triggered before
4302
4304
  const buffer = instance._preWatchers || (instance._preWatchers = []);
4303
4305
  if (buffer.indexOf(watcher) < 0)
4304
4306
  buffer.push(watcher);
@@ -4558,6 +4560,77 @@ function useCssVars(getter) {
4558
4560
  });
4559
4561
  }
4560
4562
 
4563
+ /**
4564
+ * v3-compatible async component API.
4565
+ * @internal the type is manually declared in <root>/types/v3-define-async-component.d.ts
4566
+ * because it relies on existing manual types
4567
+ */
4568
+ function defineAsyncComponent(source) {
4569
+ if (isFunction(source)) {
4570
+ source = { loader: source };
4571
+ }
4572
+ const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
4573
+ suspensible = false, // in Vue 3 default is true
4574
+ onError: userOnError } = source;
4575
+ if (suspensible) {
4576
+ warn$2(`The suspensiblbe option for async components is not supported in Vue2. It is ignored.`);
4577
+ }
4578
+ let pendingRequest = null;
4579
+ let retries = 0;
4580
+ const retry = () => {
4581
+ retries++;
4582
+ pendingRequest = null;
4583
+ return load();
4584
+ };
4585
+ const load = () => {
4586
+ let thisRequest;
4587
+ return (pendingRequest ||
4588
+ (thisRequest = pendingRequest =
4589
+ loader()
4590
+ .catch(err => {
4591
+ err = err instanceof Error ? err : new Error(String(err));
4592
+ if (userOnError) {
4593
+ return new Promise((resolve, reject) => {
4594
+ const userRetry = () => resolve(retry());
4595
+ const userFail = () => reject(err);
4596
+ userOnError(err, userRetry, userFail, retries + 1);
4597
+ });
4598
+ }
4599
+ else {
4600
+ throw err;
4601
+ }
4602
+ })
4603
+ .then((comp) => {
4604
+ if (thisRequest !== pendingRequest && pendingRequest) {
4605
+ return pendingRequest;
4606
+ }
4607
+ if (!comp) {
4608
+ warn$2(`Async component loader resolved to undefined. ` +
4609
+ `If you are using retry(), make sure to return its return value.`);
4610
+ }
4611
+ // interop module default
4612
+ if (comp &&
4613
+ (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
4614
+ comp = comp.default;
4615
+ }
4616
+ if (comp && !isObject(comp) && !isFunction(comp)) {
4617
+ throw new Error(`Invalid async component load result: ${comp}`);
4618
+ }
4619
+ return comp;
4620
+ })));
4621
+ };
4622
+ return () => {
4623
+ const component = load();
4624
+ return {
4625
+ component,
4626
+ delay,
4627
+ timeout,
4628
+ error: errorComponent,
4629
+ loading: loadingComponent
4630
+ };
4631
+ };
4632
+ }
4633
+
4561
4634
  function createLifeCycle(hookName) {
4562
4635
  return (fn, target = currentInstance) => {
4563
4636
  if (!target) {
@@ -4595,7 +4668,10 @@ const onServerPrefetch = createLifeCycle('serverPrefetch');
4595
4668
  const onRenderTracked = createLifeCycle('renderTracked');
4596
4669
  const onRenderTriggered = createLifeCycle('renderTriggered');
4597
4670
 
4598
- const version = '2.7.1';
4671
+ /**
4672
+ * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
4673
+ */
4674
+ const version = '2.7.4';
4599
4675
  /**
4600
4676
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
4601
4677
  */
@@ -4613,6 +4689,13 @@ let shouldObserve = true;
4613
4689
  function toggleObserving(value) {
4614
4690
  shouldObserve = value;
4615
4691
  }
4692
+ // ssr mock dep
4693
+ const mockDep = {
4694
+ notify: noop,
4695
+ depend: noop,
4696
+ addSub: noop,
4697
+ removeSub: noop
4698
+ };
4616
4699
  /**
4617
4700
  * Observer class that is attached to each observed
4618
4701
  * object. Once attached, the observer converts the target
@@ -4620,76 +4703,60 @@ function toggleObserving(value) {
4620
4703
  * collect dependencies and dispatch updates.
4621
4704
  */
4622
4705
  class Observer {
4623
- constructor(value, shallow = false) {
4706
+ constructor(value, shallow = false, mock = false) {
4624
4707
  this.value = value;
4625
4708
  this.shallow = shallow;
4709
+ this.mock = mock;
4626
4710
  // this.value = value
4627
- this.dep = new Dep();
4711
+ this.dep = mock ? mockDep : new Dep();
4628
4712
  this.vmCount = 0;
4629
4713
  def(value, '__ob__', this);
4630
4714
  if (isArray(value)) {
4631
- if (hasProto) {
4632
- protoAugment(value, arrayMethods);
4633
- }
4634
- else {
4635
- copyAugment(value, arrayMethods, arrayKeys);
4715
+ if (!mock) {
4716
+ if (hasProto) {
4717
+ value.__proto__ = arrayMethods;
4718
+ /* eslint-enable no-proto */
4719
+ }
4720
+ else {
4721
+ for (let i = 0, l = arrayKeys.length; i < l; i++) {
4722
+ const key = arrayKeys[i];
4723
+ def(value, key, arrayMethods[key]);
4724
+ }
4725
+ }
4636
4726
  }
4637
4727
  if (!shallow) {
4638
4728
  this.observeArray(value);
4639
4729
  }
4640
4730
  }
4641
4731
  else {
4642
- this.walk(value, shallow);
4643
- }
4644
- }
4645
- /**
4646
- * Walk through all properties and convert them into
4647
- * getter/setters. This method should only be called when
4648
- * value type is Object.
4649
- */
4650
- walk(obj, shallow) {
4651
- const keys = Object.keys(obj);
4652
- for (let i = 0; i < keys.length; i++) {
4653
- const key = keys[i];
4654
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
4732
+ /**
4733
+ * Walk through all properties and convert them into
4734
+ * getter/setters. This method should only be called when
4735
+ * value type is Object.
4736
+ */
4737
+ const keys = Object.keys(value);
4738
+ for (let i = 0; i < keys.length; i++) {
4739
+ const key = keys[i];
4740
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
4741
+ }
4655
4742
  }
4656
4743
  }
4657
4744
  /**
4658
4745
  * Observe a list of Array items.
4659
4746
  */
4660
- observeArray(items) {
4661
- for (let i = 0, l = items.length; i < l; i++) {
4662
- observe(items[i]);
4747
+ observeArray(value) {
4748
+ for (let i = 0, l = value.length; i < l; i++) {
4749
+ observe(value[i], false, this.mock);
4663
4750
  }
4664
4751
  }
4665
4752
  }
4666
4753
  // helpers
4667
- /**
4668
- * Augment a target Object or Array by intercepting
4669
- * the prototype chain using __proto__
4670
- */
4671
- function protoAugment(target, src) {
4672
- /* eslint-disable no-proto */
4673
- target.__proto__ = src;
4674
- /* eslint-enable no-proto */
4675
- }
4676
- /**
4677
- * Augment a target Object or Array by defining
4678
- * hidden properties.
4679
- */
4680
- /* istanbul ignore next */
4681
- function copyAugment(target, src, keys) {
4682
- for (let i = 0, l = keys.length; i < l; i++) {
4683
- const key = keys[i];
4684
- def(target, key, src[key]);
4685
- }
4686
- }
4687
4754
  /**
4688
4755
  * Attempt to create an observer instance for a value,
4689
4756
  * returns the new observer if successfully observed,
4690
4757
  * or the existing observer if the value already has one.
4691
4758
  */
4692
- function observe(value, shallow) {
4759
+ function observe(value, shallow, ssrMockReactivity) {
4693
4760
  if (!isObject(value) || isRef(value) || value instanceof VNode) {
4694
4761
  return;
4695
4762
  }
@@ -4698,18 +4765,18 @@ function observe(value, shallow) {
4698
4765
  ob = value.__ob__;
4699
4766
  }
4700
4767
  else if (shouldObserve &&
4701
- !isServerRendering() &&
4768
+ (ssrMockReactivity || !isServerRendering()) &&
4702
4769
  (isArray(value) || isPlainObject(value)) &&
4703
4770
  Object.isExtensible(value) &&
4704
- !value.__v_skip) {
4705
- ob = new Observer(value, shallow);
4771
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
4772
+ ob = new Observer(value, shallow, ssrMockReactivity);
4706
4773
  }
4707
4774
  return ob;
4708
4775
  }
4709
4776
  /**
4710
4777
  * Define a reactive property on an Object.
4711
4778
  */
4712
- function defineReactive(obj, key, val, customSetter, shallow) {
4779
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
4713
4780
  const dep = new Dep();
4714
4781
  const property = Object.getOwnPropertyDescriptor(obj, key);
4715
4782
  if (property && property.configurable === false) {
@@ -4722,7 +4789,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4722
4789
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
4723
4790
  val = obj[key];
4724
4791
  }
4725
- let childOb = !shallow && observe(val);
4792
+ let childOb = !shallow && observe(val, false, mock);
4726
4793
  Object.defineProperty(obj, key, {
4727
4794
  enumerable: true,
4728
4795
  configurable: true,
@@ -4767,7 +4834,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4767
4834
  else {
4768
4835
  val = newVal;
4769
4836
  }
4770
- childOb = !shallow && observe(newVal);
4837
+ childOb = !shallow && observe(newVal, false, mock);
4771
4838
  {
4772
4839
  dep.notify({
4773
4840
  type: "set" /* TriggerOpTypes.SET */,
@@ -4789,16 +4856,20 @@ function set(target, key, val) {
4789
4856
  warn$2(`Set operation on key "${key}" failed: target is readonly.`);
4790
4857
  return;
4791
4858
  }
4859
+ const ob = target.__ob__;
4792
4860
  if (isArray(target) && isValidArrayIndex(key)) {
4793
4861
  target.length = Math.max(target.length, key);
4794
4862
  target.splice(key, 1, val);
4863
+ // when mocking for SSR, array methods are not hijacked
4864
+ if (ob && !ob.shallow && ob.mock) {
4865
+ observe(val, false, true);
4866
+ }
4795
4867
  return val;
4796
4868
  }
4797
4869
  if (key in target && !(key in Object.prototype)) {
4798
4870
  target[key] = val;
4799
4871
  return val;
4800
4872
  }
4801
- const ob = target.__ob__;
4802
4873
  if (target._isVue || (ob && ob.vmCount)) {
4803
4874
  warn$2('Avoid adding reactive properties to a Vue instance or its root $data ' +
4804
4875
  'at runtime - declare it upfront in the data option.');
@@ -4808,7 +4879,7 @@ function set(target, key, val) {
4808
4879
  target[key] = val;
4809
4880
  return val;
4810
4881
  }
4811
- defineReactive(ob.value, key, val);
4882
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
4812
4883
  {
4813
4884
  ob.dep.notify({
4814
4885
  type: "add" /* TriggerOpTypes.ADD */,
@@ -6925,7 +6996,7 @@ function normalizeDirectives(dirs, vm) {
6925
6996
  }
6926
6997
  res[getRawDirName(dir)] = dir;
6927
6998
  if (vm._setupState && vm._setupState.__sfc) {
6928
- dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name);
6999
+ dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
6929
7000
  }
6930
7001
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
6931
7002
  }
@@ -11503,4 +11574,4 @@ function getOuterHTML(el) {
11503
11574
  }
11504
11575
  Vue.compile = compileToFunctions;
11505
11576
 
11506
- export { EffectScope, computed, customRef, Vue as default, defineComponent, del, effectScope, getCurrentInstance, getCurrentScope, h, inject, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, mergeDefaults, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, provide, proxyRefs, reactive, readonly, ref$1 as ref, set, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSlots, version, watch, watchEffect, watchPostEffect, watchSyncEffect };
11577
+ export { EffectScope, computed, customRef, Vue as default, defineAsyncComponent, defineComponent, del, effectScope, getCurrentInstance, getCurrentScope, h, inject, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, mergeDefaults, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, provide, proxyRefs, reactive, readonly, ref$1 as ref, set, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSlots, version, watch, watchEffect, watchPostEffect, watchSyncEffect };