vue 2.7.1 → 2.7.4

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 (42) hide show
  1. package/dist/vue.common.dev.js +133 -61
  2. package/dist/vue.common.prod.js +3 -3
  3. package/dist/vue.esm.browser.js +133 -62
  4. package/dist/vue.esm.browser.min.js +3 -3
  5. package/dist/vue.esm.js +135 -62
  6. package/dist/vue.js +135 -61
  7. package/dist/vue.min.js +3 -3
  8. package/dist/vue.runtime.common.dev.js +133 -61
  9. package/dist/vue.runtime.common.prod.js +3 -3
  10. package/dist/vue.runtime.esm.js +135 -62
  11. package/dist/vue.runtime.js +135 -61
  12. package/dist/vue.runtime.min.js +3 -3
  13. package/dist/vue.runtime.mjs +72 -8604
  14. package/package.json +2 -2
  15. package/packages/compiler-sfc/dist/compiler-sfc.js +56 -55
  16. package/packages/compiler-sfc/package.json +1 -1
  17. package/packages/compiler-sfc/src/parseComponent.ts +9 -1
  18. package/packages/compiler-sfc/test/parseComponent.spec.ts +6 -7
  19. package/src/core/instance/render-helpers/render-static.ts +1 -1
  20. package/src/core/observer/index.ts +54 -55
  21. package/src/core/util/next-tick.ts +2 -1
  22. package/src/core/vdom/modules/directives.ts +2 -2
  23. package/src/shared/constants.ts +3 -1
  24. package/src/v3/apiAsyncComponent.ts +117 -0
  25. package/src/v3/apiWatch.ts +2 -2
  26. package/src/v3/index.ts +6 -0
  27. package/src/v3/reactivity/reactive.ts +13 -2
  28. package/src/v3/reactivity/ref.ts +6 -2
  29. package/types/common.d.ts +6 -0
  30. package/types/index.d.ts +7 -4
  31. package/types/jsx.d.ts +16 -2
  32. package/types/options.d.ts +8 -2
  33. package/types/v3-component-options.d.ts +162 -33
  34. package/types/v3-component-props.d.ts +19 -20
  35. package/types/v3-component-public-instance.d.ts +234 -0
  36. package/types/v3-define-async-component.d.ts +26 -0
  37. package/types/v3-define-component.d.ts +94 -12
  38. package/types/v3-generated.d.ts +26 -1
  39. package/types/v3-setup-context.d.ts +0 -6
  40. package/types/vnode.d.ts +15 -0
  41. package/types/vue.d.ts +17 -10
  42. package/types/v3-component-proxy.d.ts +0 -189
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vue.js v2.7.1
2
+ * Vue.js v2.7.4
3
3
  * (c) 2014-2022 Evan You
4
4
  * Released under the MIT License.
5
5
  */
@@ -324,7 +324,9 @@ var LIFECYCLE_HOOKS = [
324
324
  'activated',
325
325
  'deactivated',
326
326
  'errorCaptured',
327
- 'serverPrefetch'
327
+ 'serverPrefetch',
328
+ 'renderTracked',
329
+ 'renderTriggered'
328
330
  ];
329
331
 
330
332
  var config = {
@@ -879,7 +881,7 @@ function makeReactive(target, shallow) {
879
881
  warn("Target is already a ".concat(existingOb.shallow ? "" : "non-", "shallow reactive object, and cannot be converted to ").concat(shallow ? "" : "non-", "shallow."));
880
882
  }
881
883
  }
882
- var ob = observe(target, shallow);
884
+ var ob = observe(target, shallow, isServerRendering() /* ssr mock reactivity */);
883
885
  if (process.env.NODE_ENV !== 'production' && !ob) {
884
886
  if (target == null || isPrimitive(target)) {
885
887
  warn("value cannot be made reactive: ".concat(String(target)));
@@ -941,7 +943,7 @@ function createRef(rawValue, shallow) {
941
943
  var ref = {};
942
944
  def(ref, RefFlag, true);
943
945
  def(ref, "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */, true);
944
- ref.dep = defineReactive(ref, 'value', rawValue, null, shallow);
946
+ def(ref, 'dep', defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering()));
945
947
  return ref;
946
948
  }
947
949
  function triggerRef(ref) {
@@ -1830,7 +1832,7 @@ function renderStatic(index, isInFor) {
1830
1832
  return tree;
1831
1833
  }
1832
1834
  // otherwise, render a fresh tree.
1833
- tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, null, this // for render fns generated for functional component templates
1835
+ tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, this._c, this // for render fns generated for functional component templates
1834
1836
  );
1835
1837
  markStatic(tree, "__static__".concat(index), false);
1836
1838
  return tree;
@@ -3903,8 +3905,8 @@ function doWatch(source, cb, _a) {
3903
3905
  else {
3904
3906
  // pre
3905
3907
  watcher.update = function () {
3906
- if (instance && instance === currentInstance) {
3907
- // pre-watcher triggered inside setup()
3908
+ if (instance && instance === currentInstance && !instance._isMounted) {
3909
+ // pre-watcher triggered before
3908
3910
  var buffer = instance._preWatchers || (instance._preWatchers = []);
3909
3911
  if (buffer.indexOf(watcher) < 0)
3910
3912
  buffer.push(watcher);
@@ -4174,6 +4176,78 @@ function useCssVars(getter) {
4174
4176
  });
4175
4177
  }
4176
4178
 
4179
+ /**
4180
+ * v3-compatible async component API.
4181
+ * @internal the type is manually declared in <root>/types/v3-define-async-component.d.ts
4182
+ * because it relies on existing manual types
4183
+ */
4184
+ function defineAsyncComponent(source) {
4185
+ if (isFunction(source)) {
4186
+ source = { loader: source };
4187
+ }
4188
+ var loader = source.loader, loadingComponent = source.loadingComponent, errorComponent = source.errorComponent, _a = source.delay, delay = _a === void 0 ? 200 : _a, timeout = source.timeout, // undefined = never times out
4189
+ _b = source.suspensible, // undefined = never times out
4190
+ suspensible = _b === void 0 ? false : _b, // in Vue 3 default is true
4191
+ userOnError = source.onError;
4192
+ if (process.env.NODE_ENV !== 'production' && suspensible) {
4193
+ warn("The suspensiblbe option for async components is not supported in Vue2. It is ignored.");
4194
+ }
4195
+ var pendingRequest = null;
4196
+ var retries = 0;
4197
+ var retry = function () {
4198
+ retries++;
4199
+ pendingRequest = null;
4200
+ return load();
4201
+ };
4202
+ var load = function () {
4203
+ var thisRequest;
4204
+ return (pendingRequest ||
4205
+ (thisRequest = pendingRequest =
4206
+ loader()
4207
+ .catch(function (err) {
4208
+ err = err instanceof Error ? err : new Error(String(err));
4209
+ if (userOnError) {
4210
+ return new Promise(function (resolve, reject) {
4211
+ var userRetry = function () { return resolve(retry()); };
4212
+ var userFail = function () { return reject(err); };
4213
+ userOnError(err, userRetry, userFail, retries + 1);
4214
+ });
4215
+ }
4216
+ else {
4217
+ throw err;
4218
+ }
4219
+ })
4220
+ .then(function (comp) {
4221
+ if (thisRequest !== pendingRequest && pendingRequest) {
4222
+ return pendingRequest;
4223
+ }
4224
+ if (process.env.NODE_ENV !== 'production' && !comp) {
4225
+ warn("Async component loader resolved to undefined. " +
4226
+ "If you are using retry(), make sure to return its return value.");
4227
+ }
4228
+ // interop module default
4229
+ if (comp &&
4230
+ (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
4231
+ comp = comp.default;
4232
+ }
4233
+ if (process.env.NODE_ENV !== 'production' && comp && !isObject(comp) && !isFunction(comp)) {
4234
+ throw new Error("Invalid async component load result: ".concat(comp));
4235
+ }
4236
+ return comp;
4237
+ })));
4238
+ };
4239
+ return function () {
4240
+ var component = load();
4241
+ return {
4242
+ component: component,
4243
+ delay: delay,
4244
+ timeout: timeout,
4245
+ error: errorComponent,
4246
+ loading: loadingComponent
4247
+ };
4248
+ };
4249
+ }
4250
+
4177
4251
  function createLifeCycle(hookName) {
4178
4252
  return function (fn, target) {
4179
4253
  if (target === void 0) { target = currentInstance; }
@@ -4213,7 +4287,10 @@ var onServerPrefetch = createLifeCycle('serverPrefetch');
4213
4287
  var onRenderTracked = createLifeCycle('renderTracked');
4214
4288
  var onRenderTriggered = createLifeCycle('renderTriggered');
4215
4289
 
4216
- var version = '2.7.1';
4290
+ /**
4291
+ * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
4292
+ */
4293
+ var version = '2.7.4';
4217
4294
  /**
4218
4295
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
4219
4296
  */
@@ -4231,6 +4308,13 @@ var shouldObserve = true;
4231
4308
  function toggleObserving(value) {
4232
4309
  shouldObserve = value;
4233
4310
  }
4311
+ // ssr mock dep
4312
+ var mockDep = {
4313
+ notify: noop,
4314
+ depend: noop,
4315
+ addSub: noop,
4316
+ removeSub: noop
4317
+ };
4234
4318
  /**
4235
4319
  * Observer class that is attached to each observed
4236
4320
  * object. Once attached, the observer converts the target
@@ -4238,78 +4322,63 @@ function toggleObserving(value) {
4238
4322
  * collect dependencies and dispatch updates.
4239
4323
  */
4240
4324
  var Observer = /** @class */ (function () {
4241
- function Observer(value, shallow) {
4325
+ function Observer(value, shallow, mock) {
4242
4326
  if (shallow === void 0) { shallow = false; }
4327
+ if (mock === void 0) { mock = false; }
4243
4328
  this.value = value;
4244
4329
  this.shallow = shallow;
4330
+ this.mock = mock;
4245
4331
  // this.value = value
4246
- this.dep = new Dep();
4332
+ this.dep = mock ? mockDep : new Dep();
4247
4333
  this.vmCount = 0;
4248
4334
  def(value, '__ob__', this);
4249
4335
  if (isArray(value)) {
4250
- if (hasProto) {
4251
- protoAugment(value, arrayMethods);
4252
- }
4253
- else {
4254
- copyAugment(value, arrayMethods, arrayKeys);
4336
+ if (!mock) {
4337
+ if (hasProto) {
4338
+ value.__proto__ = arrayMethods;
4339
+ /* eslint-enable no-proto */
4340
+ }
4341
+ else {
4342
+ for (var i = 0, l = arrayKeys.length; i < l; i++) {
4343
+ var key = arrayKeys[i];
4344
+ def(value, key, arrayMethods[key]);
4345
+ }
4346
+ }
4255
4347
  }
4256
4348
  if (!shallow) {
4257
4349
  this.observeArray(value);
4258
4350
  }
4259
4351
  }
4260
4352
  else {
4261
- this.walk(value, shallow);
4353
+ /**
4354
+ * Walk through all properties and convert them into
4355
+ * getter/setters. This method should only be called when
4356
+ * value type is Object.
4357
+ */
4358
+ var keys = Object.keys(value);
4359
+ for (var i = 0; i < keys.length; i++) {
4360
+ var key = keys[i];
4361
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
4362
+ }
4262
4363
  }
4263
4364
  }
4264
- /**
4265
- * Walk through all properties and convert them into
4266
- * getter/setters. This method should only be called when
4267
- * value type is Object.
4268
- */
4269
- Observer.prototype.walk = function (obj, shallow) {
4270
- var keys = Object.keys(obj);
4271
- for (var i = 0; i < keys.length; i++) {
4272
- var key = keys[i];
4273
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
4274
- }
4275
- };
4276
4365
  /**
4277
4366
  * Observe a list of Array items.
4278
4367
  */
4279
- Observer.prototype.observeArray = function (items) {
4280
- for (var i = 0, l = items.length; i < l; i++) {
4281
- observe(items[i]);
4368
+ Observer.prototype.observeArray = function (value) {
4369
+ for (var i = 0, l = value.length; i < l; i++) {
4370
+ observe(value[i], false, this.mock);
4282
4371
  }
4283
4372
  };
4284
4373
  return Observer;
4285
4374
  }());
4286
4375
  // helpers
4287
- /**
4288
- * Augment a target Object or Array by intercepting
4289
- * the prototype chain using __proto__
4290
- */
4291
- function protoAugment(target, src) {
4292
- /* eslint-disable no-proto */
4293
- target.__proto__ = src;
4294
- /* eslint-enable no-proto */
4295
- }
4296
- /**
4297
- * Augment a target Object or Array by defining
4298
- * hidden properties.
4299
- */
4300
- /* istanbul ignore next */
4301
- function copyAugment(target, src, keys) {
4302
- for (var i = 0, l = keys.length; i < l; i++) {
4303
- var key = keys[i];
4304
- def(target, key, src[key]);
4305
- }
4306
- }
4307
4376
  /**
4308
4377
  * Attempt to create an observer instance for a value,
4309
4378
  * returns the new observer if successfully observed,
4310
4379
  * or the existing observer if the value already has one.
4311
4380
  */
4312
- function observe(value, shallow) {
4381
+ function observe(value, shallow, ssrMockReactivity) {
4313
4382
  if (!isObject(value) || isRef(value) || value instanceof VNode) {
4314
4383
  return;
4315
4384
  }
@@ -4318,18 +4387,18 @@ function observe(value, shallow) {
4318
4387
  ob = value.__ob__;
4319
4388
  }
4320
4389
  else if (shouldObserve &&
4321
- !isServerRendering() &&
4390
+ (ssrMockReactivity || !isServerRendering()) &&
4322
4391
  (isArray(value) || isPlainObject(value)) &&
4323
4392
  Object.isExtensible(value) &&
4324
- !value.__v_skip) {
4325
- ob = new Observer(value, shallow);
4393
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
4394
+ ob = new Observer(value, shallow, ssrMockReactivity);
4326
4395
  }
4327
4396
  return ob;
4328
4397
  }
4329
4398
  /**
4330
4399
  * Define a reactive property on an Object.
4331
4400
  */
4332
- function defineReactive(obj, key, val, customSetter, shallow) {
4401
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
4333
4402
  var dep = new Dep();
4334
4403
  var property = Object.getOwnPropertyDescriptor(obj, key);
4335
4404
  if (property && property.configurable === false) {
@@ -4342,7 +4411,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4342
4411
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
4343
4412
  val = obj[key];
4344
4413
  }
4345
- var childOb = !shallow && observe(val);
4414
+ var childOb = !shallow && observe(val, false, mock);
4346
4415
  Object.defineProperty(obj, key, {
4347
4416
  enumerable: true,
4348
4417
  configurable: true,
@@ -4390,7 +4459,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4390
4459
  else {
4391
4460
  val = newVal;
4392
4461
  }
4393
- childOb = !shallow && observe(newVal);
4462
+ childOb = !shallow && observe(newVal, false, mock);
4394
4463
  if (process.env.NODE_ENV !== 'production') {
4395
4464
  dep.notify({
4396
4465
  type: "set" /* TriggerOpTypes.SET */,
@@ -4415,16 +4484,20 @@ function set(target, key, val) {
4415
4484
  process.env.NODE_ENV !== 'production' && warn("Set operation on key \"".concat(key, "\" failed: target is readonly."));
4416
4485
  return;
4417
4486
  }
4487
+ var ob = target.__ob__;
4418
4488
  if (isArray(target) && isValidArrayIndex(key)) {
4419
4489
  target.length = Math.max(target.length, key);
4420
4490
  target.splice(key, 1, val);
4491
+ // when mocking for SSR, array methods are not hijacked
4492
+ if (ob && !ob.shallow && ob.mock) {
4493
+ observe(val, false, true);
4494
+ }
4421
4495
  return val;
4422
4496
  }
4423
4497
  if (key in target && !(key in Object.prototype)) {
4424
4498
  target[key] = val;
4425
4499
  return val;
4426
4500
  }
4427
- var ob = target.__ob__;
4428
4501
  if (target._isVue || (ob && ob.vmCount)) {
4429
4502
  process.env.NODE_ENV !== 'production' &&
4430
4503
  warn('Avoid adding reactive properties to a Vue instance or its root $data ' +
@@ -4435,7 +4508,7 @@ function set(target, key, val) {
4435
4508
  target[key] = val;
4436
4509
  return val;
4437
4510
  }
4438
- defineReactive(ob.value, key, val);
4511
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
4439
4512
  if (process.env.NODE_ENV !== 'production') {
4440
4513
  ob.dep.notify({
4441
4514
  type: "add" /* TriggerOpTypes.ADD */,
@@ -7057,7 +7130,7 @@ function normalizeDirectives(dirs, vm) {
7057
7130
  }
7058
7131
  res[getRawDirName(dir)] = dir;
7059
7132
  if (vm._setupState && vm._setupState.__sfc) {
7060
- dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name);
7133
+ dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7061
7134
  }
7062
7135
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
7063
7136
  }
@@ -8604,4 +8677,4 @@ if (inBrowser) {
8604
8677
  }, 0);
8605
8678
  }
8606
8679
 
8607
- export { EffectScope, computed, customRef, Vue as default, 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 };
8680
+ 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 };