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
  */
@@ -330,7 +330,9 @@
330
330
  'activated',
331
331
  'deactivated',
332
332
  'errorCaptured',
333
- 'serverPrefetch'
333
+ 'serverPrefetch',
334
+ 'renderTracked',
335
+ 'renderTriggered'
334
336
  ];
335
337
 
336
338
  var config = {
@@ -882,7 +884,7 @@
882
884
  warn("Target is already a ".concat(existingOb.shallow ? "" : "non-", "shallow reactive object, and cannot be converted to ").concat(shallow ? "" : "non-", "shallow."));
883
885
  }
884
886
  }
885
- var ob = observe(target, shallow);
887
+ var ob = observe(target, shallow, isServerRendering() /* ssr mock reactivity */);
886
888
  if (!ob) {
887
889
  if (target == null || isPrimitive(target)) {
888
890
  warn("value cannot be made reactive: ".concat(String(target)));
@@ -944,7 +946,7 @@
944
946
  var ref = {};
945
947
  def(ref, RefFlag, true);
946
948
  def(ref, "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */, true);
947
- ref.dep = defineReactive(ref, 'value', rawValue, null, shallow);
949
+ def(ref, 'dep', defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering()));
948
950
  return ref;
949
951
  }
950
952
  function triggerRef(ref) {
@@ -1818,7 +1820,7 @@
1818
1820
  return tree;
1819
1821
  }
1820
1822
  // otherwise, render a fresh tree.
1821
- tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, null, this // for render fns generated for functional component templates
1823
+ tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, this._c, this // for render fns generated for functional component templates
1822
1824
  );
1823
1825
  markStatic(tree, "__static__".concat(index), false);
1824
1826
  return tree;
@@ -3880,8 +3882,8 @@
3880
3882
  else {
3881
3883
  // pre
3882
3884
  watcher.update = function () {
3883
- if (instance && instance === currentInstance) {
3884
- // pre-watcher triggered inside setup()
3885
+ if (instance && instance === currentInstance && !instance._isMounted) {
3886
+ // pre-watcher triggered before
3885
3887
  var buffer = instance._preWatchers || (instance._preWatchers = []);
3886
3888
  if (buffer.indexOf(watcher) < 0)
3887
3889
  buffer.push(watcher);
@@ -4141,6 +4143,78 @@
4141
4143
  });
4142
4144
  }
4143
4145
 
4146
+ /**
4147
+ * v3-compatible async component API.
4148
+ * @internal the type is manually declared in <root>/types/v3-define-async-component.d.ts
4149
+ * because it relies on existing manual types
4150
+ */
4151
+ function defineAsyncComponent(source) {
4152
+ if (isFunction(source)) {
4153
+ source = { loader: source };
4154
+ }
4155
+ 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
4156
+ _b = source.suspensible, // undefined = never times out
4157
+ suspensible = _b === void 0 ? false : _b, // in Vue 3 default is true
4158
+ userOnError = source.onError;
4159
+ if (suspensible) {
4160
+ warn("The suspensiblbe option for async components is not supported in Vue2. It is ignored.");
4161
+ }
4162
+ var pendingRequest = null;
4163
+ var retries = 0;
4164
+ var retry = function () {
4165
+ retries++;
4166
+ pendingRequest = null;
4167
+ return load();
4168
+ };
4169
+ var load = function () {
4170
+ var thisRequest;
4171
+ return (pendingRequest ||
4172
+ (thisRequest = pendingRequest =
4173
+ loader()
4174
+ .catch(function (err) {
4175
+ err = err instanceof Error ? err : new Error(String(err));
4176
+ if (userOnError) {
4177
+ return new Promise(function (resolve, reject) {
4178
+ var userRetry = function () { return resolve(retry()); };
4179
+ var userFail = function () { return reject(err); };
4180
+ userOnError(err, userRetry, userFail, retries + 1);
4181
+ });
4182
+ }
4183
+ else {
4184
+ throw err;
4185
+ }
4186
+ })
4187
+ .then(function (comp) {
4188
+ if (thisRequest !== pendingRequest && pendingRequest) {
4189
+ return pendingRequest;
4190
+ }
4191
+ if (!comp) {
4192
+ warn("Async component loader resolved to undefined. " +
4193
+ "If you are using retry(), make sure to return its return value.");
4194
+ }
4195
+ // interop module default
4196
+ if (comp &&
4197
+ (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
4198
+ comp = comp.default;
4199
+ }
4200
+ if (comp && !isObject(comp) && !isFunction(comp)) {
4201
+ throw new Error("Invalid async component load result: ".concat(comp));
4202
+ }
4203
+ return comp;
4204
+ })));
4205
+ };
4206
+ return function () {
4207
+ var component = load();
4208
+ return {
4209
+ component: component,
4210
+ delay: delay,
4211
+ timeout: timeout,
4212
+ error: errorComponent,
4213
+ loading: loadingComponent
4214
+ };
4215
+ };
4216
+ }
4217
+
4144
4218
  function createLifeCycle(hookName) {
4145
4219
  return function (fn, target) {
4146
4220
  if (target === void 0) { target = currentInstance; }
@@ -4179,7 +4253,10 @@
4179
4253
  var onRenderTracked = createLifeCycle('renderTracked');
4180
4254
  var onRenderTriggered = createLifeCycle('renderTriggered');
4181
4255
 
4182
- var version = '2.7.1';
4256
+ /**
4257
+ * Note: also update dist/vue.runtime.mjs when adding new exports to this file.
4258
+ */
4259
+ var version = '2.7.4';
4183
4260
  /**
4184
4261
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
4185
4262
  */
@@ -4231,6 +4308,7 @@
4231
4308
  del: del,
4232
4309
  useCssModule: useCssModule,
4233
4310
  useCssVars: useCssVars,
4311
+ defineAsyncComponent: defineAsyncComponent,
4234
4312
  onBeforeMount: onBeforeMount,
4235
4313
  onMounted: onMounted,
4236
4314
  onBeforeUpdate: onBeforeUpdate,
@@ -4255,6 +4333,13 @@
4255
4333
  function toggleObserving(value) {
4256
4334
  shouldObserve = value;
4257
4335
  }
4336
+ // ssr mock dep
4337
+ var mockDep = {
4338
+ notify: noop,
4339
+ depend: noop,
4340
+ addSub: noop,
4341
+ removeSub: noop
4342
+ };
4258
4343
  /**
4259
4344
  * Observer class that is attached to each observed
4260
4345
  * object. Once attached, the observer converts the target
@@ -4262,78 +4347,63 @@
4262
4347
  * collect dependencies and dispatch updates.
4263
4348
  */
4264
4349
  var Observer = /** @class */ (function () {
4265
- function Observer(value, shallow) {
4350
+ function Observer(value, shallow, mock) {
4266
4351
  if (shallow === void 0) { shallow = false; }
4352
+ if (mock === void 0) { mock = false; }
4267
4353
  this.value = value;
4268
4354
  this.shallow = shallow;
4355
+ this.mock = mock;
4269
4356
  // this.value = value
4270
- this.dep = new Dep();
4357
+ this.dep = mock ? mockDep : new Dep();
4271
4358
  this.vmCount = 0;
4272
4359
  def(value, '__ob__', this);
4273
4360
  if (isArray(value)) {
4274
- if (hasProto) {
4275
- protoAugment(value, arrayMethods);
4276
- }
4277
- else {
4278
- copyAugment(value, arrayMethods, arrayKeys);
4361
+ if (!mock) {
4362
+ if (hasProto) {
4363
+ value.__proto__ = arrayMethods;
4364
+ /* eslint-enable no-proto */
4365
+ }
4366
+ else {
4367
+ for (var i = 0, l = arrayKeys.length; i < l; i++) {
4368
+ var key = arrayKeys[i];
4369
+ def(value, key, arrayMethods[key]);
4370
+ }
4371
+ }
4279
4372
  }
4280
4373
  if (!shallow) {
4281
4374
  this.observeArray(value);
4282
4375
  }
4283
4376
  }
4284
4377
  else {
4285
- this.walk(value, shallow);
4378
+ /**
4379
+ * Walk through all properties and convert them into
4380
+ * getter/setters. This method should only be called when
4381
+ * value type is Object.
4382
+ */
4383
+ var keys = Object.keys(value);
4384
+ for (var i = 0; i < keys.length; i++) {
4385
+ var key = keys[i];
4386
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
4387
+ }
4286
4388
  }
4287
4389
  }
4288
- /**
4289
- * Walk through all properties and convert them into
4290
- * getter/setters. This method should only be called when
4291
- * value type is Object.
4292
- */
4293
- Observer.prototype.walk = function (obj, shallow) {
4294
- var keys = Object.keys(obj);
4295
- for (var i = 0; i < keys.length; i++) {
4296
- var key = keys[i];
4297
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
4298
- }
4299
- };
4300
4390
  /**
4301
4391
  * Observe a list of Array items.
4302
4392
  */
4303
- Observer.prototype.observeArray = function (items) {
4304
- for (var i = 0, l = items.length; i < l; i++) {
4305
- observe(items[i]);
4393
+ Observer.prototype.observeArray = function (value) {
4394
+ for (var i = 0, l = value.length; i < l; i++) {
4395
+ observe(value[i], false, this.mock);
4306
4396
  }
4307
4397
  };
4308
4398
  return Observer;
4309
4399
  }());
4310
4400
  // helpers
4311
- /**
4312
- * Augment a target Object or Array by intercepting
4313
- * the prototype chain using __proto__
4314
- */
4315
- function protoAugment(target, src) {
4316
- /* eslint-disable no-proto */
4317
- target.__proto__ = src;
4318
- /* eslint-enable no-proto */
4319
- }
4320
- /**
4321
- * Augment a target Object or Array by defining
4322
- * hidden properties.
4323
- */
4324
- /* istanbul ignore next */
4325
- function copyAugment(target, src, keys) {
4326
- for (var i = 0, l = keys.length; i < l; i++) {
4327
- var key = keys[i];
4328
- def(target, key, src[key]);
4329
- }
4330
- }
4331
4401
  /**
4332
4402
  * Attempt to create an observer instance for a value,
4333
4403
  * returns the new observer if successfully observed,
4334
4404
  * or the existing observer if the value already has one.
4335
4405
  */
4336
- function observe(value, shallow) {
4406
+ function observe(value, shallow, ssrMockReactivity) {
4337
4407
  if (!isObject(value) || isRef(value) || value instanceof VNode) {
4338
4408
  return;
4339
4409
  }
@@ -4342,18 +4412,18 @@
4342
4412
  ob = value.__ob__;
4343
4413
  }
4344
4414
  else if (shouldObserve &&
4345
- !isServerRendering() &&
4415
+ (ssrMockReactivity || !isServerRendering()) &&
4346
4416
  (isArray(value) || isPlainObject(value)) &&
4347
4417
  Object.isExtensible(value) &&
4348
- !value.__v_skip) {
4349
- ob = new Observer(value, shallow);
4418
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
4419
+ ob = new Observer(value, shallow, ssrMockReactivity);
4350
4420
  }
4351
4421
  return ob;
4352
4422
  }
4353
4423
  /**
4354
4424
  * Define a reactive property on an Object.
4355
4425
  */
4356
- function defineReactive(obj, key, val, customSetter, shallow) {
4426
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
4357
4427
  var dep = new Dep();
4358
4428
  var property = Object.getOwnPropertyDescriptor(obj, key);
4359
4429
  if (property && property.configurable === false) {
@@ -4366,7 +4436,7 @@
4366
4436
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
4367
4437
  val = obj[key];
4368
4438
  }
4369
- var childOb = !shallow && observe(val);
4439
+ var childOb = !shallow && observe(val, false, mock);
4370
4440
  Object.defineProperty(obj, key, {
4371
4441
  enumerable: true,
4372
4442
  configurable: true,
@@ -4411,7 +4481,7 @@
4411
4481
  else {
4412
4482
  val = newVal;
4413
4483
  }
4414
- childOb = !shallow && observe(newVal);
4484
+ childOb = !shallow && observe(newVal, false, mock);
4415
4485
  {
4416
4486
  dep.notify({
4417
4487
  type: "set" /* TriggerOpTypes.SET */,
@@ -4433,16 +4503,20 @@
4433
4503
  warn("Set operation on key \"".concat(key, "\" failed: target is readonly."));
4434
4504
  return;
4435
4505
  }
4506
+ var ob = target.__ob__;
4436
4507
  if (isArray(target) && isValidArrayIndex(key)) {
4437
4508
  target.length = Math.max(target.length, key);
4438
4509
  target.splice(key, 1, val);
4510
+ // when mocking for SSR, array methods are not hijacked
4511
+ if (ob && !ob.shallow && ob.mock) {
4512
+ observe(val, false, true);
4513
+ }
4439
4514
  return val;
4440
4515
  }
4441
4516
  if (key in target && !(key in Object.prototype)) {
4442
4517
  target[key] = val;
4443
4518
  return val;
4444
4519
  }
4445
- var ob = target.__ob__;
4446
4520
  if (target._isVue || (ob && ob.vmCount)) {
4447
4521
  warn('Avoid adding reactive properties to a Vue instance or its root $data ' +
4448
4522
  'at runtime - declare it upfront in the data option.');
@@ -4452,7 +4526,7 @@
4452
4526
  target[key] = val;
4453
4527
  return val;
4454
4528
  }
4455
- defineReactive(ob.value, key, val);
4529
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
4456
4530
  {
4457
4531
  ob.dep.notify({
4458
4532
  type: "add" /* TriggerOpTypes.ADD */,
@@ -7055,7 +7129,7 @@
7055
7129
  }
7056
7130
  res[getRawDirName(dir)] = dir;
7057
7131
  if (vm._setupState && vm._setupState.__sfc) {
7058
- dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name);
7132
+ dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
7059
7133
  }
7060
7134
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
7061
7135
  }