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
  */
@@ -336,7 +336,9 @@ const LIFECYCLE_HOOKS = [
336
336
  'activated',
337
337
  'deactivated',
338
338
  'errorCaptured',
339
- 'serverPrefetch'
339
+ 'serverPrefetch',
340
+ 'renderTracked',
341
+ 'renderTriggered'
340
342
  ];
341
343
 
342
344
  var config = {
@@ -844,7 +846,7 @@ function makeReactive(target, shallow) {
844
846
  warn$2(`Target is already a ${existingOb.shallow ? `` : `non-`}shallow reactive object, and cannot be converted to ${shallow ? `` : `non-`}shallow.`);
845
847
  }
846
848
  }
847
- const ob = observe(target, shallow);
849
+ const ob = observe(target, shallow, isServerRendering() /* ssr mock reactivity */);
848
850
  if (!ob) {
849
851
  if (target == null || isPrimitive(target)) {
850
852
  warn$2(`value cannot be made reactive: ${String(target)}`);
@@ -906,7 +908,7 @@ function createRef(rawValue, shallow) {
906
908
  const ref = {};
907
909
  def(ref, RefFlag, true);
908
910
  def(ref, "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */, true);
909
- ref.dep = defineReactive(ref, 'value', rawValue, null, shallow);
911
+ def(ref, 'dep', defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering()));
910
912
  return ref;
911
913
  }
912
914
  function triggerRef(ref) {
@@ -2526,7 +2528,7 @@ function renderStatic(index, isInFor) {
2526
2528
  return tree;
2527
2529
  }
2528
2530
  // otherwise, render a fresh tree.
2529
- tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, null, this // for render fns generated for functional component templates
2531
+ tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, this._c, this // for render fns generated for functional component templates
2530
2532
  );
2531
2533
  markStatic$1(tree, `__static__${index}`, false);
2532
2534
  return tree;
@@ -4299,8 +4301,8 @@ function doWatch(source, cb, { immediate, deep, flush = 'pre', onTrack, onTrigge
4299
4301
  else {
4300
4302
  // pre
4301
4303
  watcher.update = () => {
4302
- if (instance && instance === currentInstance) {
4303
- // pre-watcher triggered inside setup()
4304
+ if (instance && instance === currentInstance && !instance._isMounted) {
4305
+ // pre-watcher triggered before
4304
4306
  const buffer = instance._preWatchers || (instance._preWatchers = []);
4305
4307
  if (buffer.indexOf(watcher) < 0)
4306
4308
  buffer.push(watcher);
@@ -4566,6 +4568,77 @@ function useCssVars(getter) {
4566
4568
  });
4567
4569
  }
4568
4570
 
4571
+ /**
4572
+ * v3-compatible async component API.
4573
+ * @internal the type is manually declared in <root>/types/v3-define-async-component.d.ts
4574
+ * because it relies on existing manual types
4575
+ */
4576
+ function defineAsyncComponent(source) {
4577
+ if (isFunction(source)) {
4578
+ source = { loader: source };
4579
+ }
4580
+ const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
4581
+ suspensible = false, // in Vue 3 default is true
4582
+ onError: userOnError } = source;
4583
+ if (suspensible) {
4584
+ warn$2(`The suspensiblbe option for async components is not supported in Vue2. It is ignored.`);
4585
+ }
4586
+ let pendingRequest = null;
4587
+ let retries = 0;
4588
+ const retry = () => {
4589
+ retries++;
4590
+ pendingRequest = null;
4591
+ return load();
4592
+ };
4593
+ const load = () => {
4594
+ let thisRequest;
4595
+ return (pendingRequest ||
4596
+ (thisRequest = pendingRequest =
4597
+ loader()
4598
+ .catch(err => {
4599
+ err = err instanceof Error ? err : new Error(String(err));
4600
+ if (userOnError) {
4601
+ return new Promise((resolve, reject) => {
4602
+ const userRetry = () => resolve(retry());
4603
+ const userFail = () => reject(err);
4604
+ userOnError(err, userRetry, userFail, retries + 1);
4605
+ });
4606
+ }
4607
+ else {
4608
+ throw err;
4609
+ }
4610
+ })
4611
+ .then((comp) => {
4612
+ if (thisRequest !== pendingRequest && pendingRequest) {
4613
+ return pendingRequest;
4614
+ }
4615
+ if (!comp) {
4616
+ warn$2(`Async component loader resolved to undefined. ` +
4617
+ `If you are using retry(), make sure to return its return value.`);
4618
+ }
4619
+ // interop module default
4620
+ if (comp &&
4621
+ (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
4622
+ comp = comp.default;
4623
+ }
4624
+ if (comp && !isObject(comp) && !isFunction(comp)) {
4625
+ throw new Error(`Invalid async component load result: ${comp}`);
4626
+ }
4627
+ return comp;
4628
+ })));
4629
+ };
4630
+ return () => {
4631
+ const component = load();
4632
+ return {
4633
+ component,
4634
+ delay,
4635
+ timeout,
4636
+ error: errorComponent,
4637
+ loading: loadingComponent
4638
+ };
4639
+ };
4640
+ }
4641
+
4569
4642
  function createLifeCycle(hookName) {
4570
4643
  return (fn, target = currentInstance) => {
4571
4644
  if (!target) {
@@ -4603,7 +4676,10 @@ const onServerPrefetch = createLifeCycle('serverPrefetch');
4603
4676
  const onRenderTracked = createLifeCycle('renderTracked');
4604
4677
  const onRenderTriggered = createLifeCycle('renderTriggered');
4605
4678
 
4606
- const version = '2.7.1';
4679
+ /**
4680
+ * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
4681
+ */
4682
+ const version = '2.7.4';
4607
4683
  /**
4608
4684
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
4609
4685
  */
@@ -4655,6 +4731,7 @@ var vca = /*#__PURE__*/Object.freeze({
4655
4731
  del: del,
4656
4732
  useCssModule: useCssModule,
4657
4733
  useCssVars: useCssVars,
4734
+ defineAsyncComponent: defineAsyncComponent,
4658
4735
  onBeforeMount: onBeforeMount,
4659
4736
  onMounted: onMounted,
4660
4737
  onBeforeUpdate: onBeforeUpdate,
@@ -4679,6 +4756,13 @@ let shouldObserve = true;
4679
4756
  function toggleObserving(value) {
4680
4757
  shouldObserve = value;
4681
4758
  }
4759
+ // ssr mock dep
4760
+ const mockDep = {
4761
+ notify: noop,
4762
+ depend: noop,
4763
+ addSub: noop,
4764
+ removeSub: noop
4765
+ };
4682
4766
  /**
4683
4767
  * Observer class that is attached to each observed
4684
4768
  * object. Once attached, the observer converts the target
@@ -4686,76 +4770,60 @@ function toggleObserving(value) {
4686
4770
  * collect dependencies and dispatch updates.
4687
4771
  */
4688
4772
  class Observer {
4689
- constructor(value, shallow = false) {
4773
+ constructor(value, shallow = false, mock = false) {
4690
4774
  this.value = value;
4691
4775
  this.shallow = shallow;
4776
+ this.mock = mock;
4692
4777
  // this.value = value
4693
- this.dep = new Dep();
4778
+ this.dep = mock ? mockDep : new Dep();
4694
4779
  this.vmCount = 0;
4695
4780
  def(value, '__ob__', this);
4696
4781
  if (isArray(value)) {
4697
- if (hasProto) {
4698
- protoAugment(value, arrayMethods);
4699
- }
4700
- else {
4701
- copyAugment(value, arrayMethods, arrayKeys);
4782
+ if (!mock) {
4783
+ if (hasProto) {
4784
+ value.__proto__ = arrayMethods;
4785
+ /* eslint-enable no-proto */
4786
+ }
4787
+ else {
4788
+ for (let i = 0, l = arrayKeys.length; i < l; i++) {
4789
+ const key = arrayKeys[i];
4790
+ def(value, key, arrayMethods[key]);
4791
+ }
4792
+ }
4702
4793
  }
4703
4794
  if (!shallow) {
4704
4795
  this.observeArray(value);
4705
4796
  }
4706
4797
  }
4707
4798
  else {
4708
- this.walk(value, shallow);
4709
- }
4710
- }
4711
- /**
4712
- * Walk through all properties and convert them into
4713
- * getter/setters. This method should only be called when
4714
- * value type is Object.
4715
- */
4716
- walk(obj, shallow) {
4717
- const keys = Object.keys(obj);
4718
- for (let i = 0; i < keys.length; i++) {
4719
- const key = keys[i];
4720
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
4799
+ /**
4800
+ * Walk through all properties and convert them into
4801
+ * getter/setters. This method should only be called when
4802
+ * value type is Object.
4803
+ */
4804
+ const keys = Object.keys(value);
4805
+ for (let i = 0; i < keys.length; i++) {
4806
+ const key = keys[i];
4807
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
4808
+ }
4721
4809
  }
4722
4810
  }
4723
4811
  /**
4724
4812
  * Observe a list of Array items.
4725
4813
  */
4726
- observeArray(items) {
4727
- for (let i = 0, l = items.length; i < l; i++) {
4728
- observe(items[i]);
4814
+ observeArray(value) {
4815
+ for (let i = 0, l = value.length; i < l; i++) {
4816
+ observe(value[i], false, this.mock);
4729
4817
  }
4730
4818
  }
4731
4819
  }
4732
4820
  // helpers
4733
- /**
4734
- * Augment a target Object or Array by intercepting
4735
- * the prototype chain using __proto__
4736
- */
4737
- function protoAugment(target, src) {
4738
- /* eslint-disable no-proto */
4739
- target.__proto__ = src;
4740
- /* eslint-enable no-proto */
4741
- }
4742
- /**
4743
- * Augment a target Object or Array by defining
4744
- * hidden properties.
4745
- */
4746
- /* istanbul ignore next */
4747
- function copyAugment(target, src, keys) {
4748
- for (let i = 0, l = keys.length; i < l; i++) {
4749
- const key = keys[i];
4750
- def(target, key, src[key]);
4751
- }
4752
- }
4753
4821
  /**
4754
4822
  * Attempt to create an observer instance for a value,
4755
4823
  * returns the new observer if successfully observed,
4756
4824
  * or the existing observer if the value already has one.
4757
4825
  */
4758
- function observe(value, shallow) {
4826
+ function observe(value, shallow, ssrMockReactivity) {
4759
4827
  if (!isObject(value) || isRef(value) || value instanceof VNode) {
4760
4828
  return;
4761
4829
  }
@@ -4764,18 +4832,18 @@ function observe(value, shallow) {
4764
4832
  ob = value.__ob__;
4765
4833
  }
4766
4834
  else if (shouldObserve &&
4767
- !isServerRendering() &&
4835
+ (ssrMockReactivity || !isServerRendering()) &&
4768
4836
  (isArray(value) || isPlainObject(value)) &&
4769
4837
  Object.isExtensible(value) &&
4770
- !value.__v_skip) {
4771
- ob = new Observer(value, shallow);
4838
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
4839
+ ob = new Observer(value, shallow, ssrMockReactivity);
4772
4840
  }
4773
4841
  return ob;
4774
4842
  }
4775
4843
  /**
4776
4844
  * Define a reactive property on an Object.
4777
4845
  */
4778
- function defineReactive(obj, key, val, customSetter, shallow) {
4846
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
4779
4847
  const dep = new Dep();
4780
4848
  const property = Object.getOwnPropertyDescriptor(obj, key);
4781
4849
  if (property && property.configurable === false) {
@@ -4788,7 +4856,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4788
4856
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
4789
4857
  val = obj[key];
4790
4858
  }
4791
- let childOb = !shallow && observe(val);
4859
+ let childOb = !shallow && observe(val, false, mock);
4792
4860
  Object.defineProperty(obj, key, {
4793
4861
  enumerable: true,
4794
4862
  configurable: true,
@@ -4833,7 +4901,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4833
4901
  else {
4834
4902
  val = newVal;
4835
4903
  }
4836
- childOb = !shallow && observe(newVal);
4904
+ childOb = !shallow && observe(newVal, false, mock);
4837
4905
  {
4838
4906
  dep.notify({
4839
4907
  type: "set" /* TriggerOpTypes.SET */,
@@ -4855,16 +4923,20 @@ function set(target, key, val) {
4855
4923
  warn$2(`Set operation on key "${key}" failed: target is readonly.`);
4856
4924
  return;
4857
4925
  }
4926
+ const ob = target.__ob__;
4858
4927
  if (isArray(target) && isValidArrayIndex(key)) {
4859
4928
  target.length = Math.max(target.length, key);
4860
4929
  target.splice(key, 1, val);
4930
+ // when mocking for SSR, array methods are not hijacked
4931
+ if (ob && !ob.shallow && ob.mock) {
4932
+ observe(val, false, true);
4933
+ }
4861
4934
  return val;
4862
4935
  }
4863
4936
  if (key in target && !(key in Object.prototype)) {
4864
4937
  target[key] = val;
4865
4938
  return val;
4866
4939
  }
4867
- const ob = target.__ob__;
4868
4940
  if (target._isVue || (ob && ob.vmCount)) {
4869
4941
  warn$2('Avoid adding reactive properties to a Vue instance or its root $data ' +
4870
4942
  'at runtime - declare it upfront in the data option.');
@@ -4874,7 +4946,7 @@ function set(target, key, val) {
4874
4946
  target[key] = val;
4875
4947
  return val;
4876
4948
  }
4877
- defineReactive(ob.value, key, val);
4949
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
4878
4950
  {
4879
4951
  ob.dep.notify({
4880
4952
  type: "add" /* TriggerOpTypes.ADD */,
@@ -6991,7 +7063,7 @@ function normalizeDirectives(dirs, vm) {
6991
7063
  }
6992
7064
  res[getRawDirName(dir)] = dir;
6993
7065
  if (vm._setupState && vm._setupState.__sfc) {
6994
- dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name);
7066
+ dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
6995
7067
  }
6996
7068
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
6997
7069
  }