vue 2.7.7 → 2.7.10

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 (45) hide show
  1. package/README.md +1 -1
  2. package/dist/vue.common.dev.js +105 -49
  3. package/dist/vue.common.prod.js +3 -3
  4. package/dist/vue.esm.browser.js +103 -48
  5. package/dist/vue.esm.browser.min.js +3 -3
  6. package/dist/vue.esm.js +104 -48
  7. package/dist/vue.js +106 -49
  8. package/dist/vue.min.js +3 -3
  9. package/dist/vue.runtime.common.dev.js +81 -42
  10. package/dist/vue.runtime.common.prod.js +3 -3
  11. package/dist/vue.runtime.esm.js +80 -41
  12. package/dist/vue.runtime.js +82 -42
  13. package/dist/vue.runtime.min.js +3 -3
  14. package/package.json +2 -2
  15. package/packages/compiler-sfc/dist/compiler-sfc.js +55 -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/parseComponent.ts +2 -2
  19. package/packages/compiler-sfc/src/rewriteDefault.ts +6 -1
  20. package/packages/compiler-sfc/src/templateCompilerModules/utils.ts +8 -3
  21. package/packages/compiler-sfc/test/rewriteDefault.spec.ts +245 -0
  22. package/src/compiler/codegen/index.ts +28 -8
  23. package/src/core/instance/init.ts +1 -0
  24. package/src/core/instance/lifecycle.ts +27 -12
  25. package/src/core/instance/proxy.ts +2 -2
  26. package/src/core/instance/state.ts +1 -1
  27. package/src/core/observer/index.ts +1 -1
  28. package/src/core/observer/watcher.ts +12 -5
  29. package/src/core/vdom/modules/directives.ts +9 -1
  30. package/src/core/vdom/vnode.ts +1 -0
  31. package/src/types/component.ts +1 -0
  32. package/src/v3/apiLifecycle.ts +16 -1
  33. package/src/v3/apiSetup.ts +38 -17
  34. package/src/v3/apiWatch.ts +1 -4
  35. package/src/v3/index.ts +1 -1
  36. package/src/v3/reactivity/effectScope.ts +5 -1
  37. package/types/index.d.ts +2 -2
  38. package/types/options.d.ts +24 -9
  39. package/types/v3-component-options.d.ts +3 -0
  40. package/types/v3-component-public-instance.d.ts +2 -4
  41. package/types/v3-define-component.d.ts +34 -34
  42. package/types/v3-generated.d.ts +11 -2
  43. package/types/v3-manual-apis.d.ts +2 -2
  44. package/types/v3-setup-context.d.ts +4 -0
  45. package/types/vue.d.ts +108 -31
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vue.js v2.7.7
2
+ * Vue.js v2.7.10
3
3
  * (c) 2014-2022 Evan You
4
4
  * Released under the MIT License.
5
5
  */
@@ -641,13 +641,13 @@ let initProxy;
641
641
  'referenced during render. Make sure that this property is reactive, ' +
642
642
  'either in the data option, or for class-based components, by ' +
643
643
  'initializing the property. ' +
644
- 'See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
644
+ 'See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target);
645
645
  };
646
646
  const warnReservedPrefix = (target, key) => {
647
647
  warn$2(`Property "${key}" must be accessed with "$data.${key}" because ` +
648
648
  'properties starting with "$" or "_" are not proxied in the Vue instance to ' +
649
649
  'prevent conflicts with Vue internals. ' +
650
- 'See: https://vuejs.org/v2/api/#data', target);
650
+ 'See: https://v2.vuejs.org/v2/api/#data', target);
651
651
  };
652
652
  const hasProxy = typeof Proxy !== 'undefined' && isNative(Proxy);
653
653
  if (hasProxy) {
@@ -959,7 +959,7 @@ function defineReactive(obj, key, val, customSetter, shallow, mock) {
959
959
  // #7981: for accessor properties without setter
960
960
  return;
961
961
  }
962
- else if (isRef(value) && !isRef(newVal)) {
962
+ else if (!shallow && isRef(value) && !isRef(newVal)) {
963
963
  value.value = newVal;
964
964
  return;
965
965
  }
@@ -2232,7 +2232,19 @@ function createSetupContext(vm) {
2232
2232
  let exposeCalled = false;
2233
2233
  return {
2234
2234
  get attrs() {
2235
- return initAttrsProxy(vm);
2235
+ if (!vm._attrsProxy) {
2236
+ const proxy = (vm._attrsProxy = {});
2237
+ def(proxy, '_v_attr_proxy', true);
2238
+ syncSetupProxy(proxy, vm.$attrs, emptyObject, vm, '$attrs');
2239
+ }
2240
+ return vm._attrsProxy;
2241
+ },
2242
+ get listeners() {
2243
+ if (!vm._listenersProxy) {
2244
+ const proxy = (vm._listenersProxy = {});
2245
+ syncSetupProxy(proxy, vm.$listeners, emptyObject, vm, '$listeners');
2246
+ }
2247
+ return vm._listenersProxy;
2236
2248
  },
2237
2249
  get slots() {
2238
2250
  return initSlotsProxy(vm);
@@ -2251,20 +2263,12 @@ function createSetupContext(vm) {
2251
2263
  }
2252
2264
  };
2253
2265
  }
2254
- function initAttrsProxy(vm) {
2255
- if (!vm._attrsProxy) {
2256
- const proxy = (vm._attrsProxy = {});
2257
- def(proxy, '_v_attr_proxy', true);
2258
- syncSetupAttrs(proxy, vm.$attrs, emptyObject, vm);
2259
- }
2260
- return vm._attrsProxy;
2261
- }
2262
- function syncSetupAttrs(to, from, prev, instance) {
2266
+ function syncSetupProxy(to, from, prev, instance, type) {
2263
2267
  let changed = false;
2264
2268
  for (const key in from) {
2265
2269
  if (!(key in to)) {
2266
2270
  changed = true;
2267
- defineProxyAttr(to, key, instance);
2271
+ defineProxyAttr(to, key, instance, type);
2268
2272
  }
2269
2273
  else if (from[key] !== prev[key]) {
2270
2274
  changed = true;
@@ -2278,12 +2282,12 @@ function syncSetupAttrs(to, from, prev, instance) {
2278
2282
  }
2279
2283
  return changed;
2280
2284
  }
2281
- function defineProxyAttr(proxy, key, instance) {
2285
+ function defineProxyAttr(proxy, key, instance, type) {
2282
2286
  Object.defineProperty(proxy, key, {
2283
2287
  enumerable: true,
2284
2288
  configurable: true,
2285
2289
  get() {
2286
- return instance.$attrs[key];
2290
+ return instance[type][key];
2287
2291
  }
2288
2292
  });
2289
2293
  }
@@ -2304,17 +2308,27 @@ function syncSetupSlots(to, from) {
2304
2308
  }
2305
2309
  }
2306
2310
  /**
2307
- * @internal use manual type def
2311
+ * @internal use manual type def because public setup context type relies on
2312
+ * legacy VNode types
2308
2313
  */
2309
2314
  function useSlots() {
2310
2315
  return getContext().slots;
2311
2316
  }
2312
2317
  /**
2313
- * @internal use manual type def
2318
+ * @internal use manual type def because public setup context type relies on
2319
+ * legacy VNode types
2314
2320
  */
2315
2321
  function useAttrs() {
2316
2322
  return getContext().attrs;
2317
2323
  }
2324
+ /**
2325
+ * Vue 2 only
2326
+ * @internal use manual type def because public setup context type relies on
2327
+ * legacy VNode types
2328
+ */
2329
+ function useListeners() {
2330
+ return getContext().listeners;
2331
+ }
2318
2332
  function getContext() {
2319
2333
  if (!currentInstance) {
2320
2334
  warn$2(`useContext() called without active instance.`);
@@ -2755,8 +2769,13 @@ function lifecycleMixin(Vue) {
2755
2769
  vm.$el.__vue__ = vm;
2756
2770
  }
2757
2771
  // if parent is an HOC, update its $el as well
2758
- if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {
2759
- vm.$parent.$el = vm.$el;
2772
+ let wrapper = vm;
2773
+ while (wrapper &&
2774
+ wrapper.$vnode &&
2775
+ wrapper.$parent &&
2776
+ wrapper.$vnode === wrapper.$parent._vnode) {
2777
+ wrapper.$parent.$el = wrapper.$el;
2778
+ wrapper = wrapper.$parent;
2760
2779
  }
2761
2780
  // updated hook is called by the scheduler to ensure that children are
2762
2781
  // updated in a parent's updated hook.
@@ -2915,12 +2934,19 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
2915
2934
  if (vm._attrsProxy) {
2916
2935
  // force update if attrs are accessed and has changed since it may be
2917
2936
  // passed to a child component.
2918
- if (syncSetupAttrs(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm)) {
2937
+ if (syncSetupProxy(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm, '$attrs')) {
2919
2938
  needsForceUpdate = true;
2920
2939
  }
2921
2940
  }
2922
2941
  vm.$attrs = attrs;
2923
- vm.$listeners = listeners || emptyObject;
2942
+ // update listeners
2943
+ listeners = listeners || emptyObject;
2944
+ const prevListeners = vm.$options._parentListeners;
2945
+ if (vm._listenersProxy) {
2946
+ syncSetupProxy(vm._listenersProxy, listeners, prevListeners || emptyObject, vm, '$listeners');
2947
+ }
2948
+ vm.$listeners = vm.$options._parentListeners = listeners;
2949
+ updateComponentListeners(vm, listeners, prevListeners);
2924
2950
  // update props
2925
2951
  if (propsData && vm.$options.props) {
2926
2952
  toggleObserving(false);
@@ -2935,11 +2961,6 @@ function updateChildComponent(vm, propsData, listeners, parentVnode, renderChild
2935
2961
  // keep a copy of raw propsData
2936
2962
  vm.$options.propsData = propsData;
2937
2963
  }
2938
- // update listeners
2939
- listeners = listeners || emptyObject;
2940
- const oldListeners = vm.$options._parentListeners;
2941
- vm.$options._parentListeners = listeners;
2942
- updateComponentListeners(vm, listeners, oldListeners);
2943
2964
  // resolve slots + force update if has children
2944
2965
  if (needsForceUpdate) {
2945
2966
  vm.$slots = resolveSlots(renderChildren, parentVnode.context);
@@ -3307,8 +3328,7 @@ function doWatch(source, cb, { immediate, deep, flush = 'pre', onTrack, onTrigge
3307
3328
  let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
3308
3329
  // overwrite default run
3309
3330
  watcher.run = () => {
3310
- if (!watcher.active &&
3311
- !(flush === 'pre' && instance && instance._isBeingDestroyed)) {
3331
+ if (!watcher.active) {
3312
3332
  return;
3313
3333
  }
3314
3334
  if (cb) {
@@ -3863,17 +3883,20 @@ const onBeforeUpdate = createLifeCycle('beforeUpdate');
3863
3883
  const onUpdated = createLifeCycle('updated');
3864
3884
  const onBeforeUnmount = createLifeCycle('beforeDestroy');
3865
3885
  const onUnmounted = createLifeCycle('destroyed');
3866
- const onErrorCaptured = createLifeCycle('errorCaptured');
3867
3886
  const onActivated = createLifeCycle('activated');
3868
3887
  const onDeactivated = createLifeCycle('deactivated');
3869
3888
  const onServerPrefetch = createLifeCycle('serverPrefetch');
3870
3889
  const onRenderTracked = createLifeCycle('renderTracked');
3871
- const onRenderTriggered = createLifeCycle('renderTriggered');
3890
+ const onRenderTriggered = createLifeCycle('renderTriggered');
3891
+ const injectErrorCapturedHook = createLifeCycle('errorCaptured');
3892
+ function onErrorCaptured(hook, target = currentInstance) {
3893
+ injectErrorCapturedHook(hook, target);
3894
+ }
3872
3895
 
3873
3896
  /**
3874
3897
  * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
3875
3898
  */
3876
- const version = '2.7.7';
3899
+ const version = '2.7.10';
3877
3900
  /**
3878
3901
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
3879
3902
  */
@@ -3932,11 +3955,16 @@ let uid$1 = 0;
3932
3955
  */
3933
3956
  class Watcher {
3934
3957
  constructor(vm, expOrFn, cb, options, isRenderWatcher) {
3935
- recordEffectScope(this, activeEffectScope || (vm ? vm._scope : undefined));
3936
- if ((this.vm = vm)) {
3937
- if (isRenderWatcher) {
3938
- vm._watcher = this;
3939
- }
3958
+ recordEffectScope(this,
3959
+ // if the active effect scope is manually created (not a component scope),
3960
+ // prioritize it
3961
+ activeEffectScope && !activeEffectScope._vm
3962
+ ? activeEffectScope
3963
+ : vm
3964
+ ? vm._scope
3965
+ : undefined);
3966
+ if ((this.vm = vm) && isRenderWatcher) {
3967
+ vm._watcher = this;
3940
3968
  }
3941
3969
  // options
3942
3970
  if (options) {
@@ -4200,7 +4228,7 @@ function initData(vm) {
4200
4228
  if (!isPlainObject(data)) {
4201
4229
  data = {};
4202
4230
  warn$2('data functions should return an object:\n' +
4203
- 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
4231
+ 'https://v2.vuejs.org/v2/guide/components.html#data-Must-Be-a-Function', vm);
4204
4232
  }
4205
4233
  // proxy data on instance
4206
4234
  const keys = Object.keys(data);
@@ -4496,6 +4524,7 @@ function initMixin$1(Vue) {
4496
4524
  vm.__v_skip = true;
4497
4525
  // effect scope
4498
4526
  vm._scope = new EffectScope(true /* detached */);
4527
+ vm._scope._vm = true;
4499
4528
  // merge options
4500
4529
  if (options && options._isComponent) {
4501
4530
  // optimize internal component instantiation
@@ -7031,7 +7060,16 @@ function normalizeDirectives(dirs, vm) {
7031
7060
  }
7032
7061
  res[getRawDirName(dir)] = dir;
7033
7062
  if (vm._setupState && vm._setupState.__sfc) {
7034
- dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7063
+ const setupDef = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7064
+ if (typeof setupDef === 'function') {
7065
+ dir.def = {
7066
+ bind: setupDef,
7067
+ update: setupDef,
7068
+ };
7069
+ }
7070
+ else {
7071
+ dir.def = setupDef;
7072
+ }
7035
7073
  }
7036
7074
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
7037
7075
  }
@@ -10769,10 +10807,7 @@ function genElement(el, state) {
10769
10807
  // check if this is a component in <script setup>
10770
10808
  const bindings = state.options.bindings;
10771
10809
  if (maybeComponent && bindings && bindings.__isScriptSetup !== false) {
10772
- tag =
10773
- checkBindingType(bindings, el.tag) ||
10774
- checkBindingType(bindings, camelize(el.tag)) ||
10775
- checkBindingType(bindings, capitalize(camelize(el.tag)));
10810
+ tag = checkBindingType(bindings, el.tag);
10776
10811
  }
10777
10812
  if (!tag)
10778
10813
  tag = `'${el.tag}'`;
@@ -10789,9 +10824,29 @@ function genElement(el, state) {
10789
10824
  }
10790
10825
  }
10791
10826
  function checkBindingType(bindings, key) {
10792
- const type = bindings[key];
10793
- if (type && type.startsWith('setup')) {
10794
- return key;
10827
+ const camelName = camelize(key);
10828
+ const PascalName = capitalize(camelName);
10829
+ const checkType = (type) => {
10830
+ if (bindings[key] === type) {
10831
+ return key;
10832
+ }
10833
+ if (bindings[camelName] === type) {
10834
+ return camelName;
10835
+ }
10836
+ if (bindings[PascalName] === type) {
10837
+ return PascalName;
10838
+ }
10839
+ };
10840
+ const fromConst = checkType("setup-const" /* BindingTypes.SETUP_CONST */) ||
10841
+ checkType("setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */);
10842
+ if (fromConst) {
10843
+ return fromConst;
10844
+ }
10845
+ const fromMaybeRef = checkType("setup-let" /* BindingTypes.SETUP_LET */) ||
10846
+ checkType("setup-ref" /* BindingTypes.SETUP_REF */) ||
10847
+ checkType("setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */);
10848
+ if (fromMaybeRef) {
10849
+ return fromMaybeRef;
10795
10850
  }
10796
10851
  }
10797
10852
  // hoist static sub-trees out
@@ -11610,4 +11665,4 @@ function getOuterHTML(el) {
11610
11665
  }
11611
11666
  Vue.compile = compileToFunctions;
11612
11667
 
11613
- 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 };
11668
+ 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 };