vue 2.7.0 → 2.7.3

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 +88 -75
  2. package/dist/vue.common.prod.js +3 -3
  3. package/dist/vue.esm.browser.js +88 -76
  4. package/dist/vue.esm.browser.min.js +3 -3
  5. package/dist/vue.esm.js +89 -76
  6. package/dist/vue.js +89 -75
  7. package/dist/vue.min.js +3 -3
  8. package/dist/vue.runtime.common.dev.js +88 -75
  9. package/dist/vue.runtime.common.prod.js +3 -3
  10. package/dist/vue.runtime.esm.js +89 -76
  11. package/dist/vue.runtime.js +89 -75
  12. package/dist/vue.runtime.min.js +3 -3
  13. package/dist/vue.runtime.mjs +89 -76
  14. package/package.json +2 -2
  15. package/packages/compiler-sfc/dist/compiler-sfc.js +70 -67
  16. package/packages/compiler-sfc/package.json +1 -1
  17. package/packages/compiler-sfc/src/compileScript.ts +12 -15
  18. package/packages/compiler-sfc/src/parseComponent.ts +6 -1
  19. package/packages/compiler-sfc/src/templateCompilerModules/srcset.ts +1 -1
  20. package/packages/compiler-sfc/test/compileScript.spec.ts +12 -0
  21. package/src/core/observer/index.ts +55 -56
  22. package/src/core/util/next-tick.ts +2 -1
  23. package/src/core/vdom/modules/directives.ts +2 -2
  24. package/src/shared/constants.ts +3 -1
  25. package/src/shared/util.ts +1 -1
  26. package/src/v3/apiSetup.ts +4 -21
  27. package/src/v3/apiWatch.ts +2 -2
  28. package/src/v3/index.ts +1 -0
  29. package/src/v3/reactivity/reactive.ts +13 -2
  30. package/src/v3/reactivity/ref.ts +40 -2
  31. package/types/common.d.ts +6 -0
  32. package/types/index.d.ts +7 -4
  33. package/types/jsx.d.ts +16 -2
  34. package/types/options.d.ts +7 -1
  35. package/types/v3-component-options.d.ts +162 -33
  36. package/types/v3-component-props.d.ts +19 -20
  37. package/types/v3-component-public-instance.d.ts +230 -0
  38. package/types/v3-define-component.d.ts +70 -12
  39. package/types/v3-generated.d.ts +5 -1
  40. package/types/v3-setup-context.d.ts +0 -6
  41. package/types/vnode.d.ts +15 -0
  42. package/types/v3-component-proxy.d.ts +0 -189
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vue.js v2.7.0
2
+ * Vue.js v2.7.3
3
3
  * (c) 2014-2022 Evan You
4
4
  * Released under the MIT License.
5
5
  */
@@ -316,7 +316,7 @@ function hasChanged(x, y) {
316
316
  return x === 0 && 1 / x !== 1 / y;
317
317
  }
318
318
  else {
319
- return x === x && y === y;
319
+ return x === x || y === y;
320
320
  }
321
321
  }
322
322
 
@@ -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) {
@@ -923,6 +925,33 @@ function triggerRef(ref) {
923
925
  function unref(ref) {
924
926
  return isRef(ref) ? ref.value : ref;
925
927
  }
928
+ function proxyRefs(objectWithRefs) {
929
+ if (isReactive(objectWithRefs)) {
930
+ return objectWithRefs;
931
+ }
932
+ const proxy = {};
933
+ const keys = Object.keys(objectWithRefs);
934
+ for (let i = 0; i < keys.length; i++) {
935
+ proxyWithRefUnwrap(proxy, objectWithRefs, keys[i]);
936
+ }
937
+ return proxy;
938
+ }
939
+ function proxyWithRefUnwrap(target, source, key) {
940
+ Object.defineProperty(target, key, {
941
+ enumerable: true,
942
+ configurable: true,
943
+ get: () => unref(source[key]),
944
+ set: value => {
945
+ const oldValue = source[key];
946
+ if (isRef(oldValue) && !isRef(value)) {
947
+ oldValue.value = value;
948
+ }
949
+ else {
950
+ source[key] = value;
951
+ }
952
+ }
953
+ });
954
+ }
926
955
  function customRef(factory) {
927
956
  const dep = new Dep();
928
957
  const { get, set } = factory(() => {
@@ -1459,7 +1488,9 @@ function initSetup(vm) {
1459
1488
  // exposed for compiled render fn
1460
1489
  const proxy = (vm._setupProxy = {});
1461
1490
  for (const key in setupResult) {
1462
- proxyWithRefUnwrap(proxy, setupResult, key);
1491
+ if (key !== '__sfc') {
1492
+ proxyWithRefUnwrap(proxy, setupResult, key);
1493
+ }
1463
1494
  }
1464
1495
  }
1465
1496
  }
@@ -1468,20 +1499,6 @@ function initSetup(vm) {
1468
1499
  }
1469
1500
  }
1470
1501
  }
1471
- function proxyWithRefUnwrap(target, source, key) {
1472
- Object.defineProperty(target, key, {
1473
- enumerable: true,
1474
- configurable: true,
1475
- get: () => {
1476
- const raw = source[key];
1477
- return isRef(raw) ? raw.value : raw;
1478
- },
1479
- set: newVal => {
1480
- const raw = source[key];
1481
- isRef(raw) ? (raw.value = newVal) : (source[key] = newVal);
1482
- }
1483
- });
1484
- }
1485
1502
  function createSetupContext(vm) {
1486
1503
  let exposeCalled = false;
1487
1504
  return {
@@ -4580,7 +4597,7 @@ const onServerPrefetch = createLifeCycle('serverPrefetch');
4580
4597
  const onRenderTracked = createLifeCycle('renderTracked');
4581
4598
  const onRenderTriggered = createLifeCycle('renderTriggered');
4582
4599
 
4583
- const version = '2.7.0';
4600
+ const version = '2.7.3';
4584
4601
  /**
4585
4602
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
4586
4603
  */
@@ -4598,6 +4615,13 @@ let shouldObserve = true;
4598
4615
  function toggleObserving(value) {
4599
4616
  shouldObserve = value;
4600
4617
  }
4618
+ // ssr mock dep
4619
+ const mockDep = {
4620
+ notify: noop,
4621
+ depend: noop,
4622
+ addSub: noop,
4623
+ removeSub: noop
4624
+ };
4601
4625
  /**
4602
4626
  * Observer class that is attached to each observed
4603
4627
  * object. Once attached, the observer converts the target
@@ -4605,76 +4629,60 @@ function toggleObserving(value) {
4605
4629
  * collect dependencies and dispatch updates.
4606
4630
  */
4607
4631
  class Observer {
4608
- constructor(value, shallow = false) {
4632
+ constructor(value, shallow = false, mock = false) {
4609
4633
  this.value = value;
4610
4634
  this.shallow = shallow;
4635
+ this.mock = mock;
4611
4636
  // this.value = value
4612
- this.dep = new Dep();
4637
+ this.dep = mock ? mockDep : new Dep();
4613
4638
  this.vmCount = 0;
4614
4639
  def(value, '__ob__', this);
4615
4640
  if (isArray(value)) {
4616
- if (hasProto) {
4617
- protoAugment(value, arrayMethods);
4618
- }
4619
- else {
4620
- copyAugment(value, arrayMethods, arrayKeys);
4641
+ if (!mock) {
4642
+ if (hasProto) {
4643
+ value.__proto__ = arrayMethods;
4644
+ /* eslint-enable no-proto */
4645
+ }
4646
+ else {
4647
+ for (let i = 0, l = arrayKeys.length; i < l; i++) {
4648
+ const key = arrayKeys[i];
4649
+ def(value, key, arrayMethods[key]);
4650
+ }
4651
+ }
4621
4652
  }
4622
4653
  if (!shallow) {
4623
4654
  this.observeArray(value);
4624
4655
  }
4625
4656
  }
4626
4657
  else {
4627
- this.walk(value, shallow);
4628
- }
4629
- }
4630
- /**
4631
- * Walk through all properties and convert them into
4632
- * getter/setters. This method should only be called when
4633
- * value type is Object.
4634
- */
4635
- walk(obj, shallow) {
4636
- const keys = Object.keys(obj);
4637
- for (let i = 0; i < keys.length; i++) {
4638
- const key = keys[i];
4639
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
4658
+ /**
4659
+ * Walk through all properties and convert them into
4660
+ * getter/setters. This method should only be called when
4661
+ * value type is Object.
4662
+ */
4663
+ const keys = Object.keys(value);
4664
+ for (let i = 0; i < keys.length; i++) {
4665
+ const key = keys[i];
4666
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
4667
+ }
4640
4668
  }
4641
4669
  }
4642
4670
  /**
4643
4671
  * Observe a list of Array items.
4644
4672
  */
4645
- observeArray(items) {
4646
- for (let i = 0, l = items.length; i < l; i++) {
4647
- observe(items[i]);
4673
+ observeArray(value) {
4674
+ for (let i = 0, l = value.length; i < l; i++) {
4675
+ observe(value[i], false, this.mock);
4648
4676
  }
4649
4677
  }
4650
4678
  }
4651
4679
  // helpers
4652
- /**
4653
- * Augment a target Object or Array by intercepting
4654
- * the prototype chain using __proto__
4655
- */
4656
- function protoAugment(target, src) {
4657
- /* eslint-disable no-proto */
4658
- target.__proto__ = src;
4659
- /* eslint-enable no-proto */
4660
- }
4661
- /**
4662
- * Augment a target Object or Array by defining
4663
- * hidden properties.
4664
- */
4665
- /* istanbul ignore next */
4666
- function copyAugment(target, src, keys) {
4667
- for (let i = 0, l = keys.length; i < l; i++) {
4668
- const key = keys[i];
4669
- def(target, key, src[key]);
4670
- }
4671
- }
4672
4680
  /**
4673
4681
  * Attempt to create an observer instance for a value,
4674
4682
  * returns the new observer if successfully observed,
4675
4683
  * or the existing observer if the value already has one.
4676
4684
  */
4677
- function observe(value, shallow) {
4685
+ function observe(value, shallow, ssrMockReactivity) {
4678
4686
  if (!isObject(value) || isRef(value) || value instanceof VNode) {
4679
4687
  return;
4680
4688
  }
@@ -4683,18 +4691,18 @@ function observe(value, shallow) {
4683
4691
  ob = value.__ob__;
4684
4692
  }
4685
4693
  else if (shouldObserve &&
4686
- !isServerRendering() &&
4694
+ (ssrMockReactivity || !isServerRendering()) &&
4687
4695
  (isArray(value) || isPlainObject(value)) &&
4688
4696
  Object.isExtensible(value) &&
4689
- !value.__v_skip) {
4690
- ob = new Observer(value, shallow);
4697
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
4698
+ ob = new Observer(value, shallow, ssrMockReactivity);
4691
4699
  }
4692
4700
  return ob;
4693
4701
  }
4694
4702
  /**
4695
4703
  * Define a reactive property on an Object.
4696
4704
  */
4697
- function defineReactive(obj, key, val, customSetter, shallow) {
4705
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
4698
4706
  const dep = new Dep();
4699
4707
  const property = Object.getOwnPropertyDescriptor(obj, key);
4700
4708
  if (property && property.configurable === false) {
@@ -4707,7 +4715,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4707
4715
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
4708
4716
  val = obj[key];
4709
4717
  }
4710
- let childOb = !shallow && observe(val);
4718
+ let childOb = !shallow && observe(val, false, mock);
4711
4719
  Object.defineProperty(obj, key, {
4712
4720
  enumerable: true,
4713
4721
  configurable: true,
@@ -4728,7 +4736,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4728
4736
  }
4729
4737
  }
4730
4738
  }
4731
- return isRef(value) ? value.value : value;
4739
+ return isRef(value) && !shallow ? value.value : value;
4732
4740
  },
4733
4741
  set: function reactiveSetter(newVal) {
4734
4742
  const value = getter ? getter.call(obj) : val;
@@ -4752,7 +4760,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4752
4760
  else {
4753
4761
  val = newVal;
4754
4762
  }
4755
- childOb = !shallow && observe(newVal);
4763
+ childOb = !shallow && observe(newVal, false, mock);
4756
4764
  {
4757
4765
  dep.notify({
4758
4766
  type: "set" /* TriggerOpTypes.SET */,
@@ -4774,16 +4782,20 @@ function set(target, key, val) {
4774
4782
  warn$2(`Set operation on key "${key}" failed: target is readonly.`);
4775
4783
  return;
4776
4784
  }
4785
+ const ob = target.__ob__;
4777
4786
  if (isArray(target) && isValidArrayIndex(key)) {
4778
4787
  target.length = Math.max(target.length, key);
4779
4788
  target.splice(key, 1, val);
4789
+ // when mocking for SSR, array methods are not hijacked
4790
+ if (!ob.shallow && ob.mock) {
4791
+ observe(val, false, true);
4792
+ }
4780
4793
  return val;
4781
4794
  }
4782
4795
  if (key in target && !(key in Object.prototype)) {
4783
4796
  target[key] = val;
4784
4797
  return val;
4785
4798
  }
4786
- const ob = target.__ob__;
4787
4799
  if (target._isVue || (ob && ob.vmCount)) {
4788
4800
  warn$2('Avoid adding reactive properties to a Vue instance or its root $data ' +
4789
4801
  'at runtime - declare it upfront in the data option.');
@@ -4793,7 +4805,7 @@ function set(target, key, val) {
4793
4805
  target[key] = val;
4794
4806
  return val;
4795
4807
  }
4796
- defineReactive(ob.value, key, val);
4808
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
4797
4809
  {
4798
4810
  ob.dep.notify({
4799
4811
  type: "add" /* TriggerOpTypes.ADD */,
@@ -6910,7 +6922,7 @@ function normalizeDirectives(dirs, vm) {
6910
6922
  }
6911
6923
  res[getRawDirName(dir)] = dir;
6912
6924
  if (vm._setupState && vm._setupState.__sfc) {
6913
- dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name);
6925
+ dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
6914
6926
  }
6915
6927
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
6916
6928
  }
@@ -11488,4 +11500,4 @@ function getOuterHTML(el) {
11488
11500
  }
11489
11501
  Vue.compile = compileToFunctions;
11490
11502
 
11491
- 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, reactive, readonly, ref$1 as ref, set, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSlots, version, watch, watchEffect, watchPostEffect, watchSyncEffect };
11503
+ 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 };