vue 2.7.5 → 2.7.8

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vue.js v2.7.5
2
+ * Vue.js v2.7.8
3
3
  * (c) 2014-2022 Evan You
4
4
  * Released under the MIT License.
5
5
  */
@@ -874,7 +874,7 @@ function defineReactive(obj, key, val, customSetter, shallow, mock) {
874
874
  // #7981: for accessor properties without setter
875
875
  return;
876
876
  }
877
- else if (isRef(value) && !isRef(newVal)) {
877
+ else if (!shallow && isRef(value) && !isRef(newVal)) {
878
878
  value.value = newVal;
879
879
  return;
880
880
  }
@@ -1480,7 +1480,7 @@ function doWatch(source, cb, { immediate, deep, flush = 'pre', onTrack, onTrigge
1480
1480
  watcher.update = watcher.run;
1481
1481
  }
1482
1482
  else if (flush === 'post') {
1483
- watcher.id = Infinity;
1483
+ watcher.post = true;
1484
1484
  watcher.update = () => queueWatcher(watcher);
1485
1485
  }
1486
1486
  else {
@@ -1629,18 +1629,23 @@ function provide(key, value) {
1629
1629
  }
1630
1630
  }
1631
1631
  else {
1632
- let provides = currentInstance._provided;
1633
- // by default an instance inherits its parent's provides object
1634
- // but when it needs to provide values of its own, it creates its
1635
- // own provides object using parent provides object as prototype.
1636
- // this way in `inject` we can simply look up injections from direct
1637
- // parent and let the prototype chain do the work.
1638
- const parentProvides = currentInstance.$parent && currentInstance.$parent._provided;
1639
- if (parentProvides === provides) {
1640
- provides = currentInstance._provided = Object.create(parentProvides);
1641
- }
1642
1632
  // TS doesn't allow symbol as index type
1643
- provides[key] = value;
1633
+ resolveProvided(currentInstance)[key] = value;
1634
+ }
1635
+ }
1636
+ function resolveProvided(vm) {
1637
+ // by default an instance inherits its parent's provides object
1638
+ // but when it needs to provide values of its own, it creates its
1639
+ // own provides object using parent provides object as prototype.
1640
+ // this way in `inject` we can simply look up injections from direct
1641
+ // parent and let the prototype chain do the work.
1642
+ const existing = vm._provided;
1643
+ const parentProvides = vm.$parent && vm.$parent._provided;
1644
+ if (parentProvides === existing) {
1645
+ return (vm._provided = Object.create(parentProvides));
1646
+ }
1647
+ else {
1648
+ return existing;
1644
1649
  }
1645
1650
  }
1646
1651
  function inject(key, defaultValue, treatDefaultAsFactory = false) {
@@ -2360,7 +2365,19 @@ function createSetupContext(vm) {
2360
2365
  let exposeCalled = false;
2361
2366
  return {
2362
2367
  get attrs() {
2363
- return initAttrsProxy(vm);
2368
+ if (!vm._attrsProxy) {
2369
+ const proxy = (vm._attrsProxy = {});
2370
+ def(proxy, '_v_attr_proxy', true);
2371
+ syncSetupProxy(proxy, vm.$attrs, emptyObject, vm, '$attrs');
2372
+ }
2373
+ return vm._attrsProxy;
2374
+ },
2375
+ get listeners() {
2376
+ if (!vm._listenersProxy) {
2377
+ const proxy = (vm._listenersProxy = {});
2378
+ syncSetupProxy(proxy, vm.$listeners, emptyObject, vm, '$listeners');
2379
+ }
2380
+ return vm._listenersProxy;
2364
2381
  },
2365
2382
  get slots() {
2366
2383
  return initSlotsProxy(vm);
@@ -2379,20 +2396,12 @@ function createSetupContext(vm) {
2379
2396
  }
2380
2397
  };
2381
2398
  }
2382
- function initAttrsProxy(vm) {
2383
- if (!vm._attrsProxy) {
2384
- const proxy = (vm._attrsProxy = {});
2385
- def(proxy, '_v_attr_proxy', true);
2386
- syncSetupAttrs(proxy, vm.$attrs, emptyObject, vm);
2387
- }
2388
- return vm._attrsProxy;
2389
- }
2390
- function syncSetupAttrs(to, from, prev, instance) {
2399
+ function syncSetupProxy(to, from, prev, instance, type) {
2391
2400
  let changed = false;
2392
2401
  for (const key in from) {
2393
2402
  if (!(key in to)) {
2394
2403
  changed = true;
2395
- defineProxyAttr(to, key, instance);
2404
+ defineProxyAttr(to, key, instance, type);
2396
2405
  }
2397
2406
  else if (from[key] !== prev[key]) {
2398
2407
  changed = true;
@@ -2406,12 +2415,12 @@ function syncSetupAttrs(to, from, prev, instance) {
2406
2415
  }
2407
2416
  return changed;
2408
2417
  }
2409
- function defineProxyAttr(proxy, key, instance) {
2418
+ function defineProxyAttr(proxy, key, instance, type) {
2410
2419
  Object.defineProperty(proxy, key, {
2411
2420
  enumerable: true,
2412
2421
  configurable: true,
2413
2422
  get() {
2414
- return instance.$attrs[key];
2423
+ return instance[type][key];
2415
2424
  }
2416
2425
  });
2417
2426
  }
@@ -2432,17 +2441,27 @@ function syncSetupSlots(to, from) {
2432
2441
  }
2433
2442
  }
2434
2443
  /**
2435
- * @internal use manual type def
2444
+ * @internal use manual type def because public setup context type relies on
2445
+ * legacy VNode types
2436
2446
  */
2437
2447
  function useSlots() {
2438
2448
  return getContext().slots;
2439
2449
  }
2440
2450
  /**
2441
- * @internal use manual type def
2451
+ * @internal use manual type def because public setup context type relies on
2452
+ * legacy VNode types
2442
2453
  */
2443
2454
  function useAttrs() {
2444
2455
  return getContext().attrs;
2445
2456
  }
2457
+ /**
2458
+ * Vue 2 only
2459
+ * @internal use manual type def because public setup context type relies on
2460
+ * legacy VNode types
2461
+ */
2462
+ function useListeners() {
2463
+ return getContext().listeners;
2464
+ }
2446
2465
  function getContext() {
2447
2466
  if (!currentInstance) {
2448
2467
  warn(`useContext() called without active instance.`);
@@ -2486,7 +2505,9 @@ function initRender(vm) {
2486
2505
  const parentVnode = (vm.$vnode = options._parentVnode); // the placeholder node in parent tree
2487
2506
  const renderContext = parentVnode && parentVnode.context;
2488
2507
  vm.$slots = resolveSlots(options._renderChildren, renderContext);
2489
- vm.$scopedSlots = emptyObject;
2508
+ vm.$scopedSlots = parentVnode
2509
+ ? normalizeScopedSlots(vm.$parent, parentVnode.data.scopedSlots, vm.$slots)
2510
+ : emptyObject;
2490
2511
  // bind the createElement fn to this instance
2491
2512
  // so that we get proper render context inside it.
2492
2513
  // args order: tag, data, children, normalizationType, alwaysNormalize
@@ -2520,7 +2541,7 @@ function renderMixin(Vue) {
2520
2541
  Vue.prototype._render = function () {
2521
2542
  const vm = this;
2522
2543
  const { render, _parentVnode } = vm.$options;
2523
- if (_parentVnode) {
2544
+ if (_parentVnode && vm._isMounted) {
2524
2545
  vm.$scopedSlots = normalizeScopedSlots(vm.$parent, _parentVnode.data.scopedSlots, vm.$slots, vm.$scopedSlots);
2525
2546
  if (vm._slotsProxy) {
2526
2547
  syncSetupSlots(vm._slotsProxy, vm.$scopedSlots);
@@ -3165,7 +3186,7 @@ const onRenderTriggered = createLifeCycle('renderTriggered');
3165
3186
  /**
3166
3187
  * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
3167
3188
  */
3168
- const version = '2.7.5';
3189
+ const version = '2.7.8';
3169
3190
  /**
3170
3191
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
3171
3192
  */
@@ -3211,6 +3232,7 @@ var vca = /*#__PURE__*/Object.freeze({
3211
3232
  getCurrentInstance: getCurrentInstance,
3212
3233
  useSlots: useSlots,
3213
3234
  useAttrs: useAttrs,
3235
+ useListeners: useListeners,
3214
3236
  mergeDefaults: mergeDefaults,
3215
3237
  nextTick: nextTick,
3216
3238
  set: set,
@@ -3307,6 +3329,7 @@ class Watcher {
3307
3329
  this.cb = cb;
3308
3330
  this.id = ++uid$1; // uid for batching
3309
3331
  this.active = true;
3332
+ this.post = false;
3310
3333
  this.dirty = this.lazy; // for lazy watchers
3311
3334
  this.deps = [];
3312
3335
  this.newDeps = [];
@@ -3829,12 +3852,19 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
3829
3852
  if (vm._attrsProxy) {
3830
3853
  // force update if attrs are accessed and has changed since it may be
3831
3854
  // passed to a child component.
3832
- if (syncSetupAttrs(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm)) {
3855
+ if (syncSetupProxy(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm, '$attrs')) {
3833
3856
  needsForceUpdate = true;
3834
3857
  }
3835
3858
  }
3836
3859
  vm.$attrs = attrs;
3837
- vm.$listeners = listeners || emptyObject;
3860
+ // update listeners
3861
+ listeners = listeners || emptyObject;
3862
+ const prevListeners = vm.$options._parentListeners;
3863
+ if (vm._listenersProxy) {
3864
+ syncSetupProxy(vm._listenersProxy, listeners, prevListeners || emptyObject, vm, '$listeners');
3865
+ }
3866
+ vm.$listeners = vm.$options._parentListeners = listeners;
3867
+ updateComponentListeners(vm, listeners, prevListeners);
3838
3868
  // update props
3839
3869
  if (propsData && vm.$options.props) {
3840
3870
  toggleObserving(false);
@@ -3849,11 +3879,6 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
3849
3879
  // keep a copy of raw propsData
3850
3880
  vm.$options.propsData = propsData;
3851
3881
  }
3852
- // update listeners
3853
- listeners = listeners || emptyObject;
3854
- const oldListeners = vm.$options._parentListeners;
3855
- vm.$options._parentListeners = listeners;
3856
- updateComponentListeners(vm, listeners, oldListeners);
3857
3882
  // resolve slots + force update if has children
3858
3883
  if (needsForceUpdate) {
3859
3884
  vm.$slots = resolveSlots(renderChildren, parentVnode.context);
@@ -3967,6 +3992,16 @@ if (inBrowser && !isIE) {
3967
3992
  getNow = () => performance.now();
3968
3993
  }
3969
3994
  }
3995
+ const sortCompareFn = (a, b) => {
3996
+ if (a.post) {
3997
+ if (!b.post)
3998
+ return 1;
3999
+ }
4000
+ else if (b.post) {
4001
+ return -1;
4002
+ }
4003
+ return a.id - b.id;
4004
+ };
3970
4005
  /**
3971
4006
  * Flush both queues and run the watchers.
3972
4007
  */
@@ -3982,7 +4017,7 @@ function flushSchedulerQueue() {
3982
4017
  // user watchers are created before the render watcher)
3983
4018
  // 3. If a component is destroyed during a parent component's watcher run,
3984
4019
  // its watchers can be skipped.
3985
- queue.sort((a, b) => a.id - b.id);
4020
+ queue.sort(sortCompareFn);
3986
4021
  // do not cache length because more watchers might be pushed
3987
4022
  // as we run existing watchers
3988
4023
  for (index = 0; index < queue.length; index++) {
@@ -4090,12 +4125,14 @@ function initProvide(vm) {
4090
4125
  if (!isObject(provided)) {
4091
4126
  return;
4092
4127
  }
4128
+ const source = resolveProvided(vm);
4129
+ // IE9 doesn't support Object.getOwnPropertyDescriptors so we have to
4130
+ // iterate the keys ourselves.
4093
4131
  const keys = hasSymbol ? Reflect.ownKeys(provided) : Object.keys(provided);
4094
- setCurrentInstance(vm);
4095
4132
  for (let i = 0; i < keys.length; i++) {
4096
- provide(keys[i], provided[keys[i]]);
4133
+ const key = keys[i];
4134
+ Object.defineProperty(source, key, Object.getOwnPropertyDescriptor(provided, key));
4097
4135
  }
4098
- setCurrentInstance();
4099
4136
  }
4100
4137
  }
4101
4138
  function initInjections(vm) {