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
package/dist/vue.esm.js CHANGED
@@ -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 @@ var 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 = {
@@ -889,7 +891,7 @@ function makeReactive(target, shallow) {
889
891
  warn$2("Target is already a ".concat(existingOb.shallow ? "" : "non-", "shallow reactive object, and cannot be converted to ").concat(shallow ? "" : "non-", "shallow."));
890
892
  }
891
893
  }
892
- var ob = observe(target, shallow);
894
+ var ob = observe(target, shallow, isServerRendering() /* ssr mock reactivity */);
893
895
  if (process.env.NODE_ENV !== 'production' && !ob) {
894
896
  if (target == null || isPrimitive(target)) {
895
897
  warn$2("value cannot be made reactive: ".concat(String(target)));
@@ -951,7 +953,7 @@ function createRef(rawValue, shallow) {
951
953
  var ref = {};
952
954
  def(ref, RefFlag, true);
953
955
  def(ref, "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */, true);
954
- ref.dep = defineReactive(ref, 'value', rawValue, null, shallow);
956
+ def(ref, 'dep', defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering()));
955
957
  return ref;
956
958
  }
957
959
  function triggerRef(ref) {
@@ -2606,7 +2608,7 @@ function renderStatic(index, isInFor) {
2606
2608
  return tree;
2607
2609
  }
2608
2610
  // otherwise, render a fresh tree.
2609
- tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, null, this // for render fns generated for functional component templates
2611
+ tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, this._c, this // for render fns generated for functional component templates
2610
2612
  );
2611
2613
  markStatic$1(tree, "__static__".concat(index), false);
2612
2614
  return tree;
@@ -4402,8 +4404,8 @@ function doWatch(source, cb, _a) {
4402
4404
  else {
4403
4405
  // pre
4404
4406
  watcher.update = function () {
4405
- if (instance && instance === currentInstance) {
4406
- // pre-watcher triggered inside setup()
4407
+ if (instance && instance === currentInstance && !instance._isMounted) {
4408
+ // pre-watcher triggered before
4407
4409
  var buffer = instance._preWatchers || (instance._preWatchers = []);
4408
4410
  if (buffer.indexOf(watcher) < 0)
4409
4411
  buffer.push(watcher);
@@ -4673,6 +4675,78 @@ function useCssVars(getter) {
4673
4675
  });
4674
4676
  }
4675
4677
 
4678
+ /**
4679
+ * v3-compatible async component API.
4680
+ * @internal the type is manually declared in <root>/types/v3-define-async-component.d.ts
4681
+ * because it relies on existing manual types
4682
+ */
4683
+ function defineAsyncComponent(source) {
4684
+ if (isFunction(source)) {
4685
+ source = { loader: source };
4686
+ }
4687
+ var loader = source.loader, loadingComponent = source.loadingComponent, errorComponent = source.errorComponent, _a = source.delay, delay = _a === void 0 ? 200 : _a, timeout = source.timeout, // undefined = never times out
4688
+ _b = source.suspensible, // undefined = never times out
4689
+ suspensible = _b === void 0 ? false : _b, // in Vue 3 default is true
4690
+ userOnError = source.onError;
4691
+ if (process.env.NODE_ENV !== 'production' && suspensible) {
4692
+ warn$2("The suspensiblbe option for async components is not supported in Vue2. It is ignored.");
4693
+ }
4694
+ var pendingRequest = null;
4695
+ var retries = 0;
4696
+ var retry = function () {
4697
+ retries++;
4698
+ pendingRequest = null;
4699
+ return load();
4700
+ };
4701
+ var load = function () {
4702
+ var thisRequest;
4703
+ return (pendingRequest ||
4704
+ (thisRequest = pendingRequest =
4705
+ loader()
4706
+ .catch(function (err) {
4707
+ err = err instanceof Error ? err : new Error(String(err));
4708
+ if (userOnError) {
4709
+ return new Promise(function (resolve, reject) {
4710
+ var userRetry = function () { return resolve(retry()); };
4711
+ var userFail = function () { return reject(err); };
4712
+ userOnError(err, userRetry, userFail, retries + 1);
4713
+ });
4714
+ }
4715
+ else {
4716
+ throw err;
4717
+ }
4718
+ })
4719
+ .then(function (comp) {
4720
+ if (thisRequest !== pendingRequest && pendingRequest) {
4721
+ return pendingRequest;
4722
+ }
4723
+ if (process.env.NODE_ENV !== 'production' && !comp) {
4724
+ warn$2("Async component loader resolved to undefined. " +
4725
+ "If you are using retry(), make sure to return its return value.");
4726
+ }
4727
+ // interop module default
4728
+ if (comp &&
4729
+ (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
4730
+ comp = comp.default;
4731
+ }
4732
+ if (process.env.NODE_ENV !== 'production' && comp && !isObject(comp) && !isFunction(comp)) {
4733
+ throw new Error("Invalid async component load result: ".concat(comp));
4734
+ }
4735
+ return comp;
4736
+ })));
4737
+ };
4738
+ return function () {
4739
+ var component = load();
4740
+ return {
4741
+ component: component,
4742
+ delay: delay,
4743
+ timeout: timeout,
4744
+ error: errorComponent,
4745
+ loading: loadingComponent
4746
+ };
4747
+ };
4748
+ }
4749
+
4676
4750
  function createLifeCycle(hookName) {
4677
4751
  return function (fn, target) {
4678
4752
  if (target === void 0) { target = currentInstance; }
@@ -4712,7 +4786,10 @@ var onServerPrefetch = createLifeCycle('serverPrefetch');
4712
4786
  var onRenderTracked = createLifeCycle('renderTracked');
4713
4787
  var onRenderTriggered = createLifeCycle('renderTriggered');
4714
4788
 
4715
- var version = '2.7.1';
4789
+ /**
4790
+ * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
4791
+ */
4792
+ var version = '2.7.4';
4716
4793
  /**
4717
4794
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
4718
4795
  */
@@ -4730,6 +4807,13 @@ var shouldObserve = true;
4730
4807
  function toggleObserving(value) {
4731
4808
  shouldObserve = value;
4732
4809
  }
4810
+ // ssr mock dep
4811
+ var mockDep = {
4812
+ notify: noop,
4813
+ depend: noop,
4814
+ addSub: noop,
4815
+ removeSub: noop
4816
+ };
4733
4817
  /**
4734
4818
  * Observer class that is attached to each observed
4735
4819
  * object. Once attached, the observer converts the target
@@ -4737,78 +4821,63 @@ function toggleObserving(value) {
4737
4821
  * collect dependencies and dispatch updates.
4738
4822
  */
4739
4823
  var Observer = /** @class */ (function () {
4740
- function Observer(value, shallow) {
4824
+ function Observer(value, shallow, mock) {
4741
4825
  if (shallow === void 0) { shallow = false; }
4826
+ if (mock === void 0) { mock = false; }
4742
4827
  this.value = value;
4743
4828
  this.shallow = shallow;
4829
+ this.mock = mock;
4744
4830
  // this.value = value
4745
- this.dep = new Dep();
4831
+ this.dep = mock ? mockDep : new Dep();
4746
4832
  this.vmCount = 0;
4747
4833
  def(value, '__ob__', this);
4748
4834
  if (isArray(value)) {
4749
- if (hasProto) {
4750
- protoAugment(value, arrayMethods);
4751
- }
4752
- else {
4753
- copyAugment(value, arrayMethods, arrayKeys);
4835
+ if (!mock) {
4836
+ if (hasProto) {
4837
+ value.__proto__ = arrayMethods;
4838
+ /* eslint-enable no-proto */
4839
+ }
4840
+ else {
4841
+ for (var i = 0, l = arrayKeys.length; i < l; i++) {
4842
+ var key = arrayKeys[i];
4843
+ def(value, key, arrayMethods[key]);
4844
+ }
4845
+ }
4754
4846
  }
4755
4847
  if (!shallow) {
4756
4848
  this.observeArray(value);
4757
4849
  }
4758
4850
  }
4759
4851
  else {
4760
- this.walk(value, shallow);
4852
+ /**
4853
+ * Walk through all properties and convert them into
4854
+ * getter/setters. This method should only be called when
4855
+ * value type is Object.
4856
+ */
4857
+ var keys = Object.keys(value);
4858
+ for (var i = 0; i < keys.length; i++) {
4859
+ var key = keys[i];
4860
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
4861
+ }
4761
4862
  }
4762
4863
  }
4763
- /**
4764
- * Walk through all properties and convert them into
4765
- * getter/setters. This method should only be called when
4766
- * value type is Object.
4767
- */
4768
- Observer.prototype.walk = function (obj, shallow) {
4769
- var keys = Object.keys(obj);
4770
- for (var i = 0; i < keys.length; i++) {
4771
- var key = keys[i];
4772
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
4773
- }
4774
- };
4775
4864
  /**
4776
4865
  * Observe a list of Array items.
4777
4866
  */
4778
- Observer.prototype.observeArray = function (items) {
4779
- for (var i = 0, l = items.length; i < l; i++) {
4780
- observe(items[i]);
4867
+ Observer.prototype.observeArray = function (value) {
4868
+ for (var i = 0, l = value.length; i < l; i++) {
4869
+ observe(value[i], false, this.mock);
4781
4870
  }
4782
4871
  };
4783
4872
  return Observer;
4784
4873
  }());
4785
4874
  // helpers
4786
- /**
4787
- * Augment a target Object or Array by intercepting
4788
- * the prototype chain using __proto__
4789
- */
4790
- function protoAugment(target, src) {
4791
- /* eslint-disable no-proto */
4792
- target.__proto__ = src;
4793
- /* eslint-enable no-proto */
4794
- }
4795
- /**
4796
- * Augment a target Object or Array by defining
4797
- * hidden properties.
4798
- */
4799
- /* istanbul ignore next */
4800
- function copyAugment(target, src, keys) {
4801
- for (var i = 0, l = keys.length; i < l; i++) {
4802
- var key = keys[i];
4803
- def(target, key, src[key]);
4804
- }
4805
- }
4806
4875
  /**
4807
4876
  * Attempt to create an observer instance for a value,
4808
4877
  * returns the new observer if successfully observed,
4809
4878
  * or the existing observer if the value already has one.
4810
4879
  */
4811
- function observe(value, shallow) {
4880
+ function observe(value, shallow, ssrMockReactivity) {
4812
4881
  if (!isObject(value) || isRef(value) || value instanceof VNode) {
4813
4882
  return;
4814
4883
  }
@@ -4817,18 +4886,18 @@ function observe(value, shallow) {
4817
4886
  ob = value.__ob__;
4818
4887
  }
4819
4888
  else if (shouldObserve &&
4820
- !isServerRendering() &&
4889
+ (ssrMockReactivity || !isServerRendering()) &&
4821
4890
  (isArray(value) || isPlainObject(value)) &&
4822
4891
  Object.isExtensible(value) &&
4823
- !value.__v_skip) {
4824
- ob = new Observer(value, shallow);
4892
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
4893
+ ob = new Observer(value, shallow, ssrMockReactivity);
4825
4894
  }
4826
4895
  return ob;
4827
4896
  }
4828
4897
  /**
4829
4898
  * Define a reactive property on an Object.
4830
4899
  */
4831
- function defineReactive(obj, key, val, customSetter, shallow) {
4900
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
4832
4901
  var dep = new Dep();
4833
4902
  var property = Object.getOwnPropertyDescriptor(obj, key);
4834
4903
  if (property && property.configurable === false) {
@@ -4841,7 +4910,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4841
4910
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
4842
4911
  val = obj[key];
4843
4912
  }
4844
- var childOb = !shallow && observe(val);
4913
+ var childOb = !shallow && observe(val, false, mock);
4845
4914
  Object.defineProperty(obj, key, {
4846
4915
  enumerable: true,
4847
4916
  configurable: true,
@@ -4889,7 +4958,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4889
4958
  else {
4890
4959
  val = newVal;
4891
4960
  }
4892
- childOb = !shallow && observe(newVal);
4961
+ childOb = !shallow && observe(newVal, false, mock);
4893
4962
  if (process.env.NODE_ENV !== 'production') {
4894
4963
  dep.notify({
4895
4964
  type: "set" /* TriggerOpTypes.SET */,
@@ -4914,16 +4983,20 @@ function set(target, key, val) {
4914
4983
  process.env.NODE_ENV !== 'production' && warn$2("Set operation on key \"".concat(key, "\" failed: target is readonly."));
4915
4984
  return;
4916
4985
  }
4986
+ var ob = target.__ob__;
4917
4987
  if (isArray(target) && isValidArrayIndex(key)) {
4918
4988
  target.length = Math.max(target.length, key);
4919
4989
  target.splice(key, 1, val);
4990
+ // when mocking for SSR, array methods are not hijacked
4991
+ if (ob && !ob.shallow && ob.mock) {
4992
+ observe(val, false, true);
4993
+ }
4920
4994
  return val;
4921
4995
  }
4922
4996
  if (key in target && !(key in Object.prototype)) {
4923
4997
  target[key] = val;
4924
4998
  return val;
4925
4999
  }
4926
- var ob = target.__ob__;
4927
5000
  if (target._isVue || (ob && ob.vmCount)) {
4928
5001
  process.env.NODE_ENV !== 'production' &&
4929
5002
  warn$2('Avoid adding reactive properties to a Vue instance or its root $data ' +
@@ -4934,7 +5007,7 @@ function set(target, key, val) {
4934
5007
  target[key] = val;
4935
5008
  return val;
4936
5009
  }
4937
- defineReactive(ob.value, key, val);
5010
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
4938
5011
  if (process.env.NODE_ENV !== 'production') {
4939
5012
  ob.dep.notify({
4940
5013
  type: "add" /* TriggerOpTypes.ADD */,
@@ -7068,7 +7141,7 @@ function normalizeDirectives(dirs, vm) {
7068
7141
  }
7069
7142
  res[getRawDirName(dir)] = dir;
7070
7143
  if (vm._setupState && vm._setupState.__sfc) {
7071
- dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name);
7144
+ dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7072
7145
  }
7073
7146
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
7074
7147
  }
@@ -11681,4 +11754,4 @@ function getOuterHTML(el) {
11681
11754
  }
11682
11755
  Vue.compile = compileToFunctions;
11683
11756
 
11684
- 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 };
11757
+ 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 };