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
  */
@@ -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
  }
@@ -1446,8 +1446,7 @@ function doWatch(source, cb, { immediate, deep, flush = 'pre', onTrack, onTrigge
1446
1446
  let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
1447
1447
  // overwrite default run
1448
1448
  watcher.run = () => {
1449
- if (!watcher.active &&
1450
- !(flush === 'pre' && instance && instance._isBeingDestroyed)) {
1449
+ if (!watcher.active) {
1451
1450
  return;
1452
1451
  }
1453
1452
  if (cb) {
@@ -1480,7 +1479,7 @@ function doWatch(source, cb, { immediate, deep, flush = 'pre', onTrack, onTrigge
1480
1479
  watcher.update = watcher.run;
1481
1480
  }
1482
1481
  else if (flush === 'post') {
1483
- watcher.id = Infinity;
1482
+ watcher.post = true;
1484
1483
  watcher.update = () => queueWatcher(watcher);
1485
1484
  }
1486
1485
  else {
@@ -1629,18 +1628,23 @@ function provide(key, value) {
1629
1628
  }
1630
1629
  }
1631
1630
  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
1631
  // TS doesn't allow symbol as index type
1643
- provides[key] = value;
1632
+ resolveProvided(currentInstance)[key] = value;
1633
+ }
1634
+ }
1635
+ function resolveProvided(vm) {
1636
+ // by default an instance inherits its parent's provides object
1637
+ // but when it needs to provide values of its own, it creates its
1638
+ // own provides object using parent provides object as prototype.
1639
+ // this way in `inject` we can simply look up injections from direct
1640
+ // parent and let the prototype chain do the work.
1641
+ const existing = vm._provided;
1642
+ const parentProvides = vm.$parent && vm.$parent._provided;
1643
+ if (parentProvides === existing) {
1644
+ return (vm._provided = Object.create(parentProvides));
1645
+ }
1646
+ else {
1647
+ return existing;
1644
1648
  }
1645
1649
  }
1646
1650
  function inject(key, defaultValue, treatDefaultAsFactory = false) {
@@ -2360,7 +2364,19 @@ function createSetupContext(vm) {
2360
2364
  let exposeCalled = false;
2361
2365
  return {
2362
2366
  get attrs() {
2363
- return initAttrsProxy(vm);
2367
+ if (!vm._attrsProxy) {
2368
+ const proxy = (vm._attrsProxy = {});
2369
+ def(proxy, '_v_attr_proxy', true);
2370
+ syncSetupProxy(proxy, vm.$attrs, emptyObject, vm, '$attrs');
2371
+ }
2372
+ return vm._attrsProxy;
2373
+ },
2374
+ get listeners() {
2375
+ if (!vm._listenersProxy) {
2376
+ const proxy = (vm._listenersProxy = {});
2377
+ syncSetupProxy(proxy, vm.$listeners, emptyObject, vm, '$listeners');
2378
+ }
2379
+ return vm._listenersProxy;
2364
2380
  },
2365
2381
  get slots() {
2366
2382
  return initSlotsProxy(vm);
@@ -2379,20 +2395,12 @@ function createSetupContext(vm) {
2379
2395
  }
2380
2396
  };
2381
2397
  }
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) {
2398
+ function syncSetupProxy(to, from, prev, instance, type) {
2391
2399
  let changed = false;
2392
2400
  for (const key in from) {
2393
2401
  if (!(key in to)) {
2394
2402
  changed = true;
2395
- defineProxyAttr(to, key, instance);
2403
+ defineProxyAttr(to, key, instance, type);
2396
2404
  }
2397
2405
  else if (from[key] !== prev[key]) {
2398
2406
  changed = true;
@@ -2406,12 +2414,12 @@ function syncSetupAttrs(to, from, prev, instance) {
2406
2414
  }
2407
2415
  return changed;
2408
2416
  }
2409
- function defineProxyAttr(proxy, key, instance) {
2417
+ function defineProxyAttr(proxy, key, instance, type) {
2410
2418
  Object.defineProperty(proxy, key, {
2411
2419
  enumerable: true,
2412
2420
  configurable: true,
2413
2421
  get() {
2414
- return instance.$attrs[key];
2422
+ return instance[type][key];
2415
2423
  }
2416
2424
  });
2417
2425
  }
@@ -2432,17 +2440,27 @@ function syncSetupSlots(to, from) {
2432
2440
  }
2433
2441
  }
2434
2442
  /**
2435
- * @internal use manual type def
2443
+ * @internal use manual type def because public setup context type relies on
2444
+ * legacy VNode types
2436
2445
  */
2437
2446
  function useSlots() {
2438
2447
  return getContext().slots;
2439
2448
  }
2440
2449
  /**
2441
- * @internal use manual type def
2450
+ * @internal use manual type def because public setup context type relies on
2451
+ * legacy VNode types
2442
2452
  */
2443
2453
  function useAttrs() {
2444
2454
  return getContext().attrs;
2445
2455
  }
2456
+ /**
2457
+ * Vue 2 only
2458
+ * @internal use manual type def because public setup context type relies on
2459
+ * legacy VNode types
2460
+ */
2461
+ function useListeners() {
2462
+ return getContext().listeners;
2463
+ }
2446
2464
  function getContext() {
2447
2465
  if (!currentInstance) {
2448
2466
  warn(`useContext() called without active instance.`);
@@ -2486,7 +2504,9 @@ function initRender(vm) {
2486
2504
  const parentVnode = (vm.$vnode = options._parentVnode); // the placeholder node in parent tree
2487
2505
  const renderContext = parentVnode && parentVnode.context;
2488
2506
  vm.$slots = resolveSlots(options._renderChildren, renderContext);
2489
- vm.$scopedSlots = emptyObject;
2507
+ vm.$scopedSlots = parentVnode
2508
+ ? normalizeScopedSlots(vm.$parent, parentVnode.data.scopedSlots, vm.$slots)
2509
+ : emptyObject;
2490
2510
  // bind the createElement fn to this instance
2491
2511
  // so that we get proper render context inside it.
2492
2512
  // args order: tag, data, children, normalizationType, alwaysNormalize
@@ -2520,7 +2540,7 @@ function renderMixin(Vue) {
2520
2540
  Vue.prototype._render = function () {
2521
2541
  const vm = this;
2522
2542
  const { render, _parentVnode } = vm.$options;
2523
- if (_parentVnode) {
2543
+ if (_parentVnode && vm._isMounted) {
2524
2544
  vm.$scopedSlots = normalizeScopedSlots(vm.$parent, _parentVnode.data.scopedSlots, vm.$slots, vm.$scopedSlots);
2525
2545
  if (vm._slotsProxy) {
2526
2546
  syncSetupSlots(vm._slotsProxy, vm.$scopedSlots);
@@ -3155,17 +3175,20 @@ const onBeforeUpdate = createLifeCycle('beforeUpdate');
3155
3175
  const onUpdated = createLifeCycle('updated');
3156
3176
  const onBeforeUnmount = createLifeCycle('beforeDestroy');
3157
3177
  const onUnmounted = createLifeCycle('destroyed');
3158
- const onErrorCaptured = createLifeCycle('errorCaptured');
3159
3178
  const onActivated = createLifeCycle('activated');
3160
3179
  const onDeactivated = createLifeCycle('deactivated');
3161
3180
  const onServerPrefetch = createLifeCycle('serverPrefetch');
3162
3181
  const onRenderTracked = createLifeCycle('renderTracked');
3163
- const onRenderTriggered = createLifeCycle('renderTriggered');
3182
+ const onRenderTriggered = createLifeCycle('renderTriggered');
3183
+ const injectErrorCapturedHook = createLifeCycle('errorCaptured');
3184
+ function onErrorCaptured(hook, target = currentInstance) {
3185
+ injectErrorCapturedHook(hook, target);
3186
+ }
3164
3187
 
3165
3188
  /**
3166
3189
  * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
3167
3190
  */
3168
- const version = '2.7.6';
3191
+ const version = '2.7.9';
3169
3192
  /**
3170
3193
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
3171
3194
  */
@@ -3211,6 +3234,7 @@ var vca = /*#__PURE__*/Object.freeze({
3211
3234
  getCurrentInstance: getCurrentInstance,
3212
3235
  useSlots: useSlots,
3213
3236
  useAttrs: useAttrs,
3237
+ useListeners: useListeners,
3214
3238
  mergeDefaults: mergeDefaults,
3215
3239
  nextTick: nextTick,
3216
3240
  set: set,
@@ -3224,12 +3248,12 @@ var vca = /*#__PURE__*/Object.freeze({
3224
3248
  onUpdated: onUpdated,
3225
3249
  onBeforeUnmount: onBeforeUnmount,
3226
3250
  onUnmounted: onUnmounted,
3227
- onErrorCaptured: onErrorCaptured,
3228
3251
  onActivated: onActivated,
3229
3252
  onDeactivated: onDeactivated,
3230
3253
  onServerPrefetch: onServerPrefetch,
3231
3254
  onRenderTracked: onRenderTracked,
3232
- onRenderTriggered: onRenderTriggered
3255
+ onRenderTriggered: onRenderTriggered,
3256
+ onErrorCaptured: onErrorCaptured
3233
3257
  });
3234
3258
 
3235
3259
  const seenObjects = new _Set();
@@ -3283,11 +3307,16 @@ let uid$1 = 0;
3283
3307
  */
3284
3308
  class Watcher {
3285
3309
  constructor(vm, expOrFn, cb, options, isRenderWatcher) {
3286
- recordEffectScope(this, activeEffectScope || (vm ? vm._scope : undefined));
3287
- if ((this.vm = vm)) {
3288
- if (isRenderWatcher) {
3289
- vm._watcher = this;
3290
- }
3310
+ recordEffectScope(this,
3311
+ // if the active effect scope is manually created (not a component scope),
3312
+ // prioritize it
3313
+ activeEffectScope && !activeEffectScope._vm
3314
+ ? activeEffectScope
3315
+ : vm
3316
+ ? vm._scope
3317
+ : undefined);
3318
+ if ((this.vm = vm) && isRenderWatcher) {
3319
+ vm._watcher = this;
3291
3320
  }
3292
3321
  // options
3293
3322
  if (options) {
@@ -3307,6 +3336,7 @@ class Watcher {
3307
3336
  this.cb = cb;
3308
3337
  this.id = ++uid$1; // uid for batching
3309
3338
  this.active = true;
3339
+ this.post = false;
3310
3340
  this.dirty = this.lazy; // for lazy watchers
3311
3341
  this.deps = [];
3312
3342
  this.newDeps = [];
@@ -3829,12 +3859,19 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
3829
3859
  if (vm._attrsProxy) {
3830
3860
  // force update if attrs are accessed and has changed since it may be
3831
3861
  // passed to a child component.
3832
- if (syncSetupAttrs(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm)) {
3862
+ if (syncSetupProxy(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm, '$attrs')) {
3833
3863
  needsForceUpdate = true;
3834
3864
  }
3835
3865
  }
3836
3866
  vm.$attrs = attrs;
3837
- vm.$listeners = listeners || emptyObject;
3867
+ // update listeners
3868
+ listeners = listeners || emptyObject;
3869
+ const prevListeners = vm.$options._parentListeners;
3870
+ if (vm._listenersProxy) {
3871
+ syncSetupProxy(vm._listenersProxy, listeners, prevListeners || emptyObject, vm, '$listeners');
3872
+ }
3873
+ vm.$listeners = vm.$options._parentListeners = listeners;
3874
+ updateComponentListeners(vm, listeners, prevListeners);
3838
3875
  // update props
3839
3876
  if (propsData && vm.$options.props) {
3840
3877
  toggleObserving(false);
@@ -3849,11 +3886,6 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
3849
3886
  // keep a copy of raw propsData
3850
3887
  vm.$options.propsData = propsData;
3851
3888
  }
3852
- // update listeners
3853
- listeners = listeners || emptyObject;
3854
- const oldListeners = vm.$options._parentListeners;
3855
- vm.$options._parentListeners = listeners;
3856
- updateComponentListeners(vm, listeners, oldListeners);
3857
3889
  // resolve slots + force update if has children
3858
3890
  if (needsForceUpdate) {
3859
3891
  vm.$slots = resolveSlots(renderChildren, parentVnode.context);
@@ -3967,6 +3999,16 @@ if (inBrowser && !isIE) {
3967
3999
  getNow = () => performance.now();
3968
4000
  }
3969
4001
  }
4002
+ const sortCompareFn = (a, b) => {
4003
+ if (a.post) {
4004
+ if (!b.post)
4005
+ return 1;
4006
+ }
4007
+ else if (b.post) {
4008
+ return -1;
4009
+ }
4010
+ return a.id - b.id;
4011
+ };
3970
4012
  /**
3971
4013
  * Flush both queues and run the watchers.
3972
4014
  */
@@ -3982,7 +4024,7 @@ function flushSchedulerQueue() {
3982
4024
  // user watchers are created before the render watcher)
3983
4025
  // 3. If a component is destroyed during a parent component's watcher run,
3984
4026
  // its watchers can be skipped.
3985
- queue.sort((a, b) => a.id - b.id);
4027
+ queue.sort(sortCompareFn);
3986
4028
  // do not cache length because more watchers might be pushed
3987
4029
  // as we run existing watchers
3988
4030
  for (index = 0; index < queue.length; index++) {
@@ -4090,12 +4132,14 @@ function initProvide(vm) {
4090
4132
  if (!isObject(provided)) {
4091
4133
  return;
4092
4134
  }
4135
+ const source = resolveProvided(vm);
4136
+ // IE9 doesn't support Object.getOwnPropertyDescriptors so we have to
4137
+ // iterate the keys ourselves.
4093
4138
  const keys = hasSymbol ? Reflect.ownKeys(provided) : Object.keys(provided);
4094
- setCurrentInstance(vm);
4095
4139
  for (let i = 0; i < keys.length; i++) {
4096
- provide(keys[i], provided[keys[i]]);
4140
+ const key = keys[i];
4141
+ Object.defineProperty(source, key, Object.getOwnPropertyDescriptor(provided, key));
4097
4142
  }
4098
- setCurrentInstance();
4099
4143
  }
4100
4144
  }
4101
4145
  function initInjections(vm) {
@@ -5120,13 +5164,13 @@ let initProxy;
5120
5164
  'referenced during render. Make sure that this property is reactive, ' +
5121
5165
  'either in the data option, or for class-based components, by ' +
5122
5166
  'initializing the property. ' +
5123
- 'See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
5167
+ 'See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
5124
5168
  };
5125
5169
  const warnReservedPrefix = (target, key) => {
5126
5170
  warn(`Property "${key}" must be accessed with "$data.${key}" because ` +
5127
5171
  'properties starting with "$" or "_" are not proxied in the Vue instance to ' +
5128
5172
  'prevent conflicts with Vue internals. ' +
5129
- 'See: https://vuejs.org/v2/api/#data', target);
5173
+ 'See: https://v2.vuejs.org/v2/api/#data', target);
5130
5174
  };
5131
5175
  const hasProxy = typeof Proxy !== 'undefined' && isNative(Proxy);
5132
5176
  if (hasProxy) {
@@ -5265,7 +5309,7 @@ function initData(vm) {
5265
5309
  if (!isPlainObject(data)) {
5266
5310
  data = {};
5267
5311
  warn('data functions should return an object:\n' +
5268
- 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
5312
+ 'https://v2.vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
5269
5313
  }
5270
5314
  // proxy data on instance
5271
5315
  const keys = Object.keys(data);
@@ -5497,6 +5541,7 @@ function initMixin$1(Vue) {
5497
5541
  vm.__v_skip = true;
5498
5542
  // effect scope
5499
5543
  vm._scope = new EffectScope(true /* detached */);
5544
+ vm._scope._vm = true;
5500
5545
  // merge options
5501
5546
  if (options && options._isComponent) {
5502
5547
  // optimize internal component instantiation
@@ -7067,7 +7112,16 @@ function normalizeDirectives(dirs, vm) {
7067
7112
  }
7068
7113
  res[getRawDirName(dir)] = dir;
7069
7114
  if (vm._setupState && vm._setupState.__sfc) {
7070
- dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7115
+ const setupDef = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7116
+ if (typeof setupDef === 'function') {
7117
+ dir.def = {
7118
+ bind: setupDef,
7119
+ update: setupDef,
7120
+ };
7121
+ }
7122
+ else {
7123
+ dir.def = setupDef;
7124
+ }
7071
7125
  }
7072
7126
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
7073
7127
  }