vue 2.7.0 → 2.7.3

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 +88 -75
  2. package/dist/vue.common.prod.js +3 -3
  3. package/dist/vue.esm.browser.js +88 -76
  4. package/dist/vue.esm.browser.min.js +3 -3
  5. package/dist/vue.esm.js +89 -76
  6. package/dist/vue.js +89 -75
  7. package/dist/vue.min.js +3 -3
  8. package/dist/vue.runtime.common.dev.js +88 -75
  9. package/dist/vue.runtime.common.prod.js +3 -3
  10. package/dist/vue.runtime.esm.js +89 -76
  11. package/dist/vue.runtime.js +89 -75
  12. package/dist/vue.runtime.min.js +3 -3
  13. package/dist/vue.runtime.mjs +89 -76
  14. package/package.json +2 -2
  15. package/packages/compiler-sfc/dist/compiler-sfc.js +70 -67
  16. package/packages/compiler-sfc/package.json +1 -1
  17. package/packages/compiler-sfc/src/compileScript.ts +12 -15
  18. package/packages/compiler-sfc/src/parseComponent.ts +6 -1
  19. package/packages/compiler-sfc/src/templateCompilerModules/srcset.ts +1 -1
  20. package/packages/compiler-sfc/test/compileScript.spec.ts +12 -0
  21. package/src/core/observer/index.ts +55 -56
  22. package/src/core/util/next-tick.ts +2 -1
  23. package/src/core/vdom/modules/directives.ts +2 -2
  24. package/src/shared/constants.ts +3 -1
  25. package/src/shared/util.ts +1 -1
  26. package/src/v3/apiSetup.ts +4 -21
  27. package/src/v3/apiWatch.ts +2 -2
  28. package/src/v3/index.ts +1 -0
  29. package/src/v3/reactivity/reactive.ts +13 -2
  30. package/src/v3/reactivity/ref.ts +40 -2
  31. package/types/common.d.ts +6 -0
  32. package/types/index.d.ts +7 -4
  33. package/types/jsx.d.ts +16 -2
  34. package/types/options.d.ts +7 -1
  35. package/types/v3-component-options.d.ts +162 -33
  36. package/types/v3-component-props.d.ts +19 -20
  37. package/types/v3-component-public-instance.d.ts +230 -0
  38. package/types/v3-define-component.d.ts +70 -12
  39. package/types/v3-generated.d.ts +5 -1
  40. package/types/v3-setup-context.d.ts +0 -6
  41. package/types/vnode.d.ts +15 -0
  42. package/types/v3-component-proxy.d.ts +0 -189
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vue.js v2.7.0
2
+ * Vue.js v2.7.3
3
3
  * (c) 2014-2022 Evan You
4
4
  * Released under the MIT License.
5
5
  */
@@ -308,7 +308,7 @@ function hasChanged(x, y) {
308
308
  return x === 0 && 1 / x !== 1 / y;
309
309
  }
310
310
  else {
311
- return x === x && y === y;
311
+ return x === x || y === y;
312
312
  }
313
313
  }
314
314
 
@@ -326,7 +326,9 @@ const LIFECYCLE_HOOKS = [
326
326
  'activated',
327
327
  'deactivated',
328
328
  'errorCaptured',
329
- 'serverPrefetch'
329
+ 'serverPrefetch',
330
+ 'renderTracked',
331
+ 'renderTriggered'
330
332
  ];
331
333
 
332
334
  var config = {
@@ -834,7 +836,7 @@ function makeReactive(target, shallow) {
834
836
  warn(`Target is already a ${existingOb.shallow ? `` : `non-`}shallow reactive object, and cannot be converted to ${shallow ? `` : `non-`}shallow.`);
835
837
  }
836
838
  }
837
- const ob = observe(target, shallow);
839
+ const ob = observe(target, shallow, isServerRendering() /* ssr mock reactivity */);
838
840
  if (!ob) {
839
841
  if (target == null || isPrimitive(target)) {
840
842
  warn(`value cannot be made reactive: ${String(target)}`);
@@ -896,7 +898,7 @@ function createRef(rawValue, shallow) {
896
898
  const ref = {};
897
899
  def(ref, RefFlag, true);
898
900
  def(ref, "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */, true);
899
- ref.dep = defineReactive(ref, 'value', rawValue, null, shallow);
901
+ def(ref, 'dep', defineReactive(ref, 'value', rawValue, null, shallow, isServerRendering()));
900
902
  return ref;
901
903
  }
902
904
  function triggerRef(ref) {
@@ -915,6 +917,33 @@ function triggerRef(ref) {
915
917
  function unref(ref) {
916
918
  return isRef(ref) ? ref.value : ref;
917
919
  }
920
+ function proxyRefs(objectWithRefs) {
921
+ if (isReactive(objectWithRefs)) {
922
+ return objectWithRefs;
923
+ }
924
+ const proxy = {};
925
+ const keys = Object.keys(objectWithRefs);
926
+ for (let i = 0; i < keys.length; i++) {
927
+ proxyWithRefUnwrap(proxy, objectWithRefs, keys[i]);
928
+ }
929
+ return proxy;
930
+ }
931
+ function proxyWithRefUnwrap(target, source, key) {
932
+ Object.defineProperty(target, key, {
933
+ enumerable: true,
934
+ configurable: true,
935
+ get: () => unref(source[key]),
936
+ set: value => {
937
+ const oldValue = source[key];
938
+ if (isRef(oldValue) && !isRef(value)) {
939
+ oldValue.value = value;
940
+ }
941
+ else {
942
+ source[key] = value;
943
+ }
944
+ }
945
+ });
946
+ }
918
947
  function customRef(factory) {
919
948
  const dep = new Dep();
920
949
  const { get, set } = factory(() => {
@@ -2311,7 +2340,9 @@ function initSetup(vm) {
2311
2340
  // exposed for compiled render fn
2312
2341
  const proxy = (vm._setupProxy = {});
2313
2342
  for (const key in setupResult) {
2314
- proxyWithRefUnwrap(proxy, setupResult, key);
2343
+ if (key !== '__sfc') {
2344
+ proxyWithRefUnwrap(proxy, setupResult, key);
2345
+ }
2315
2346
  }
2316
2347
  }
2317
2348
  }
@@ -2320,20 +2351,6 @@ function initSetup(vm) {
2320
2351
  }
2321
2352
  }
2322
2353
  }
2323
- function proxyWithRefUnwrap(target, source, key) {
2324
- Object.defineProperty(target, key, {
2325
- enumerable: true,
2326
- configurable: true,
2327
- get: () => {
2328
- const raw = source[key];
2329
- return isRef(raw) ? raw.value : raw;
2330
- },
2331
- set: newVal => {
2332
- const raw = source[key];
2333
- isRef(raw) ? (raw.value = newVal) : (source[key] = newVal);
2334
- }
2335
- });
2336
- }
2337
2354
  function createSetupContext(vm) {
2338
2355
  let exposeCalled = false;
2339
2356
  return {
@@ -4100,7 +4117,7 @@ const onServerPrefetch = createLifeCycle('serverPrefetch');
4100
4117
  const onRenderTracked = createLifeCycle('renderTracked');
4101
4118
  const onRenderTriggered = createLifeCycle('renderTriggered');
4102
4119
 
4103
- const version = '2.7.0';
4120
+ const version = '2.7.3';
4104
4121
  /**
4105
4122
  * @internal type is manually declared in <root>/types/v3-define-component.d.ts
4106
4123
  */
@@ -4118,6 +4135,7 @@ var vca = /*#__PURE__*/Object.freeze({
4118
4135
  toRef: toRef,
4119
4136
  toRefs: toRefs,
4120
4137
  unref: unref,
4138
+ proxyRefs: proxyRefs,
4121
4139
  customRef: customRef,
4122
4140
  triggerRef: triggerRef,
4123
4141
  reactive: reactive,
@@ -4175,6 +4193,13 @@ let shouldObserve = true;
4175
4193
  function toggleObserving(value) {
4176
4194
  shouldObserve = value;
4177
4195
  }
4196
+ // ssr mock dep
4197
+ const mockDep = {
4198
+ notify: noop,
4199
+ depend: noop,
4200
+ addSub: noop,
4201
+ removeSub: noop
4202
+ };
4178
4203
  /**
4179
4204
  * Observer class that is attached to each observed
4180
4205
  * object. Once attached, the observer converts the target
@@ -4182,76 +4207,60 @@ function toggleObserving(value) {
4182
4207
  * collect dependencies and dispatch updates.
4183
4208
  */
4184
4209
  class Observer {
4185
- constructor(value, shallow = false) {
4210
+ constructor(value, shallow = false, mock = false) {
4186
4211
  this.value = value;
4187
4212
  this.shallow = shallow;
4213
+ this.mock = mock;
4188
4214
  // this.value = value
4189
- this.dep = new Dep();
4215
+ this.dep = mock ? mockDep : new Dep();
4190
4216
  this.vmCount = 0;
4191
4217
  def(value, '__ob__', this);
4192
4218
  if (isArray(value)) {
4193
- if (hasProto) {
4194
- protoAugment(value, arrayMethods);
4195
- }
4196
- else {
4197
- copyAugment(value, arrayMethods, arrayKeys);
4219
+ if (!mock) {
4220
+ if (hasProto) {
4221
+ value.__proto__ = arrayMethods;
4222
+ /* eslint-enable no-proto */
4223
+ }
4224
+ else {
4225
+ for (let i = 0, l = arrayKeys.length; i < l; i++) {
4226
+ const key = arrayKeys[i];
4227
+ def(value, key, arrayMethods[key]);
4228
+ }
4229
+ }
4198
4230
  }
4199
4231
  if (!shallow) {
4200
4232
  this.observeArray(value);
4201
4233
  }
4202
4234
  }
4203
4235
  else {
4204
- this.walk(value, shallow);
4205
- }
4206
- }
4207
- /**
4208
- * Walk through all properties and convert them into
4209
- * getter/setters. This method should only be called when
4210
- * value type is Object.
4211
- */
4212
- walk(obj, shallow) {
4213
- const keys = Object.keys(obj);
4214
- for (let i = 0; i < keys.length; i++) {
4215
- const key = keys[i];
4216
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
4236
+ /**
4237
+ * Walk through all properties and convert them into
4238
+ * getter/setters. This method should only be called when
4239
+ * value type is Object.
4240
+ */
4241
+ const keys = Object.keys(value);
4242
+ for (let i = 0; i < keys.length; i++) {
4243
+ const key = keys[i];
4244
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
4245
+ }
4217
4246
  }
4218
4247
  }
4219
4248
  /**
4220
4249
  * Observe a list of Array items.
4221
4250
  */
4222
- observeArray(items) {
4223
- for (let i = 0, l = items.length; i < l; i++) {
4224
- observe(items[i]);
4251
+ observeArray(value) {
4252
+ for (let i = 0, l = value.length; i < l; i++) {
4253
+ observe(value[i], false, this.mock);
4225
4254
  }
4226
4255
  }
4227
4256
  }
4228
4257
  // helpers
4229
- /**
4230
- * Augment a target Object or Array by intercepting
4231
- * the prototype chain using __proto__
4232
- */
4233
- function protoAugment(target, src) {
4234
- /* eslint-disable no-proto */
4235
- target.__proto__ = src;
4236
- /* eslint-enable no-proto */
4237
- }
4238
- /**
4239
- * Augment a target Object or Array by defining
4240
- * hidden properties.
4241
- */
4242
- /* istanbul ignore next */
4243
- function copyAugment(target, src, keys) {
4244
- for (let i = 0, l = keys.length; i < l; i++) {
4245
- const key = keys[i];
4246
- def(target, key, src[key]);
4247
- }
4248
- }
4249
4258
  /**
4250
4259
  * Attempt to create an observer instance for a value,
4251
4260
  * returns the new observer if successfully observed,
4252
4261
  * or the existing observer if the value already has one.
4253
4262
  */
4254
- function observe(value, shallow) {
4263
+ function observe(value, shallow, ssrMockReactivity) {
4255
4264
  if (!isObject(value) || isRef(value) || value instanceof VNode) {
4256
4265
  return;
4257
4266
  }
@@ -4260,18 +4269,18 @@ function observe(value, shallow) {
4260
4269
  ob = value.__ob__;
4261
4270
  }
4262
4271
  else if (shouldObserve &&
4263
- !isServerRendering() &&
4272
+ (ssrMockReactivity || !isServerRendering()) &&
4264
4273
  (isArray(value) || isPlainObject(value)) &&
4265
4274
  Object.isExtensible(value) &&
4266
- !value.__v_skip) {
4267
- ob = new Observer(value, shallow);
4275
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
4276
+ ob = new Observer(value, shallow, ssrMockReactivity);
4268
4277
  }
4269
4278
  return ob;
4270
4279
  }
4271
4280
  /**
4272
4281
  * Define a reactive property on an Object.
4273
4282
  */
4274
- function defineReactive(obj, key, val, customSetter, shallow) {
4283
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
4275
4284
  const dep = new Dep();
4276
4285
  const property = Object.getOwnPropertyDescriptor(obj, key);
4277
4286
  if (property && property.configurable === false) {
@@ -4284,7 +4293,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4284
4293
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
4285
4294
  val = obj[key];
4286
4295
  }
4287
- let childOb = !shallow && observe(val);
4296
+ let childOb = !shallow && observe(val, false, mock);
4288
4297
  Object.defineProperty(obj, key, {
4289
4298
  enumerable: true,
4290
4299
  configurable: true,
@@ -4305,7 +4314,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4305
4314
  }
4306
4315
  }
4307
4316
  }
4308
- return isRef(value) ? value.value : value;
4317
+ return isRef(value) && !shallow ? value.value : value;
4309
4318
  },
4310
4319
  set: function reactiveSetter(newVal) {
4311
4320
  const value = getter ? getter.call(obj) : val;
@@ -4329,7 +4338,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
4329
4338
  else {
4330
4339
  val = newVal;
4331
4340
  }
4332
- childOb = !shallow && observe(newVal);
4341
+ childOb = !shallow && observe(newVal, false, mock);
4333
4342
  {
4334
4343
  dep.notify({
4335
4344
  type: "set" /* TriggerOpTypes.SET */,
@@ -4351,16 +4360,20 @@ function set(target, key, val) {
4351
4360
  warn(`Set operation on key "${key}" failed: target is readonly.`);
4352
4361
  return;
4353
4362
  }
4363
+ const ob = target.__ob__;
4354
4364
  if (isArray(target) && isValidArrayIndex(key)) {
4355
4365
  target.length = Math.max(target.length, key);
4356
4366
  target.splice(key, 1, val);
4367
+ // when mocking for SSR, array methods are not hijacked
4368
+ if (!ob.shallow && ob.mock) {
4369
+ observe(val, false, true);
4370
+ }
4357
4371
  return val;
4358
4372
  }
4359
4373
  if (key in target && !(key in Object.prototype)) {
4360
4374
  target[key] = val;
4361
4375
  return val;
4362
4376
  }
4363
- const ob = target.__ob__;
4364
4377
  if (target._isVue || (ob && ob.vmCount)) {
4365
4378
  warn('Avoid adding reactive properties to a Vue instance or its root $data ' +
4366
4379
  'at runtime - declare it upfront in the data option.');
@@ -4370,7 +4383,7 @@ function set(target, key, val) {
4370
4383
  target[key] = val;
4371
4384
  return val;
4372
4385
  }
4373
- defineReactive(ob.value, key, val);
4386
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
4374
4387
  {
4375
4388
  ob.dep.notify({
4376
4389
  type: "add" /* TriggerOpTypes.ADD */,
@@ -6964,7 +6977,7 @@ function normalizeDirectives(dirs, vm) {
6964
6977
  }
6965
6978
  res[getRawDirName(dir)] = dir;
6966
6979
  if (vm._setupState && vm._setupState.__sfc) {
6967
- dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name);
6980
+ dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name);
6968
6981
  }
6969
6982
  dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true);
6970
6983
  }