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
package/dist/vue.js CHANGED
@@ -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
  */
@@ -655,13 +655,13 @@
655
655
  'referenced during render. Make sure that this property is reactive, ' +
656
656
  'either in the data option, or for class-based components, by ' +
657
657
  'initializing the property. ' +
658
- 'See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
658
+ 'See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
659
659
  };
660
660
  var warnReservedPrefix_1 = function (target, key) {
661
661
  warn$2("Property \"".concat(key, "\" must be accessed with \"$data.").concat(key, "\" because ") +
662
662
  'properties starting with "$" or "_" are not proxied in the Vue instance to ' +
663
663
  'prevent conflicts with Vue internals. ' +
664
- 'See: https://vuejs.org/v2/api/#data', target);
664
+ 'See: https://v2.vuejs.org/v2/api/#data', target);
665
665
  };
666
666
  var hasProxy_1 = typeof Proxy !== 'undefined' && isNative(Proxy);
667
667
  if (hasProxy_1) {
@@ -1007,7 +1007,7 @@
1007
1007
  // #7981: for accessor properties without setter
1008
1008
  return;
1009
1009
  }
1010
- else if (isRef(value) && !isRef(newVal)) {
1010
+ else if (!shallow && isRef(value) && !isRef(newVal)) {
1011
1011
  value.value = newVal;
1012
1012
  return;
1013
1013
  }
@@ -2283,7 +2283,19 @@
2283
2283
  var exposeCalled = false;
2284
2284
  return {
2285
2285
  get attrs() {
2286
- return initAttrsProxy(vm);
2286
+ if (!vm._attrsProxy) {
2287
+ var proxy = (vm._attrsProxy = {});
2288
+ def(proxy, '_v_attr_proxy', true);
2289
+ syncSetupProxy(proxy, vm.$attrs, emptyObject, vm, '$attrs');
2290
+ }
2291
+ return vm._attrsProxy;
2292
+ },
2293
+ get listeners() {
2294
+ if (!vm._listenersProxy) {
2295
+ var proxy = (vm._listenersProxy = {});
2296
+ syncSetupProxy(proxy, vm.$listeners, emptyObject, vm, '$listeners');
2297
+ }
2298
+ return vm._listenersProxy;
2287
2299
  },
2288
2300
  get slots() {
2289
2301
  return initSlotsProxy(vm);
@@ -2304,20 +2316,12 @@
2304
2316
  }
2305
2317
  };
2306
2318
  }
2307
- function initAttrsProxy(vm) {
2308
- if (!vm._attrsProxy) {
2309
- var proxy = (vm._attrsProxy = {});
2310
- def(proxy, '_v_attr_proxy', true);
2311
- syncSetupAttrs(proxy, vm.$attrs, emptyObject, vm);
2312
- }
2313
- return vm._attrsProxy;
2314
- }
2315
- function syncSetupAttrs(to, from, prev, instance) {
2319
+ function syncSetupProxy(to, from, prev, instance, type) {
2316
2320
  var changed = false;
2317
2321
  for (var key in from) {
2318
2322
  if (!(key in to)) {
2319
2323
  changed = true;
2320
- defineProxyAttr(to, key, instance);
2324
+ defineProxyAttr(to, key, instance, type);
2321
2325
  }
2322
2326
  else if (from[key] !== prev[key]) {
2323
2327
  changed = true;
@@ -2331,12 +2335,12 @@
2331
2335
  }
2332
2336
  return changed;
2333
2337
  }
2334
- function defineProxyAttr(proxy, key, instance) {
2338
+ function defineProxyAttr(proxy, key, instance, type) {
2335
2339
  Object.defineProperty(proxy, key, {
2336
2340
  enumerable: true,
2337
2341
  configurable: true,
2338
2342
  get: function () {
2339
- return instance.$attrs[key];
2343
+ return instance[type][key];
2340
2344
  }
2341
2345
  });
2342
2346
  }
@@ -2357,17 +2361,27 @@
2357
2361
  }
2358
2362
  }
2359
2363
  /**
2360
- * @internal use manual type def
2364
+ * @internal use manual type def because public setup context type relies on
2365
+ * legacy VNode types
2361
2366
  */
2362
2367
  function useSlots() {
2363
2368
  return getContext().slots;
2364
2369
  }
2365
2370
  /**
2366
- * @internal use manual type def
2371
+ * @internal use manual type def because public setup context type relies on
2372
+ * legacy VNode types
2367
2373
  */
2368
2374
  function useAttrs() {
2369
2375
  return getContext().attrs;
2370
2376
  }
2377
+ /**
2378
+ * Vue 2 only
2379
+ * @internal use manual type def because public setup context type relies on
2380
+ * legacy VNode types
2381
+ */
2382
+ function useListeners() {
2383
+ return getContext().listeners;
2384
+ }
2371
2385
  function getContext() {
2372
2386
  if (!currentInstance) {
2373
2387
  warn$2("useContext() called without active instance.");
@@ -2411,7 +2425,9 @@
2411
2425
  var parentVnode = (vm.$vnode = options._parentVnode); // the placeholder node in parent tree
2412
2426
  var renderContext = parentVnode && parentVnode.context;
2413
2427
  vm.$slots = resolveSlots(options._renderChildren, renderContext);
2414
- vm.$scopedSlots = emptyObject;
2428
+ vm.$scopedSlots = parentVnode
2429
+ ? normalizeScopedSlots(vm.$parent, parentVnode.data.scopedSlots, vm.$slots)
2430
+ : emptyObject;
2415
2431
  // bind the createElement fn to this instance
2416
2432
  // so that we get proper render context inside it.
2417
2433
  // args order: tag, data, children, normalizationType, alwaysNormalize
@@ -2445,7 +2461,7 @@
2445
2461
  Vue.prototype._render = function () {
2446
2462
  var vm = this;
2447
2463
  var _a = vm.$options, render = _a.render, _parentVnode = _a._parentVnode;
2448
- if (_parentVnode) {
2464
+ if (_parentVnode && vm._isMounted) {
2449
2465
  vm.$scopedSlots = normalizeScopedSlots(vm.$parent, _parentVnode.data.scopedSlots, vm.$slots, vm.$scopedSlots);
2450
2466
  if (vm._slotsProxy) {
2451
2467
  syncSetupSlots(vm._slotsProxy, vm.$scopedSlots);
@@ -2966,12 +2982,19 @@
2966
2982
  if (vm._attrsProxy) {
2967
2983
  // force update if attrs are accessed and has changed since it may be
2968
2984
  // passed to a child component.
2969
- if (syncSetupAttrs(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm)) {
2985
+ if (syncSetupProxy(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm, '$attrs')) {
2970
2986
  needsForceUpdate = true;
2971
2987
  }
2972
2988
  }
2973
2989
  vm.$attrs = attrs;
2974
- vm.$listeners = listeners || emptyObject;
2990
+ // update listeners
2991
+ listeners = listeners || emptyObject;
2992
+ var prevListeners = vm.$options._parentListeners;
2993
+ if (vm._listenersProxy) {
2994
+ syncSetupProxy(vm._listenersProxy, listeners, prevListeners || emptyObject, vm, '$listeners');
2995
+ }
2996
+ vm.$listeners = vm.$options._parentListeners = listeners;
2997
+ updateComponentListeners(vm, listeners, prevListeners);
2975
2998
  // update props
2976
2999
  if (propsData && vm.$options.props) {
2977
3000
  toggleObserving(false);
@@ -2986,11 +3009,6 @@
2986
3009
  // keep a copy of raw propsData
2987
3010
  vm.$options.propsData = propsData;
2988
3011
  }
2989
- // update listeners
2990
- listeners = listeners || emptyObject;
2991
- var oldListeners = vm.$options._parentListeners;
2992
- vm.$options._parentListeners = listeners;
2993
- updateComponentListeners(vm, listeners, oldListeners);
2994
3012
  // resolve slots + force update if has children
2995
3013
  if (needsForceUpdate) {
2996
3014
  vm.$slots = resolveSlots(renderChildren, parentVnode.context);
@@ -3105,6 +3123,16 @@
3105
3123
  getNow = function () { return performance_1.now(); };
3106
3124
  }
3107
3125
  }
3126
+ var sortCompareFn = function (a, b) {
3127
+ if (a.post) {
3128
+ if (!b.post)
3129
+ return 1;
3130
+ }
3131
+ else if (b.post) {
3132
+ return -1;
3133
+ }
3134
+ return a.id - b.id;
3135
+ };
3108
3136
  /**
3109
3137
  * Flush both queues and run the watchers.
3110
3138
  */
@@ -3120,7 +3148,7 @@
3120
3148
  // user watchers are created before the render watcher)
3121
3149
  // 3. If a component is destroyed during a parent component's watcher run,
3122
3150
  // its watchers can be skipped.
3123
- queue.sort(function (a, b) { return a.id - b.id; });
3151
+ queue.sort(sortCompareFn);
3124
3152
  // do not cache length because more watchers might be pushed
3125
3153
  // as we run existing watchers
3126
3154
  for (index$1 = 0; index$1 < queue.length; index$1++) {
@@ -3355,8 +3383,7 @@
3355
3383
  var oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
3356
3384
  // overwrite default run
3357
3385
  watcher.run = function () {
3358
- if (!watcher.active &&
3359
- !(flush === 'pre' && instance && instance._isBeingDestroyed)) {
3386
+ if (!watcher.active) {
3360
3387
  return;
3361
3388
  }
3362
3389
  if (cb) {
@@ -3391,7 +3418,7 @@
3391
3418
  watcher.update = watcher.run;
3392
3419
  }
3393
3420
  else if (flush === 'post') {
3394
- watcher.id = Infinity;
3421
+ watcher.post = true;
3395
3422
  watcher.update = function () { return queueWatcher(watcher); };
3396
3423
  }
3397
3424
  else {
@@ -3543,18 +3570,23 @@
3543
3570
  }
3544
3571
  }
3545
3572
  else {
3546
- var provides = currentInstance._provided;
3547
- // by default an instance inherits its parent's provides object
3548
- // but when it needs to provide values of its own, it creates its
3549
- // own provides object using parent provides object as prototype.
3550
- // this way in `inject` we can simply look up injections from direct
3551
- // parent and let the prototype chain do the work.
3552
- var parentProvides = currentInstance.$parent && currentInstance.$parent._provided;
3553
- if (parentProvides === provides) {
3554
- provides = currentInstance._provided = Object.create(parentProvides);
3555
- }
3556
3573
  // TS doesn't allow symbol as index type
3557
- provides[key] = value;
3574
+ resolveProvided(currentInstance)[key] = value;
3575
+ }
3576
+ }
3577
+ function resolveProvided(vm) {
3578
+ // by default an instance inherits its parent's provides object
3579
+ // but when it needs to provide values of its own, it creates its
3580
+ // own provides object using parent provides object as prototype.
3581
+ // this way in `inject` we can simply look up injections from direct
3582
+ // parent and let the prototype chain do the work.
3583
+ var existing = vm._provided;
3584
+ var parentProvides = vm.$parent && vm.$parent._provided;
3585
+ if (parentProvides === existing) {
3586
+ return (vm._provided = Object.create(parentProvides));
3587
+ }
3588
+ else {
3589
+ return existing;
3558
3590
  }
3559
3591
  }
3560
3592
  function inject(key, defaultValue, treatDefaultAsFactory) {
@@ -3914,17 +3946,21 @@
3914
3946
  var onUpdated = createLifeCycle('updated');
3915
3947
  var onBeforeUnmount = createLifeCycle('beforeDestroy');
3916
3948
  var onUnmounted = createLifeCycle('destroyed');
3917
- var onErrorCaptured = createLifeCycle('errorCaptured');
3918
3949
  var onActivated = createLifeCycle('activated');
3919
3950
  var onDeactivated = createLifeCycle('deactivated');
3920
3951
  var onServerPrefetch = createLifeCycle('serverPrefetch');
3921
3952
  var onRenderTracked = createLifeCycle('renderTracked');
3922
- var onRenderTriggered = createLifeCycle('renderTriggered');
3953
+ var onRenderTriggered = createLifeCycle('renderTriggered');
3954
+ var injectErrorCapturedHook = createLifeCycle('errorCaptured');
3955
+ function onErrorCaptured(hook, target) {
3956
+ if (target === void 0) { target = currentInstance; }
3957
+ injectErrorCapturedHook(hook, target);
3958
+ }
3923
3959
 
3924
3960
  /**
3925
3961
  * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
3926
3962
  */
3927
- var version = '2.7.6';
3963
+ var version = '2.7.9';
3928
3964
  /**
3929
3965
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
3930
3966
  */
@@ -3970,6 +4006,7 @@
3970
4006
  getCurrentInstance: getCurrentInstance,
3971
4007
  useSlots: useSlots,
3972
4008
  useAttrs: useAttrs,
4009
+ useListeners: useListeners,
3973
4010
  mergeDefaults: mergeDefaults,
3974
4011
  nextTick: nextTick,
3975
4012
  set: set,
@@ -3983,12 +4020,12 @@
3983
4020
  onUpdated: onUpdated,
3984
4021
  onBeforeUnmount: onBeforeUnmount,
3985
4022
  onUnmounted: onUnmounted,
3986
- onErrorCaptured: onErrorCaptured,
3987
4023
  onActivated: onActivated,
3988
4024
  onDeactivated: onDeactivated,
3989
4025
  onServerPrefetch: onServerPrefetch,
3990
4026
  onRenderTracked: onRenderTracked,
3991
- onRenderTriggered: onRenderTriggered
4027
+ onRenderTriggered: onRenderTriggered,
4028
+ onErrorCaptured: onErrorCaptured
3992
4029
  });
3993
4030
 
3994
4031
  var seenObjects = new _Set();
@@ -4042,11 +4079,16 @@
4042
4079
  */
4043
4080
  var Watcher = /** @class */ (function () {
4044
4081
  function Watcher(vm, expOrFn, cb, options, isRenderWatcher) {
4045
- recordEffectScope(this, activeEffectScope || (vm ? vm._scope : undefined));
4046
- if ((this.vm = vm)) {
4047
- if (isRenderWatcher) {
4048
- vm._watcher = this;
4049
- }
4082
+ recordEffectScope(this,
4083
+ // if the active effect scope is manually created (not a component scope),
4084
+ // prioritize it
4085
+ activeEffectScope && !activeEffectScope._vm
4086
+ ? activeEffectScope
4087
+ : vm
4088
+ ? vm._scope
4089
+ : undefined);
4090
+ if ((this.vm = vm) && isRenderWatcher) {
4091
+ vm._watcher = this;
4050
4092
  }
4051
4093
  // options
4052
4094
  if (options) {
@@ -4066,6 +4108,7 @@
4066
4108
  this.cb = cb;
4067
4109
  this.id = ++uid$1; // uid for batching
4068
4110
  this.active = true;
4111
+ this.post = false;
4069
4112
  this.dirty = this.lazy; // for lazy watchers
4070
4113
  this.deps = [];
4071
4114
  this.newDeps = [];
@@ -4313,7 +4356,7 @@
4313
4356
  if (!isPlainObject(data)) {
4314
4357
  data = {};
4315
4358
  warn$2('data functions should return an object:\n' +
4316
- 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
4359
+ 'https://v2.vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
4317
4360
  }
4318
4361
  // proxy data on instance
4319
4362
  var keys = Object.keys(data);
@@ -4534,12 +4577,14 @@
4534
4577
  if (!isObject(provided)) {
4535
4578
  return;
4536
4579
  }
4580
+ var source = resolveProvided(vm);
4581
+ // IE9 doesn't support Object.getOwnPropertyDescriptors so we have to
4582
+ // iterate the keys ourselves.
4537
4583
  var keys = hasSymbol ? Reflect.ownKeys(provided) : Object.keys(provided);
4538
- setCurrentInstance(vm);
4539
4584
  for (var i = 0; i < keys.length; i++) {
4540
- provide(keys[i], provided[keys[i]]);
4585
+ var key = keys[i];
4586
+ Object.defineProperty(source, key, Object.getOwnPropertyDescriptor(provided, key));
4541
4587
  }
4542
- setCurrentInstance();
4543
4588
  }
4544
4589
  }
4545
4590
  function initInjections(vm) {
@@ -4607,6 +4652,7 @@
4607
4652
  vm.__v_skip = true;
4608
4653
  // effect scope
4609
4654
  vm._scope = new EffectScope(true /* detached */);
4655
+ vm._scope._vm = true;
4610
4656
  // merge options
4611
4657
  if (options && options._isComponent) {
4612
4658
  // optimize internal component instantiation
@@ -7156,7 +7202,16 @@
7156
7202
  }
7157
7203
  res[getRawDirName(dir)] = dir;
7158
7204
  if (vm._setupState && vm._setupState.__sfc) {
7159
- dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7205
+ var setupDef = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7206
+ if (typeof setupDef === 'function') {
7207
+ dir.def = {
7208
+ bind: setupDef,
7209
+ update: setupDef,
7210
+ };
7211
+ }
7212
+ else {
7213
+ dir.def = setupDef;
7214
+ }
7160
7215
  }
7161
7216
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
7162
7217
  }
@@ -10907,7 +10962,8 @@
10907
10962
  }
10908
10963
  else {
10909
10964
  var data = void 0;
10910
- if (!el.plain || (el.pre && state.maybeComponent(el))) {
10965
+ var maybeComponent = state.maybeComponent(el);
10966
+ if (!el.plain || (el.pre && maybeComponent)) {
10911
10967
  data = genData(el, state);
10912
10968
  }
10913
10969
  var tag
@@ -10915,11 +10971,8 @@
10915
10971
  = void 0;
10916
10972
  // check if this is a component in <script setup>
10917
10973
  var bindings = state.options.bindings;
10918
- if (bindings && bindings.__isScriptSetup !== false) {
10919
- tag =
10920
- checkBindingType(bindings, el.tag) ||
10921
- checkBindingType(bindings, camelize(el.tag)) ||
10922
- checkBindingType(bindings, capitalize(camelize(el.tag)));
10974
+ if (maybeComponent && bindings && bindings.__isScriptSetup !== false) {
10975
+ tag = checkBindingType(bindings, el.tag);
10923
10976
  }
10924
10977
  if (!tag)
10925
10978
  tag = "'".concat(el.tag, "'");
@@ -10936,9 +10989,29 @@
10936
10989
  }
10937
10990
  }
10938
10991
  function checkBindingType(bindings, key) {
10939
- var type = bindings[key];
10940
- if (type && type.startsWith('setup')) {
10941
- return key;
10992
+ var camelName = camelize(key);
10993
+ var PascalName = capitalize(camelName);
10994
+ var checkType = function (type) {
10995
+ if (bindings[key] === type) {
10996
+ return key;
10997
+ }
10998
+ if (bindings[camelName] === type) {
10999
+ return camelName;
11000
+ }
11001
+ if (bindings[PascalName] === type) {
11002
+ return PascalName;
11003
+ }
11004
+ };
11005
+ var fromConst = checkType("setup-const" /* BindingTypes.SETUP_CONST */) ||
11006
+ checkType("setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */);
11007
+ if (fromConst) {
11008
+ return fromConst;
11009
+ }
11010
+ var fromMaybeRef = checkType("setup-let" /* BindingTypes.SETUP_LET */) ||
11011
+ checkType("setup-ref" /* BindingTypes.SETUP_REF */) ||
11012
+ checkType("setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */);
11013
+ if (fromMaybeRef) {
11014
+ return fromMaybeRef;
10942
11015
  }
10943
11016
  }
10944
11017
  // hoist static sub-trees out