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
  */
@@ -318,7 +318,7 @@ function hasChanged(x, y) {
318
318
  return x === 0 && 1 / x !== 1 / y;
319
319
  }
320
320
  else {
321
- return x === x && y === y;
321
+ return x === x || y === y;
322
322
  }
323
323
  }
324
324
 
@@ -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) {
@@ -925,6 +927,33 @@ function triggerRef(ref) {
925
927
  function unref(ref) {
926
928
  return isRef(ref) ? ref.value : ref;
927
929
  }
930
+ function proxyRefs(objectWithRefs) {
931
+ if (isReactive(objectWithRefs)) {
932
+ return objectWithRefs;
933
+ }
934
+ const proxy = {};
935
+ const keys = Object.keys(objectWithRefs);
936
+ for (let i = 0; i < keys.length; i++) {
937
+ proxyWithRefUnwrap(proxy, objectWithRefs, keys[i]);
938
+ }
939
+ return proxy;
940
+ }
941
+ function proxyWithRefUnwrap(target, source, key) {
942
+ Object.defineProperty(target, key, {
943
+ enumerable: true,
944
+ configurable: true,
945
+ get: () => unref(source[key]),
946
+ set: value => {
947
+ const oldValue = source[key];
948
+ if (isRef(oldValue) && !isRef(value)) {
949
+ oldValue.value = value;
950
+ }
951
+ else {
952
+ source[key] = value;
953
+ }
954
+ }
955
+ });
956
+ }
928
957
  function customRef(factory) {
929
958
  const dep = new Dep();
930
959
  const { get, set } = factory(() => {
@@ -1461,7 +1490,9 @@ function initSetup(vm) {
1461
1490
  // exposed for compiled render fn
1462
1491
  const proxy = (vm._setupProxy = {});
1463
1492
  for (const key in setupResult) {
1464
- proxyWithRefUnwrap(proxy, setupResult, key);
1493
+ if (key !== '__sfc') {
1494
+ proxyWithRefUnwrap(proxy, setupResult, key);
1495
+ }
1465
1496
  }
1466
1497
  }
1467
1498
  }
@@ -1470,20 +1501,6 @@ function initSetup(vm) {
1470
1501
  }
1471
1502
  }
1472
1503
  }
1473
- function proxyWithRefUnwrap(target, source, key) {
1474
- Object.defineProperty(target, key, {
1475
- enumerable: true,
1476
- configurable: true,
1477
- get: () => {
1478
- const raw = source[key];
1479
- return isRef(raw) ? raw.value : raw;
1480
- },
1481
- set: newVal => {
1482
- const raw = source[key];
1483
- isRef(raw) ? (raw.value = newVal) : (source[key] = newVal);
1484
- }
1485
- });
1486
- }
1487
1504
  function createSetupContext(vm) {
1488
1505
  let exposeCalled = false;
1489
1506
  return {
@@ -4588,7 +4605,7 @@ const onServerPrefetch = createLifeCycle('serverPrefetch');
4588
4605
  const onRenderTracked = createLifeCycle('renderTracked');
4589
4606
  const onRenderTriggered = createLifeCycle('renderTriggered');
4590
4607
 
4591
- const version = '2.7.0';
4608
+ const version = '2.7.3';
4592
4609
  /**
4593
4610
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
4594
4611
  */
@@ -4606,6 +4623,7 @@ var vca = /*#__PURE__*/Object.freeze({
4606
4623
  toRef: toRef,
4607
4624
  toRefs: toRefs,
4608
4625
  unref: unref,
4626
+ proxyRefs: proxyRefs,
4609
4627
  customRef: customRef,
4610
4628
  triggerRef: triggerRef,
4611
4629
  reactive: reactive,
@@ -4663,6 +4681,13 @@ let shouldObserve = true;
4663
4681
  function toggleObserving(value) {
4664
4682
  shouldObserve = value;
4665
4683
  }
4684
+ // ssr mock dep
4685
+ const mockDep = {
4686
+ notify: noop,
4687
+ depend: noop,
4688
+ addSub: noop,
4689
+ removeSub: noop
4690
+ };
4666
4691
  /**
4667
4692
  * Observer class that is attached to each observed
4668
4693
  * object. Once attached, the observer converts the target
@@ -4670,76 +4695,60 @@ function toggleObserving(value) {
4670
4695
  * collect dependencies and dispatch updates.
4671
4696
  */
4672
4697
  class Observer {
4673
- constructor(value, shallow = false) {
4698
+ constructor(value, shallow = false, mock = false) {
4674
4699
  this.value = value;
4675
4700
  this.shallow = shallow;
4701
+ this.mock = mock;
4676
4702
  // this.value = value
4677
- this.dep = new Dep();
4703
+ this.dep = mock ? mockDep : new Dep();
4678
4704
  this.vmCount = 0;
4679
4705
  def(value, '__ob__', this);
4680
4706
  if (isArray(value)) {
4681
- if (hasProto) {
4682
- protoAugment(value, arrayMethods);
4683
- }
4684
- else {
4685
- copyAugment(value, arrayMethods, arrayKeys);
4707
+ if (!mock) {
4708
+ if (hasProto) {
4709
+ value.__proto__ = arrayMethods;
4710
+ /* eslint-enable no-proto */
4711
+ }
4712
+ else {
4713
+ for (let i = 0, l = arrayKeys.length; i < l; i++) {
4714
+ const key = arrayKeys[i];
4715
+ def(value, key, arrayMethods[key]);
4716
+ }
4717
+ }
4686
4718
  }
4687
4719
  if (!shallow) {
4688
4720
  this.observeArray(value);
4689
4721
  }
4690
4722
  }
4691
4723
  else {
4692
- this.walk(value, shallow);
4693
- }
4694
- }
4695
- /**
4696
- * Walk through all properties and convert them into
4697
- * getter/setters. This method should only be called when
4698
- * value type is Object.
4699
- */
4700
- walk(obj, shallow) {
4701
- const keys = Object.keys(obj);
4702
- for (let i = 0; i < keys.length; i++) {
4703
- const key = keys[i];
4704
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
4724
+ /**
4725
+ * Walk through all properties and convert them into
4726
+ * getter/setters. This method should only be called when
4727
+ * value type is Object.
4728
+ */
4729
+ const keys = Object.keys(value);
4730
+ for (let i = 0; i < keys.length; i++) {
4731
+ const key = keys[i];
4732
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
4733
+ }
4705
4734
  }
4706
4735
  }
4707
4736
  /**
4708
4737
  * Observe a list of Array items.
4709
4738
  */
4710
- observeArray(items) {
4711
- for (let i = 0, l = items.length; i < l; i++) {
4712
- observe(items[i]);
4739
+ observeArray(value) {
4740
+ for (let i = 0, l = value.length; i < l; i++) {
4741
+ observe(value[i], false, this.mock);
4713
4742
  }
4714
4743
  }
4715
4744
  }
4716
4745
  // helpers
4717
- /**
4718
- * Augment a target Object or Array by intercepting
4719
- * the prototype chain using __proto__
4720
- */
4721
- function protoAugment(target, src) {
4722
- /* eslint-disable no-proto */
4723
- target.__proto__ = src;
4724
- /* eslint-enable no-proto */
4725
- }
4726
- /**
4727
- * Augment a target Object or Array by defining
4728
- * hidden properties.
4729
- */
4730
- /* istanbul ignore next */
4731
- function copyAugment(target, src, keys) {
4732
- for (let i = 0, l = keys.length; i < l; i++) {
4733
- const key = keys[i];
4734
- def(target, key, src[key]);
4735
- }
4736
- }
4737
4746
  /**
4738
4747
  * Attempt to create an observer instance for a value,
4739
4748
  * returns the new observer if successfully observed,
4740
4749
  * or the existing observer if the value already has one.
4741
4750
  */
4742
- function observe(value, shallow) {
4751
+ function observe(value, shallow, ssrMockReactivity) {
4743
4752
  if (!isObject(value) || isRef(value) || value instanceof VNode) {
4744
4753
  return;
4745
4754
  }
@@ -4748,18 +4757,18 @@ function observe(value, shallow) {
4748
4757
  ob = value.__ob__;
4749
4758
  }
4750
4759
  else if (shouldObserve &&
4751
- !isServerRendering() &&
4760
+ (ssrMockReactivity || !isServerRendering()) &&
4752
4761
  (isArray(value) || isPlainObject(value)) &&
4753
4762
  Object.isExtensible(value) &&
4754
- !value.__v_skip) {
4755
- ob = new Observer(value, shallow);
4763
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
4764
+ ob = new Observer(value, shallow, ssrMockReactivity);
4756
4765
  }
4757
4766
  return ob;
4758
4767
  }
4759
4768
  /**
4760
4769
  * Define a reactive property on an Object.
4761
4770
  */
4762
- function defineReactive(obj, key, val, customSetter, shallow) {
4771
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
4763
4772
  const dep = new Dep();
4764
4773
  const property = Object.getOwnPropertyDescriptor(obj, key);
4765
4774
  if (property && property.configurable === false) {
@@ -4772,7 +4781,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4772
4781
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
4773
4782
  val = obj[key];
4774
4783
  }
4775
- let childOb = !shallow && observe(val);
4784
+ let childOb = !shallow && observe(val, false, mock);
4776
4785
  Object.defineProperty(obj, key, {
4777
4786
  enumerable: true,
4778
4787
  configurable: true,
@@ -4793,7 +4802,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4793
4802
  }
4794
4803
  }
4795
4804
  }
4796
- return isRef(value) ? value.value : value;
4805
+ return isRef(value) && !shallow ? value.value : value;
4797
4806
  },
4798
4807
  set: function reactiveSetter(newVal) {
4799
4808
  const value = getter ? getter.call(obj) : val;
@@ -4817,7 +4826,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4817
4826
  else {
4818
4827
  val = newVal;
4819
4828
  }
4820
- childOb = !shallow && observe(newVal);
4829
+ childOb = !shallow && observe(newVal, false, mock);
4821
4830
  {
4822
4831
  dep.notify({
4823
4832
  type: "set" /* TriggerOpTypes.SET */,
@@ -4839,16 +4848,20 @@ function set(target, key, val) {
4839
4848
  warn$2(`Set operation on key "${key}" failed: target is readonly.`);
4840
4849
  return;
4841
4850
  }
4851
+ const ob = target.__ob__;
4842
4852
  if (isArray(target) && isValidArrayIndex(key)) {
4843
4853
  target.length = Math.max(target.length, key);
4844
4854
  target.splice(key, 1, val);
4855
+ // when mocking for SSR, array methods are not hijacked
4856
+ if (!ob.shallow && ob.mock) {
4857
+ observe(val, false, true);
4858
+ }
4845
4859
  return val;
4846
4860
  }
4847
4861
  if (key in target && !(key in Object.prototype)) {
4848
4862
  target[key] = val;
4849
4863
  return val;
4850
4864
  }
4851
- const ob = target.__ob__;
4852
4865
  if (target._isVue || (ob && ob.vmCount)) {
4853
4866
  warn$2('Avoid adding reactive properties to a Vue instance or its root $data ' +
4854
4867
  'at runtime - declare it upfront in the data option.');
@@ -4858,7 +4871,7 @@ function set(target, key, val) {
4858
4871
  target[key] = val;
4859
4872
  return val;
4860
4873
  }
4861
- defineReactive(ob.value, key, val);
4874
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
4862
4875
  {
4863
4876
  ob.dep.notify({
4864
4877
  type: "add" /* TriggerOpTypes.ADD */,
@@ -6975,7 +6988,7 @@ function normalizeDirectives(dirs, vm) {
6975
6988
  }
6976
6989
  res[getRawDirName(dir)] = dir;
6977
6990
  if (vm._setupState && vm._setupState.__sfc) {
6978
- dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name);
6991
+ dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
6979
6992
  }
6980
6993
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
6981
6994
  }