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 @@
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
  }
@@ -1498,8 +1498,7 @@
1498
1498
  var oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
1499
1499
  // overwrite default run
1500
1500
  watcher.run = function () {
1501
- if (!watcher.active &&
1502
- !(flush === 'pre' && instance && instance._isBeingDestroyed)) {
1501
+ if (!watcher.active) {
1503
1502
  return;
1504
1503
  }
1505
1504
  if (cb) {
@@ -1534,7 +1533,7 @@
1534
1533
  watcher.update = watcher.run;
1535
1534
  }
1536
1535
  else if (flush === 'post') {
1537
- watcher.id = Infinity;
1536
+ watcher.post = true;
1538
1537
  watcher.update = function () { return queueWatcher(watcher); };
1539
1538
  }
1540
1539
  else {
@@ -1686,18 +1685,23 @@
1686
1685
  }
1687
1686
  }
1688
1687
  else {
1689
- var provides = currentInstance._provided;
1690
- // by default an instance inherits its parent's provides object
1691
- // but when it needs to provide values of its own, it creates its
1692
- // own provides object using parent provides object as prototype.
1693
- // this way in `inject` we can simply look up injections from direct
1694
- // parent and let the prototype chain do the work.
1695
- var parentProvides = currentInstance.$parent && currentInstance.$parent._provided;
1696
- if (parentProvides === provides) {
1697
- provides = currentInstance._provided = Object.create(parentProvides);
1698
- }
1699
1688
  // TS doesn't allow symbol as index type
1700
- provides[key] = value;
1689
+ resolveProvided(currentInstance)[key] = value;
1690
+ }
1691
+ }
1692
+ function resolveProvided(vm) {
1693
+ // by default an instance inherits its parent's provides object
1694
+ // but when it needs to provide values of its own, it creates its
1695
+ // own provides object using parent provides object as prototype.
1696
+ // this way in `inject` we can simply look up injections from direct
1697
+ // parent and let the prototype chain do the work.
1698
+ var existing = vm._provided;
1699
+ var parentProvides = vm.$parent && vm.$parent._provided;
1700
+ if (parentProvides === existing) {
1701
+ return (vm._provided = Object.create(parentProvides));
1702
+ }
1703
+ else {
1704
+ return existing;
1701
1705
  }
1702
1706
  }
1703
1707
  function inject(key, defaultValue, treatDefaultAsFactory) {
@@ -2421,7 +2425,19 @@
2421
2425
  var exposeCalled = false;
2422
2426
  return {
2423
2427
  get attrs() {
2424
- return initAttrsProxy(vm);
2428
+ if (!vm._attrsProxy) {
2429
+ var proxy = (vm._attrsProxy = {});
2430
+ def(proxy, '_v_attr_proxy', true);
2431
+ syncSetupProxy(proxy, vm.$attrs, emptyObject, vm, '$attrs');
2432
+ }
2433
+ return vm._attrsProxy;
2434
+ },
2435
+ get listeners() {
2436
+ if (!vm._listenersProxy) {
2437
+ var proxy = (vm._listenersProxy = {});
2438
+ syncSetupProxy(proxy, vm.$listeners, emptyObject, vm, '$listeners');
2439
+ }
2440
+ return vm._listenersProxy;
2425
2441
  },
2426
2442
  get slots() {
2427
2443
  return initSlotsProxy(vm);
@@ -2442,20 +2458,12 @@
2442
2458
  }
2443
2459
  };
2444
2460
  }
2445
- function initAttrsProxy(vm) {
2446
- if (!vm._attrsProxy) {
2447
- var proxy = (vm._attrsProxy = {});
2448
- def(proxy, '_v_attr_proxy', true);
2449
- syncSetupAttrs(proxy, vm.$attrs, emptyObject, vm);
2450
- }
2451
- return vm._attrsProxy;
2452
- }
2453
- function syncSetupAttrs(to, from, prev, instance) {
2461
+ function syncSetupProxy(to, from, prev, instance, type) {
2454
2462
  var changed = false;
2455
2463
  for (var key in from) {
2456
2464
  if (!(key in to)) {
2457
2465
  changed = true;
2458
- defineProxyAttr(to, key, instance);
2466
+ defineProxyAttr(to, key, instance, type);
2459
2467
  }
2460
2468
  else if (from[key] !== prev[key]) {
2461
2469
  changed = true;
@@ -2469,12 +2477,12 @@
2469
2477
  }
2470
2478
  return changed;
2471
2479
  }
2472
- function defineProxyAttr(proxy, key, instance) {
2480
+ function defineProxyAttr(proxy, key, instance, type) {
2473
2481
  Object.defineProperty(proxy, key, {
2474
2482
  enumerable: true,
2475
2483
  configurable: true,
2476
2484
  get: function () {
2477
- return instance.$attrs[key];
2485
+ return instance[type][key];
2478
2486
  }
2479
2487
  });
2480
2488
  }
@@ -2495,17 +2503,27 @@
2495
2503
  }
2496
2504
  }
2497
2505
  /**
2498
- * @internal use manual type def
2506
+ * @internal use manual type def because public setup context type relies on
2507
+ * legacy VNode types
2499
2508
  */
2500
2509
  function useSlots() {
2501
2510
  return getContext().slots;
2502
2511
  }
2503
2512
  /**
2504
- * @internal use manual type def
2513
+ * @internal use manual type def because public setup context type relies on
2514
+ * legacy VNode types
2505
2515
  */
2506
2516
  function useAttrs() {
2507
2517
  return getContext().attrs;
2508
2518
  }
2519
+ /**
2520
+ * Vue 2 only
2521
+ * @internal use manual type def because public setup context type relies on
2522
+ * legacy VNode types
2523
+ */
2524
+ function useListeners() {
2525
+ return getContext().listeners;
2526
+ }
2509
2527
  function getContext() {
2510
2528
  if (!currentInstance) {
2511
2529
  warn("useContext() called without active instance.");
@@ -2549,7 +2567,9 @@
2549
2567
  var parentVnode = (vm.$vnode = options._parentVnode); // the placeholder node in parent tree
2550
2568
  var renderContext = parentVnode && parentVnode.context;
2551
2569
  vm.$slots = resolveSlots(options._renderChildren, renderContext);
2552
- vm.$scopedSlots = emptyObject;
2570
+ vm.$scopedSlots = parentVnode
2571
+ ? normalizeScopedSlots(vm.$parent, parentVnode.data.scopedSlots, vm.$slots)
2572
+ : emptyObject;
2553
2573
  // bind the createElement fn to this instance
2554
2574
  // so that we get proper render context inside it.
2555
2575
  // args order: tag, data, children, normalizationType, alwaysNormalize
@@ -2583,7 +2603,7 @@
2583
2603
  Vue.prototype._render = function () {
2584
2604
  var vm = this;
2585
2605
  var _a = vm.$options, render = _a.render, _parentVnode = _a._parentVnode;
2586
- if (_parentVnode) {
2606
+ if (_parentVnode && vm._isMounted) {
2587
2607
  vm.$scopedSlots = normalizeScopedSlots(vm.$parent, _parentVnode.data.scopedSlots, vm.$slots, vm.$scopedSlots);
2588
2608
  if (vm._slotsProxy) {
2589
2609
  syncSetupSlots(vm._slotsProxy, vm.$scopedSlots);
@@ -3214,17 +3234,21 @@
3214
3234
  var onUpdated = createLifeCycle('updated');
3215
3235
  var onBeforeUnmount = createLifeCycle('beforeDestroy');
3216
3236
  var onUnmounted = createLifeCycle('destroyed');
3217
- var onErrorCaptured = createLifeCycle('errorCaptured');
3218
3237
  var onActivated = createLifeCycle('activated');
3219
3238
  var onDeactivated = createLifeCycle('deactivated');
3220
3239
  var onServerPrefetch = createLifeCycle('serverPrefetch');
3221
3240
  var onRenderTracked = createLifeCycle('renderTracked');
3222
- var onRenderTriggered = createLifeCycle('renderTriggered');
3241
+ var onRenderTriggered = createLifeCycle('renderTriggered');
3242
+ var injectErrorCapturedHook = createLifeCycle('errorCaptured');
3243
+ function onErrorCaptured(hook, target) {
3244
+ if (target === void 0) { target = currentInstance; }
3245
+ injectErrorCapturedHook(hook, target);
3246
+ }
3223
3247
 
3224
3248
  /**
3225
3249
  * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
3226
3250
  */
3227
- var version = '2.7.6';
3251
+ var version = '2.7.9';
3228
3252
  /**
3229
3253
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
3230
3254
  */
@@ -3270,6 +3294,7 @@
3270
3294
  getCurrentInstance: getCurrentInstance,
3271
3295
  useSlots: useSlots,
3272
3296
  useAttrs: useAttrs,
3297
+ useListeners: useListeners,
3273
3298
  mergeDefaults: mergeDefaults,
3274
3299
  nextTick: nextTick,
3275
3300
  set: set,
@@ -3283,12 +3308,12 @@
3283
3308
  onUpdated: onUpdated,
3284
3309
  onBeforeUnmount: onBeforeUnmount,
3285
3310
  onUnmounted: onUnmounted,
3286
- onErrorCaptured: onErrorCaptured,
3287
3311
  onActivated: onActivated,
3288
3312
  onDeactivated: onDeactivated,
3289
3313
  onServerPrefetch: onServerPrefetch,
3290
3314
  onRenderTracked: onRenderTracked,
3291
- onRenderTriggered: onRenderTriggered
3315
+ onRenderTriggered: onRenderTriggered,
3316
+ onErrorCaptured: onErrorCaptured
3292
3317
  });
3293
3318
 
3294
3319
  var seenObjects = new _Set();
@@ -3342,11 +3367,16 @@
3342
3367
  */
3343
3368
  var Watcher = /** @class */ (function () {
3344
3369
  function Watcher(vm, expOrFn, cb, options, isRenderWatcher) {
3345
- recordEffectScope(this, activeEffectScope || (vm ? vm._scope : undefined));
3346
- if ((this.vm = vm)) {
3347
- if (isRenderWatcher) {
3348
- vm._watcher = this;
3349
- }
3370
+ recordEffectScope(this,
3371
+ // if the active effect scope is manually created (not a component scope),
3372
+ // prioritize it
3373
+ activeEffectScope && !activeEffectScope._vm
3374
+ ? activeEffectScope
3375
+ : vm
3376
+ ? vm._scope
3377
+ : undefined);
3378
+ if ((this.vm = vm) && isRenderWatcher) {
3379
+ vm._watcher = this;
3350
3380
  }
3351
3381
  // options
3352
3382
  if (options) {
@@ -3366,6 +3396,7 @@
3366
3396
  this.cb = cb;
3367
3397
  this.id = ++uid$1; // uid for batching
3368
3398
  this.active = true;
3399
+ this.post = false;
3369
3400
  this.dirty = this.lazy; // for lazy watchers
3370
3401
  this.deps = [];
3371
3402
  this.newDeps = [];
@@ -3889,12 +3920,19 @@
3889
3920
  if (vm._attrsProxy) {
3890
3921
  // force update if attrs are accessed and has changed since it may be
3891
3922
  // passed to a child component.
3892
- if (syncSetupAttrs(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm)) {
3923
+ if (syncSetupProxy(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm, '$attrs')) {
3893
3924
  needsForceUpdate = true;
3894
3925
  }
3895
3926
  }
3896
3927
  vm.$attrs = attrs;
3897
- vm.$listeners = listeners || emptyObject;
3928
+ // update listeners
3929
+ listeners = listeners || emptyObject;
3930
+ var prevListeners = vm.$options._parentListeners;
3931
+ if (vm._listenersProxy) {
3932
+ syncSetupProxy(vm._listenersProxy, listeners, prevListeners || emptyObject, vm, '$listeners');
3933
+ }
3934
+ vm.$listeners = vm.$options._parentListeners = listeners;
3935
+ updateComponentListeners(vm, listeners, prevListeners);
3898
3936
  // update props
3899
3937
  if (propsData && vm.$options.props) {
3900
3938
  toggleObserving(false);
@@ -3909,11 +3947,6 @@
3909
3947
  // keep a copy of raw propsData
3910
3948
  vm.$options.propsData = propsData;
3911
3949
  }
3912
- // update listeners
3913
- listeners = listeners || emptyObject;
3914
- var oldListeners = vm.$options._parentListeners;
3915
- vm.$options._parentListeners = listeners;
3916
- updateComponentListeners(vm, listeners, oldListeners);
3917
3950
  // resolve slots + force update if has children
3918
3951
  if (needsForceUpdate) {
3919
3952
  vm.$slots = resolveSlots(renderChildren, parentVnode.context);
@@ -4028,6 +4061,16 @@
4028
4061
  getNow = function () { return performance_1.now(); };
4029
4062
  }
4030
4063
  }
4064
+ var sortCompareFn = function (a, b) {
4065
+ if (a.post) {
4066
+ if (!b.post)
4067
+ return 1;
4068
+ }
4069
+ else if (b.post) {
4070
+ return -1;
4071
+ }
4072
+ return a.id - b.id;
4073
+ };
4031
4074
  /**
4032
4075
  * Flush both queues and run the watchers.
4033
4076
  */
@@ -4043,7 +4086,7 @@
4043
4086
  // user watchers are created before the render watcher)
4044
4087
  // 3. If a component is destroyed during a parent component's watcher run,
4045
4088
  // its watchers can be skipped.
4046
- queue.sort(function (a, b) { return a.id - b.id; });
4089
+ queue.sort(sortCompareFn);
4047
4090
  // do not cache length because more watchers might be pushed
4048
4091
  // as we run existing watchers
4049
4092
  for (index = 0; index < queue.length; index++) {
@@ -4151,12 +4194,14 @@
4151
4194
  if (!isObject(provided)) {
4152
4195
  return;
4153
4196
  }
4197
+ var source = resolveProvided(vm);
4198
+ // IE9 doesn't support Object.getOwnPropertyDescriptors so we have to
4199
+ // iterate the keys ourselves.
4154
4200
  var keys = hasSymbol ? Reflect.ownKeys(provided) : Object.keys(provided);
4155
- setCurrentInstance(vm);
4156
4201
  for (var i = 0; i < keys.length; i++) {
4157
- provide(keys[i], provided[keys[i]]);
4202
+ var key = keys[i];
4203
+ Object.defineProperty(source, key, Object.getOwnPropertyDescriptor(provided, key));
4158
4204
  }
4159
- setCurrentInstance();
4160
4205
  }
4161
4206
  }
4162
4207
  function initInjections(vm) {
@@ -5193,13 +5238,13 @@
5193
5238
  'referenced during render. Make sure that this property is reactive, ' +
5194
5239
  'either in the data option, or for class-based components, by ' +
5195
5240
  'initializing the property. ' +
5196
- 'See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
5241
+ 'See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
5197
5242
  };
5198
5243
  var warnReservedPrefix_1 = function (target, key) {
5199
5244
  warn("Property \"".concat(key, "\" must be accessed with \"$data.").concat(key, "\" because ") +
5200
5245
  'properties starting with "$" or "_" are not proxied in the Vue instance to ' +
5201
5246
  'prevent conflicts with Vue internals. ' +
5202
- 'See: https://vuejs.org/v2/api/#data', target);
5247
+ 'See: https://v2.vuejs.org/v2/api/#data', target);
5203
5248
  };
5204
5249
  var hasProxy_1 = typeof Proxy !== 'undefined' && isNative(Proxy);
5205
5250
  if (hasProxy_1) {
@@ -5341,7 +5386,7 @@
5341
5386
  if (!isPlainObject(data)) {
5342
5387
  data = {};
5343
5388
  warn('data functions should return an object:\n' +
5344
- 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
5389
+ 'https://v2.vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
5345
5390
  }
5346
5391
  // proxy data on instance
5347
5392
  var keys = Object.keys(data);
@@ -5573,6 +5618,7 @@
5573
5618
  vm.__v_skip = true;
5574
5619
  // effect scope
5575
5620
  vm._scope = new EffectScope(true /* detached */);
5621
+ vm._scope._vm = true;
5576
5622
  // merge options
5577
5623
  if (options && options._isComponent) {
5578
5624
  // optimize internal component instantiation
@@ -7145,7 +7191,16 @@
7145
7191
  }
7146
7192
  res[getRawDirName(dir)] = dir;
7147
7193
  if (vm._setupState && vm._setupState.__sfc) {
7148
- 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
+ }
7149
7204
  }
7150
7205
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
7151
7206
  }