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
  */
@@ -961,7 +961,7 @@ function defineReactive(obj, key, val, customSetter, shallow, mock) {
961
961
  // #7981: for accessor properties without setter
962
962
  return;
963
963
  }
964
- else if (isRef(value) && !isRef(newVal)) {
964
+ else if (!shallow && isRef(value) && !isRef(newVal)) {
965
965
  value.value = newVal;
966
966
  return;
967
967
  }
@@ -2234,7 +2234,19 @@ function createSetupContext(vm) {
2234
2234
  let exposeCalled = false;
2235
2235
  return {
2236
2236
  get attrs() {
2237
- return initAttrsProxy(vm);
2237
+ if (!vm._attrsProxy) {
2238
+ const proxy = (vm._attrsProxy = {});
2239
+ def(proxy, '_v_attr_proxy', true);
2240
+ syncSetupProxy(proxy, vm.$attrs, emptyObject, vm, '$attrs');
2241
+ }
2242
+ return vm._attrsProxy;
2243
+ },
2244
+ get listeners() {
2245
+ if (!vm._listenersProxy) {
2246
+ const proxy = (vm._listenersProxy = {});
2247
+ syncSetupProxy(proxy, vm.$listeners, emptyObject, vm, '$listeners');
2248
+ }
2249
+ return vm._listenersProxy;
2238
2250
  },
2239
2251
  get slots() {
2240
2252
  return initSlotsProxy(vm);
@@ -2253,20 +2265,12 @@ function createSetupContext(vm) {
2253
2265
  }
2254
2266
  };
2255
2267
  }
2256
- function initAttrsProxy(vm) {
2257
- if (!vm._attrsProxy) {
2258
- const proxy = (vm._attrsProxy = {});
2259
- def(proxy, '_v_attr_proxy', true);
2260
- syncSetupAttrs(proxy, vm.$attrs, emptyObject, vm);
2261
- }
2262
- return vm._attrsProxy;
2263
- }
2264
- function syncSetupAttrs(to, from, prev, instance) {
2268
+ function syncSetupProxy(to, from, prev, instance, type) {
2265
2269
  let changed = false;
2266
2270
  for (const key in from) {
2267
2271
  if (!(key in to)) {
2268
2272
  changed = true;
2269
- defineProxyAttr(to, key, instance);
2273
+ defineProxyAttr(to, key, instance, type);
2270
2274
  }
2271
2275
  else if (from[key] !== prev[key]) {
2272
2276
  changed = true;
@@ -2280,12 +2284,12 @@ function syncSetupAttrs(to, from, prev, instance) {
2280
2284
  }
2281
2285
  return changed;
2282
2286
  }
2283
- function defineProxyAttr(proxy, key, instance) {
2287
+ function defineProxyAttr(proxy, key, instance, type) {
2284
2288
  Object.defineProperty(proxy, key, {
2285
2289
  enumerable: true,
2286
2290
  configurable: true,
2287
2291
  get() {
2288
- return instance.$attrs[key];
2292
+ return instance[type][key];
2289
2293
  }
2290
2294
  });
2291
2295
  }
@@ -2306,17 +2310,27 @@ function syncSetupSlots(to, from) {
2306
2310
  }
2307
2311
  }
2308
2312
  /**
2309
- * @internal use manual type def
2313
+ * @internal use manual type def because public setup context type relies on
2314
+ * legacy VNode types
2310
2315
  */
2311
2316
  function useSlots() {
2312
2317
  return getContext().slots;
2313
2318
  }
2314
2319
  /**
2315
- * @internal use manual type def
2320
+ * @internal use manual type def because public setup context type relies on
2321
+ * legacy VNode types
2316
2322
  */
2317
2323
  function useAttrs() {
2318
2324
  return getContext().attrs;
2319
2325
  }
2326
+ /**
2327
+ * Vue 2 only
2328
+ * @internal use manual type def because public setup context type relies on
2329
+ * legacy VNode types
2330
+ */
2331
+ function useListeners() {
2332
+ return getContext().listeners;
2333
+ }
2320
2334
  function getContext() {
2321
2335
  if (!currentInstance) {
2322
2336
  warn$2(`useContext() called without active instance.`);
@@ -2360,7 +2374,9 @@ function initRender(vm) {
2360
2374
  const parentVnode = (vm.$vnode = options._parentVnode); // the placeholder node in parent tree
2361
2375
  const renderContext = parentVnode && parentVnode.context;
2362
2376
  vm.$slots = resolveSlots(options._renderChildren, renderContext);
2363
- vm.$scopedSlots = emptyObject;
2377
+ vm.$scopedSlots = parentVnode
2378
+ ? normalizeScopedSlots(vm.$parent, parentVnode.data.scopedSlots, vm.$slots)
2379
+ : emptyObject;
2364
2380
  // bind the createElement fn to this instance
2365
2381
  // so that we get proper render context inside it.
2366
2382
  // args order: tag, data, children, normalizationType, alwaysNormalize
@@ -2394,7 +2410,7 @@ function renderMixin(Vue) {
2394
2410
  Vue.prototype._render = function () {
2395
2411
  const vm = this;
2396
2412
  const { render, _parentVnode } = vm.$options;
2397
- if (_parentVnode) {
2413
+ if (_parentVnode && vm._isMounted) {
2398
2414
  vm.$scopedSlots = normalizeScopedSlots(vm.$parent, _parentVnode.data.scopedSlots, vm.$slots, vm.$scopedSlots);
2399
2415
  if (vm._slotsProxy) {
2400
2416
  syncSetupSlots(vm._slotsProxy, vm.$scopedSlots);
@@ -2915,12 +2931,19 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
2915
2931
  if (vm._attrsProxy) {
2916
2932
  // force update if attrs are accessed and has changed since it may be
2917
2933
  // passed to a child component.
2918
- if (syncSetupAttrs(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm)) {
2934
+ if (syncSetupProxy(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm, '$attrs')) {
2919
2935
  needsForceUpdate = true;
2920
2936
  }
2921
2937
  }
2922
2938
  vm.$attrs = attrs;
2923
- vm.$listeners = listeners || emptyObject;
2939
+ // update listeners
2940
+ listeners = listeners || emptyObject;
2941
+ const prevListeners = vm.$options._parentListeners;
2942
+ if (vm._listenersProxy) {
2943
+ syncSetupProxy(vm._listenersProxy, listeners, prevListeners || emptyObject, vm, '$listeners');
2944
+ }
2945
+ vm.$listeners = vm.$options._parentListeners = listeners;
2946
+ updateComponentListeners(vm, listeners, prevListeners);
2924
2947
  // update props
2925
2948
  if (propsData && vm.$options.props) {
2926
2949
  toggleObserving(false);
@@ -2935,11 +2958,6 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
2935
2958
  // keep a copy of raw propsData
2936
2959
  vm.$options.propsData = propsData;
2937
2960
  }
2938
- // update listeners
2939
- listeners = listeners || emptyObject;
2940
- const oldListeners = vm.$options._parentListeners;
2941
- vm.$options._parentListeners = listeners;
2942
- updateComponentListeners(vm, listeners, oldListeners);
2943
2961
  // resolve slots + force update if has children
2944
2962
  if (needsForceUpdate) {
2945
2963
  vm.$slots = resolveSlots(renderChildren, parentVnode.context);
@@ -3053,6 +3071,16 @@ if (inBrowser && !isIE) {
3053
3071
  getNow = () => performance.now();
3054
3072
  }
3055
3073
  }
3074
+ const sortCompareFn = (a, b) => {
3075
+ if (a.post) {
3076
+ if (!b.post)
3077
+ return 1;
3078
+ }
3079
+ else if (b.post) {
3080
+ return -1;
3081
+ }
3082
+ return a.id - b.id;
3083
+ };
3056
3084
  /**
3057
3085
  * Flush both queues and run the watchers.
3058
3086
  */
@@ -3068,7 +3096,7 @@ function flushSchedulerQueue() {
3068
3096
  // user watchers are created before the render watcher)
3069
3097
  // 3. If a component is destroyed during a parent component's watcher run,
3070
3098
  // its watchers can be skipped.
3071
- queue.sort((a, b) => a.id - b.id);
3099
+ queue.sort(sortCompareFn);
3072
3100
  // do not cache length because more watchers might be pushed
3073
3101
  // as we run existing watchers
3074
3102
  for (index$1 = 0; index$1 < queue.length; index$1++) {
@@ -3331,7 +3359,7 @@ function doWatch(source, cb, { immediate, deep, flush = 'pre', onTrack, onTrigge
3331
3359
  watcher.update = watcher.run;
3332
3360
  }
3333
3361
  else if (flush === 'post') {
3334
- watcher.id = Infinity;
3362
+ watcher.post = true;
3335
3363
  watcher.update = () => queueWatcher(watcher);
3336
3364
  }
3337
3365
  else {
@@ -3480,18 +3508,23 @@ function provide(key, value) {
3480
3508
  }
3481
3509
  }
3482
3510
  else {
3483
- let provides = currentInstance._provided;
3484
- // by default an instance inherits its parent's provides object
3485
- // but when it needs to provide values of its own, it creates its
3486
- // own provides object using parent provides object as prototype.
3487
- // this way in `inject` we can simply look up injections from direct
3488
- // parent and let the prototype chain do the work.
3489
- const parentProvides = currentInstance.$parent && currentInstance.$parent._provided;
3490
- if (parentProvides === provides) {
3491
- provides = currentInstance._provided = Object.create(parentProvides);
3492
- }
3493
3511
  // TS doesn't allow symbol as index type
3494
- provides[key] = value;
3512
+ resolveProvided(currentInstance)[key] = value;
3513
+ }
3514
+ }
3515
+ function resolveProvided(vm) {
3516
+ // by default an instance inherits its parent's provides object
3517
+ // but when it needs to provide values of its own, it creates its
3518
+ // own provides object using parent provides object as prototype.
3519
+ // this way in `inject` we can simply look up injections from direct
3520
+ // parent and let the prototype chain do the work.
3521
+ const existing = vm._provided;
3522
+ const parentProvides = vm.$parent && vm.$parent._provided;
3523
+ if (parentProvides === existing) {
3524
+ return (vm._provided = Object.create(parentProvides));
3525
+ }
3526
+ else {
3527
+ return existing;
3495
3528
  }
3496
3529
  }
3497
3530
  function inject(key, defaultValue, treatDefaultAsFactory = false) {
@@ -3864,7 +3897,7 @@ const onRenderTriggered = createLifeCycle('renderTriggered');
3864
3897
  /**
3865
3898
  * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
3866
3899
  */
3867
- const version = '2.7.5';
3900
+ const version = '2.7.8';
3868
3901
  /**
3869
3902
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
3870
3903
  */
@@ -3910,6 +3943,7 @@ var vca = /*#__PURE__*/Object.freeze({
3910
3943
  getCurrentInstance: getCurrentInstance,
3911
3944
  useSlots: useSlots,
3912
3945
  useAttrs: useAttrs,
3946
+ useListeners: useListeners,
3913
3947
  mergeDefaults: mergeDefaults,
3914
3948
  nextTick: nextTick,
3915
3949
  set: set,
@@ -4006,6 +4040,7 @@ class Watcher {
4006
4040
  this.cb = cb;
4007
4041
  this.id = ++uid$1; // uid for batching
4008
4042
  this.active = true;
4043
+ this.post = false;
4009
4044
  this.dirty = this.lazy; // for lazy watchers
4010
4045
  this.deps = [];
4011
4046
  this.newDeps = [];
@@ -4470,12 +4505,14 @@ function initProvide(vm) {
4470
4505
  if (!isObject(provided)) {
4471
4506
  return;
4472
4507
  }
4508
+ const source = resolveProvided(vm);
4509
+ // IE9 doesn't support Object.getOwnPropertyDescriptors so we have to
4510
+ // iterate the keys ourselves.
4473
4511
  const keys = hasSymbol ? Reflect.ownKeys(provided) : Object.keys(provided);
4474
- setCurrentInstance(vm);
4475
4512
  for (let i = 0; i < keys.length; i++) {
4476
- provide(keys[i], provided[keys[i]]);
4513
+ const key = keys[i];
4514
+ Object.defineProperty(source, key, Object.getOwnPropertyDescriptor(provided, key));
4477
4515
  }
4478
- setCurrentInstance();
4479
4516
  }
4480
4517
  }
4481
4518
  function initInjections(vm) {
@@ -10808,17 +10845,15 @@ function genElement(el, state) {
10808
10845
  }
10809
10846
  else {
10810
10847
  let data;
10811
- if (!el.plain || (el.pre && state.maybeComponent(el))) {
10848
+ const maybeComponent = state.maybeComponent(el);
10849
+ if (!el.plain || (el.pre && maybeComponent)) {
10812
10850
  data = genData(el, state);
10813
10851
  }
10814
10852
  let tag;
10815
10853
  // check if this is a component in <script setup>
10816
10854
  const bindings = state.options.bindings;
10817
- if (bindings && bindings.__isScriptSetup !== false) {
10818
- tag =
10819
- checkBindingType(bindings, el.tag) ||
10820
- checkBindingType(bindings, camelize(el.tag)) ||
10821
- checkBindingType(bindings, capitalize(camelize(el.tag)));
10855
+ if (maybeComponent && bindings && bindings.__isScriptSetup !== false) {
10856
+ tag = checkBindingType(bindings, el.tag);
10822
10857
  }
10823
10858
  if (!tag)
10824
10859
  tag = `'${el.tag}'`;
@@ -10835,9 +10870,29 @@ function genElement(el, state) {
10835
10870
  }
10836
10871
  }
10837
10872
  function checkBindingType(bindings, key) {
10838
- const type = bindings[key];
10839
- if (type && type.startsWith('setup')) {
10840
- return key;
10873
+ const camelName = camelize(key);
10874
+ const PascalName = capitalize(camelName);
10875
+ const checkType = (type) => {
10876
+ if (bindings[key] === type) {
10877
+ return key;
10878
+ }
10879
+ if (bindings[camelName] === type) {
10880
+ return camelName;
10881
+ }
10882
+ if (bindings[PascalName] === type) {
10883
+ return PascalName;
10884
+ }
10885
+ };
10886
+ const fromConst = checkType("setup-const" /* BindingTypes.SETUP_CONST */) ||
10887
+ checkType("setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */);
10888
+ if (fromConst) {
10889
+ return fromConst;
10890
+ }
10891
+ const fromMaybeRef = checkType("setup-let" /* BindingTypes.SETUP_LET */) ||
10892
+ checkType("setup-ref" /* BindingTypes.SETUP_REF */) ||
10893
+ checkType("setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */);
10894
+ if (fromMaybeRef) {
10895
+ return fromMaybeRef;
10841
10896
  }
10842
10897
  }
10843
10898
  // hoist static sub-trees out