vue 2.7.6 → 2.7.9

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 (48) hide show
  1. package/README.md +1 -1
  2. package/dist/vue.common.dev.js +139 -67
  3. package/dist/vue.common.prod.js +3 -3
  4. package/dist/vue.esm.browser.js +137 -66
  5. package/dist/vue.esm.browser.min.js +3 -3
  6. package/dist/vue.esm.js +138 -66
  7. package/dist/vue.js +140 -67
  8. package/dist/vue.min.js +3 -3
  9. package/dist/vue.runtime.common.dev.js +112 -58
  10. package/dist/vue.runtime.common.prod.js +3 -3
  11. package/dist/vue.runtime.esm.js +111 -57
  12. package/dist/vue.runtime.js +113 -58
  13. package/dist/vue.runtime.min.js +3 -3
  14. package/package.json +2 -2
  15. package/packages/compiler-sfc/dist/compiler-sfc.js +56 -26
  16. package/packages/compiler-sfc/package.json +2 -3
  17. package/packages/compiler-sfc/src/compileTemplate.ts +1 -2
  18. package/packages/compiler-sfc/src/rewriteDefault.ts +6 -1
  19. package/packages/compiler-sfc/src/templateCompilerModules/utils.ts +8 -3
  20. package/packages/compiler-sfc/test/rewriteDefault.spec.ts +245 -0
  21. package/src/compiler/codegen/index.ts +31 -10
  22. package/src/core/instance/init.ts +1 -0
  23. package/src/core/instance/inject.ts +10 -5
  24. package/src/core/instance/lifecycle.ts +18 -10
  25. package/src/core/instance/proxy.ts +2 -2
  26. package/src/core/instance/render.ts +8 -2
  27. package/src/core/instance/state.ts +1 -1
  28. package/src/core/observer/index.ts +1 -1
  29. package/src/core/observer/scheduler.ts +10 -1
  30. package/src/core/observer/watcher.ts +14 -5
  31. package/src/core/vdom/modules/directives.ts +9 -1
  32. package/src/core/vdom/vnode.ts +1 -0
  33. package/src/types/component.ts +1 -0
  34. package/src/v3/apiInject.ts +17 -12
  35. package/src/v3/apiLifecycle.ts +16 -1
  36. package/src/v3/apiSetup.ts +38 -17
  37. package/src/v3/apiWatch.ts +2 -5
  38. package/src/v3/index.ts +1 -1
  39. package/src/v3/reactivity/effectScope.ts +5 -1
  40. package/types/index.d.ts +2 -2
  41. package/types/options.d.ts +24 -9
  42. package/types/v3-component-options.d.ts +3 -0
  43. package/types/v3-component-public-instance.d.ts +2 -4
  44. package/types/v3-define-component.d.ts +34 -34
  45. package/types/v3-generated.d.ts +11 -2
  46. package/types/v3-manual-apis.d.ts +2 -2
  47. package/types/v3-setup-context.d.ts +4 -0
  48. package/types/vue.d.ts +108 -31
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vue.js v2.7.6
2
+ * Vue.js v2.7.9
3
3
  * (c) 2014-2022 Evan You
4
4
  * Released under the MIT License.
5
5
  */
@@ -920,7 +920,7 @@ function defineReactive(obj, key, val, customSetter, shallow, mock) {
920
920
  // #7981: for accessor properties without setter
921
921
  return;
922
922
  }
923
- else if (isRef(value) && !isRef(newVal)) {
923
+ else if (!shallow && isRef(value) && !isRef(newVal)) {
924
924
  value.value = newVal;
925
925
  return;
926
926
  }
@@ -1523,8 +1523,7 @@ function doWatch(source, cb, _a) {
1523
1523
  var oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
1524
1524
  // overwrite default run
1525
1525
  watcher.run = function () {
1526
- if (!watcher.active &&
1527
- !(flush === 'pre' && instance && instance._isBeingDestroyed)) {
1526
+ if (!watcher.active) {
1528
1527
  return;
1529
1528
  }
1530
1529
  if (cb) {
@@ -1559,7 +1558,7 @@ function doWatch(source, cb, _a) {
1559
1558
  watcher.update = watcher.run;
1560
1559
  }
1561
1560
  else if (flush === 'post') {
1562
- watcher.id = Infinity;
1561
+ watcher.post = true;
1563
1562
  watcher.update = function () { return queueWatcher(watcher); };
1564
1563
  }
1565
1564
  else {
@@ -1711,18 +1710,23 @@ function provide(key, value) {
1711
1710
  }
1712
1711
  }
1713
1712
  else {
1714
- var provides = currentInstance._provided;
1715
- // by default an instance inherits its parent's provides object
1716
- // but when it needs to provide values of its own, it creates its
1717
- // own provides object using parent provides object as prototype.
1718
- // this way in `inject` we can simply look up injections from direct
1719
- // parent and let the prototype chain do the work.
1720
- var parentProvides = currentInstance.$parent && currentInstance.$parent._provided;
1721
- if (parentProvides === provides) {
1722
- provides = currentInstance._provided = Object.create(parentProvides);
1723
- }
1724
1713
  // TS doesn't allow symbol as index type
1725
- provides[key] = value;
1714
+ resolveProvided(currentInstance)[key] = value;
1715
+ }
1716
+ }
1717
+ function resolveProvided(vm) {
1718
+ // by default an instance inherits its parent's provides object
1719
+ // but when it needs to provide values of its own, it creates its
1720
+ // own provides object using parent provides object as prototype.
1721
+ // this way in `inject` we can simply look up injections from direct
1722
+ // parent and let the prototype chain do the work.
1723
+ var existing = vm._provided;
1724
+ var parentProvides = vm.$parent && vm.$parent._provided;
1725
+ if (parentProvides === existing) {
1726
+ return (vm._provided = Object.create(parentProvides));
1727
+ }
1728
+ else {
1729
+ return existing;
1726
1730
  }
1727
1731
  }
1728
1732
  function inject(key, defaultValue, treatDefaultAsFactory) {
@@ -2448,7 +2452,19 @@ function createSetupContext(vm) {
2448
2452
  var exposeCalled = false;
2449
2453
  return {
2450
2454
  get attrs() {
2451
- return initAttrsProxy(vm);
2455
+ if (!vm._attrsProxy) {
2456
+ var proxy = (vm._attrsProxy = {});
2457
+ def(proxy, '_v_attr_proxy', true);
2458
+ syncSetupProxy(proxy, vm.$attrs, emptyObject, vm, '$attrs');
2459
+ }
2460
+ return vm._attrsProxy;
2461
+ },
2462
+ get listeners() {
2463
+ if (!vm._listenersProxy) {
2464
+ var proxy = (vm._listenersProxy = {});
2465
+ syncSetupProxy(proxy, vm.$listeners, emptyObject, vm, '$listeners');
2466
+ }
2467
+ return vm._listenersProxy;
2452
2468
  },
2453
2469
  get slots() {
2454
2470
  return initSlotsProxy(vm);
@@ -2469,20 +2485,12 @@ function createSetupContext(vm) {
2469
2485
  }
2470
2486
  };
2471
2487
  }
2472
- function initAttrsProxy(vm) {
2473
- if (!vm._attrsProxy) {
2474
- var proxy = (vm._attrsProxy = {});
2475
- def(proxy, '_v_attr_proxy', true);
2476
- syncSetupAttrs(proxy, vm.$attrs, emptyObject, vm);
2477
- }
2478
- return vm._attrsProxy;
2479
- }
2480
- function syncSetupAttrs(to, from, prev, instance) {
2488
+ function syncSetupProxy(to, from, prev, instance, type) {
2481
2489
  var changed = false;
2482
2490
  for (var key in from) {
2483
2491
  if (!(key in to)) {
2484
2492
  changed = true;
2485
- defineProxyAttr(to, key, instance);
2493
+ defineProxyAttr(to, key, instance, type);
2486
2494
  }
2487
2495
  else if (from[key] !== prev[key]) {
2488
2496
  changed = true;
@@ -2496,12 +2504,12 @@ function syncSetupAttrs(to, from, prev, instance) {
2496
2504
  }
2497
2505
  return changed;
2498
2506
  }
2499
- function defineProxyAttr(proxy, key, instance) {
2507
+ function defineProxyAttr(proxy, key, instance, type) {
2500
2508
  Object.defineProperty(proxy, key, {
2501
2509
  enumerable: true,
2502
2510
  configurable: true,
2503
2511
  get: function () {
2504
- return instance.$attrs[key];
2512
+ return instance[type][key];
2505
2513
  }
2506
2514
  });
2507
2515
  }
@@ -2522,17 +2530,27 @@ function syncSetupSlots(to, from) {
2522
2530
  }
2523
2531
  }
2524
2532
  /**
2525
- * @internal use manual type def
2533
+ * @internal use manual type def because public setup context type relies on
2534
+ * legacy VNode types
2526
2535
  */
2527
2536
  function useSlots() {
2528
2537
  return getContext().slots;
2529
2538
  }
2530
2539
  /**
2531
- * @internal use manual type def
2540
+ * @internal use manual type def because public setup context type relies on
2541
+ * legacy VNode types
2532
2542
  */
2533
2543
  function useAttrs() {
2534
2544
  return getContext().attrs;
2535
2545
  }
2546
+ /**
2547
+ * Vue 2 only
2548
+ * @internal use manual type def because public setup context type relies on
2549
+ * legacy VNode types
2550
+ */
2551
+ function useListeners() {
2552
+ return getContext().listeners;
2553
+ }
2536
2554
  function getContext() {
2537
2555
  if (process.env.NODE_ENV !== 'production' && !currentInstance) {
2538
2556
  warn("useContext() called without active instance.");
@@ -2576,7 +2594,9 @@ function initRender(vm) {
2576
2594
  var parentVnode = (vm.$vnode = options._parentVnode); // the placeholder node in parent tree
2577
2595
  var renderContext = parentVnode && parentVnode.context;
2578
2596
  vm.$slots = resolveSlots(options._renderChildren, renderContext);
2579
- vm.$scopedSlots = emptyObject;
2597
+ vm.$scopedSlots = parentVnode
2598
+ ? normalizeScopedSlots(vm.$parent, parentVnode.data.scopedSlots, vm.$slots)
2599
+ : emptyObject;
2580
2600
  // bind the createElement fn to this instance
2581
2601
  // so that we get proper render context inside it.
2582
2602
  // args order: tag, data, children, normalizationType, alwaysNormalize
@@ -2614,7 +2634,7 @@ function renderMixin(Vue) {
2614
2634
  Vue.prototype._render = function () {
2615
2635
  var vm = this;
2616
2636
  var _a = vm.$options, render = _a.render, _parentVnode = _a._parentVnode;
2617
- if (_parentVnode) {
2637
+ if (_parentVnode && vm._isMounted) {
2618
2638
  vm.$scopedSlots = normalizeScopedSlots(vm.$parent, _parentVnode.data.scopedSlots, vm.$slots, vm.$scopedSlots);
2619
2639
  if (vm._slotsProxy) {
2620
2640
  syncSetupSlots(vm._slotsProxy, vm.$scopedSlots);
@@ -3259,17 +3279,21 @@ var onBeforeUpdate = createLifeCycle('beforeUpdate');
3259
3279
  var onUpdated = createLifeCycle('updated');
3260
3280
  var onBeforeUnmount = createLifeCycle('beforeDestroy');
3261
3281
  var onUnmounted = createLifeCycle('destroyed');
3262
- var onErrorCaptured = createLifeCycle('errorCaptured');
3263
3282
  var onActivated = createLifeCycle('activated');
3264
3283
  var onDeactivated = createLifeCycle('deactivated');
3265
3284
  var onServerPrefetch = createLifeCycle('serverPrefetch');
3266
3285
  var onRenderTracked = createLifeCycle('renderTracked');
3267
- var onRenderTriggered = createLifeCycle('renderTriggered');
3286
+ var onRenderTriggered = createLifeCycle('renderTriggered');
3287
+ var injectErrorCapturedHook = createLifeCycle('errorCaptured');
3288
+ function onErrorCaptured(hook, target) {
3289
+ if (target === void 0) { target = currentInstance; }
3290
+ injectErrorCapturedHook(hook, target);
3291
+ }
3268
3292
 
3269
3293
  /**
3270
3294
  * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
3271
3295
  */
3272
- var version = '2.7.6';
3296
+ var version = '2.7.9';
3273
3297
  /**
3274
3298
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
3275
3299
  */
@@ -3328,11 +3352,16 @@ var uid$1 = 0;
3328
3352
  */
3329
3353
  var Watcher = /** @class */ (function () {
3330
3354
  function Watcher(vm, expOrFn, cb, options, isRenderWatcher) {
3331
- recordEffectScope(this, activeEffectScope || (vm ? vm._scope : undefined));
3332
- if ((this.vm = vm)) {
3333
- if (isRenderWatcher) {
3334
- vm._watcher = this;
3335
- }
3355
+ recordEffectScope(this,
3356
+ // if the active effect scope is manually created (not a component scope),
3357
+ // prioritize it
3358
+ activeEffectScope && !activeEffectScope._vm
3359
+ ? activeEffectScope
3360
+ : vm
3361
+ ? vm._scope
3362
+ : undefined);
3363
+ if ((this.vm = vm) && isRenderWatcher) {
3364
+ vm._watcher = this;
3336
3365
  }
3337
3366
  // options
3338
3367
  if (options) {
@@ -3352,6 +3381,7 @@ var Watcher = /** @class */ (function () {
3352
3381
  this.cb = cb;
3353
3382
  this.id = ++uid$1; // uid for batching
3354
3383
  this.active = true;
3384
+ this.post = false;
3355
3385
  this.dirty = this.lazy; // for lazy watchers
3356
3386
  this.deps = [];
3357
3387
  this.newDeps = [];
@@ -3876,12 +3906,19 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
3876
3906
  if (vm._attrsProxy) {
3877
3907
  // force update if attrs are accessed and has changed since it may be
3878
3908
  // passed to a child component.
3879
- if (syncSetupAttrs(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm)) {
3909
+ if (syncSetupProxy(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm, '$attrs')) {
3880
3910
  needsForceUpdate = true;
3881
3911
  }
3882
3912
  }
3883
3913
  vm.$attrs = attrs;
3884
- vm.$listeners = listeners || emptyObject;
3914
+ // update listeners
3915
+ listeners = listeners || emptyObject;
3916
+ var prevListeners = vm.$options._parentListeners;
3917
+ if (vm._listenersProxy) {
3918
+ syncSetupProxy(vm._listenersProxy, listeners, prevListeners || emptyObject, vm, '$listeners');
3919
+ }
3920
+ vm.$listeners = vm.$options._parentListeners = listeners;
3921
+ updateComponentListeners(vm, listeners, prevListeners);
3885
3922
  // update props
3886
3923
  if (propsData && vm.$options.props) {
3887
3924
  toggleObserving(false);
@@ -3896,11 +3933,6 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
3896
3933
  // keep a copy of raw propsData
3897
3934
  vm.$options.propsData = propsData;
3898
3935
  }
3899
- // update listeners
3900
- listeners = listeners || emptyObject;
3901
- var oldListeners = vm.$options._parentListeners;
3902
- vm.$options._parentListeners = listeners;
3903
- updateComponentListeners(vm, listeners, oldListeners);
3904
3936
  // resolve slots + force update if has children
3905
3937
  if (needsForceUpdate) {
3906
3938
  vm.$slots = resolveSlots(renderChildren, parentVnode.context);
@@ -4015,6 +4047,16 @@ if (inBrowser && !isIE) {
4015
4047
  getNow = function () { return performance_1.now(); };
4016
4048
  }
4017
4049
  }
4050
+ var sortCompareFn = function (a, b) {
4051
+ if (a.post) {
4052
+ if (!b.post)
4053
+ return 1;
4054
+ }
4055
+ else if (b.post) {
4056
+ return -1;
4057
+ }
4058
+ return a.id - b.id;
4059
+ };
4018
4060
  /**
4019
4061
  * Flush both queues and run the watchers.
4020
4062
  */
@@ -4030,7 +4072,7 @@ function flushSchedulerQueue() {
4030
4072
  // user watchers are created before the render watcher)
4031
4073
  // 3. If a component is destroyed during a parent component's watcher run,
4032
4074
  // its watchers can be skipped.
4033
- queue.sort(function (a, b) { return a.id - b.id; });
4075
+ queue.sort(sortCompareFn);
4034
4076
  // do not cache length because more watchers might be pushed
4035
4077
  // as we run existing watchers
4036
4078
  for (index = 0; index < queue.length; index++) {
@@ -4138,12 +4180,14 @@ function initProvide(vm) {
4138
4180
  if (!isObject(provided)) {
4139
4181
  return;
4140
4182
  }
4183
+ var source = resolveProvided(vm);
4184
+ // IE9 doesn't support Object.getOwnPropertyDescriptors so we have to
4185
+ // iterate the keys ourselves.
4141
4186
  var keys = hasSymbol ? Reflect.ownKeys(provided) : Object.keys(provided);
4142
- setCurrentInstance(vm);
4143
4187
  for (var i = 0; i < keys.length; i++) {
4144
- provide(keys[i], provided[keys[i]]);
4188
+ var key = keys[i];
4189
+ Object.defineProperty(source, key, Object.getOwnPropertyDescriptor(provided, key));
4145
4190
  }
4146
- setCurrentInstance();
4147
4191
  }
4148
4192
  }
4149
4193
  function initInjections(vm) {
@@ -5184,13 +5228,13 @@ if (process.env.NODE_ENV !== 'production') {
5184
5228
  'referenced during render. Make sure that this property is reactive, ' +
5185
5229
  'either in the data option, or for class-based components, by ' +
5186
5230
  'initializing the property. ' +
5187
- 'See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
5231
+ 'See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
5188
5232
  };
5189
5233
  var warnReservedPrefix_1 = function (target, key) {
5190
5234
  warn("Property \"".concat(key, "\" must be accessed with \"$data.").concat(key, "\" because ") +
5191
5235
  'properties starting with "$" or "_" are not proxied in the Vue instance to ' +
5192
5236
  'prevent conflicts with Vue internals. ' +
5193
- 'See: https://vuejs.org/v2/api/#data', target);
5237
+ 'See: https://v2.vuejs.org/v2/api/#data', target);
5194
5238
  };
5195
5239
  var hasProxy_1 = typeof Proxy !== 'undefined' && isNative(Proxy);
5196
5240
  if (hasProxy_1) {
@@ -5336,7 +5380,7 @@ function initData(vm) {
5336
5380
  data = {};
5337
5381
  process.env.NODE_ENV !== 'production' &&
5338
5382
  warn('data functions should return an object:\n' +
5339
- 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
5383
+ 'https://v2.vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
5340
5384
  }
5341
5385
  // proxy data on instance
5342
5386
  var keys = Object.keys(data);
@@ -5569,6 +5613,7 @@ function initMixin$1(Vue) {
5569
5613
  vm.__v_skip = true;
5570
5614
  // effect scope
5571
5615
  vm._scope = new EffectScope(true /* detached */);
5616
+ vm._scope._vm = true;
5572
5617
  // merge options
5573
5618
  if (options && options._isComponent) {
5574
5619
  // optimize internal component instantiation
@@ -7146,7 +7191,16 @@ function normalizeDirectives(dirs, vm) {
7146
7191
  }
7147
7192
  res[getRawDirName(dir)] = dir;
7148
7193
  if (vm._setupState && vm._setupState.__sfc) {
7149
- dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7194
+ var setupDef = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7195
+ if (typeof setupDef === 'function') {
7196
+ dir.def = {
7197
+ bind: setupDef,
7198
+ update: setupDef,
7199
+ };
7200
+ }
7201
+ else {
7202
+ dir.def = setupDef;
7203
+ }
7150
7204
  }
7151
7205
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
7152
7206
  }
@@ -8693,4 +8747,4 @@ if (inBrowser) {
8693
8747
  }, 0);
8694
8748
  }
8695
8749
 
8696
- 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 };
8750
+ 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, useListeners, useSlots, version, watch, watchEffect, watchPostEffect, watchSyncEffect };