@vue/compiler-sfc 2.7.2 → 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.
@@ -3350,7 +3350,9 @@ const LIFECYCLE_HOOKS = [
3350
3350
  'activated',
3351
3351
  'deactivated',
3352
3352
  'errorCaptured',
3353
- 'serverPrefetch'
3353
+ 'serverPrefetch',
3354
+ 'renderTracked',
3355
+ 'renderTriggered'
3354
3356
  ];
3355
3357
 
3356
3358
  var config = {
@@ -5189,6 +5191,13 @@ let shouldObserve = true;
5189
5191
  function toggleObserving(value) {
5190
5192
  shouldObserve = value;
5191
5193
  }
5194
+ // ssr mock dep
5195
+ const mockDep = {
5196
+ notify: noop,
5197
+ depend: noop,
5198
+ addSub: noop,
5199
+ removeSub: noop
5200
+ };
5192
5201
  /**
5193
5202
  * Observer class that is attached to each observed
5194
5203
  * object. Once attached, the observer converts the target
@@ -5196,76 +5205,60 @@ function toggleObserving(value) {
5196
5205
  * collect dependencies and dispatch updates.
5197
5206
  */
5198
5207
  class Observer {
5199
- constructor(value, shallow = false) {
5208
+ constructor(value, shallow = false, mock = false) {
5200
5209
  this.value = value;
5201
5210
  this.shallow = shallow;
5211
+ this.mock = mock;
5202
5212
  // this.value = value
5203
- this.dep = new Dep();
5213
+ this.dep = mock ? mockDep : new Dep();
5204
5214
  this.vmCount = 0;
5205
5215
  def(value, '__ob__', this);
5206
5216
  if (isArray(value)) {
5207
- if (hasProto) {
5208
- protoAugment(value, arrayMethods);
5209
- }
5210
- else {
5211
- copyAugment(value, arrayMethods, arrayKeys);
5217
+ if (!mock) {
5218
+ if (hasProto) {
5219
+ value.__proto__ = arrayMethods;
5220
+ /* eslint-enable no-proto */
5221
+ }
5222
+ else {
5223
+ for (let i = 0, l = arrayKeys.length; i < l; i++) {
5224
+ const key = arrayKeys[i];
5225
+ def(value, key, arrayMethods[key]);
5226
+ }
5227
+ }
5212
5228
  }
5213
5229
  if (!shallow) {
5214
5230
  this.observeArray(value);
5215
5231
  }
5216
5232
  }
5217
5233
  else {
5218
- this.walk(value, shallow);
5219
- }
5220
- }
5221
- /**
5222
- * Walk through all properties and convert them into
5223
- * getter/setters. This method should only be called when
5224
- * value type is Object.
5225
- */
5226
- walk(obj, shallow) {
5227
- const keys = Object.keys(obj);
5228
- for (let i = 0; i < keys.length; i++) {
5229
- const key = keys[i];
5230
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
5234
+ /**
5235
+ * Walk through all properties and convert them into
5236
+ * getter/setters. This method should only be called when
5237
+ * value type is Object.
5238
+ */
5239
+ const keys = Object.keys(value);
5240
+ for (let i = 0; i < keys.length; i++) {
5241
+ const key = keys[i];
5242
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
5243
+ }
5231
5244
  }
5232
5245
  }
5233
5246
  /**
5234
5247
  * Observe a list of Array items.
5235
5248
  */
5236
- observeArray(items) {
5237
- for (let i = 0, l = items.length; i < l; i++) {
5238
- observe(items[i]);
5249
+ observeArray(value) {
5250
+ for (let i = 0, l = value.length; i < l; i++) {
5251
+ observe(value[i], false, this.mock);
5239
5252
  }
5240
5253
  }
5241
5254
  }
5242
5255
  // helpers
5243
- /**
5244
- * Augment a target Object or Array by intercepting
5245
- * the prototype chain using __proto__
5246
- */
5247
- function protoAugment(target, src) {
5248
- /* eslint-disable no-proto */
5249
- target.__proto__ = src;
5250
- /* eslint-enable no-proto */
5251
- }
5252
- /**
5253
- * Augment a target Object or Array by defining
5254
- * hidden properties.
5255
- */
5256
- /* istanbul ignore next */
5257
- function copyAugment(target, src, keys) {
5258
- for (let i = 0, l = keys.length; i < l; i++) {
5259
- const key = keys[i];
5260
- def(target, key, src[key]);
5261
- }
5262
- }
5263
5256
  /**
5264
5257
  * Attempt to create an observer instance for a value,
5265
5258
  * returns the new observer if successfully observed,
5266
5259
  * or the existing observer if the value already has one.
5267
5260
  */
5268
- function observe(value, shallow) {
5261
+ function observe(value, shallow, ssrMockReactivity) {
5269
5262
  if (!isObject$1(value) || isRef(value) || value instanceof VNode) {
5270
5263
  return;
5271
5264
  }
@@ -5274,18 +5267,18 @@ function observe(value, shallow) {
5274
5267
  ob = value.__ob__;
5275
5268
  }
5276
5269
  else if (shouldObserve &&
5277
- !isServerRendering() &&
5270
+ (ssrMockReactivity || !isServerRendering()) &&
5278
5271
  (isArray(value) || isPlainObject(value)) &&
5279
5272
  Object.isExtensible(value) &&
5280
- !value.__v_skip) {
5281
- ob = new Observer(value, shallow);
5273
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
5274
+ ob = new Observer(value, shallow, ssrMockReactivity);
5282
5275
  }
5283
5276
  return ob;
5284
5277
  }
5285
5278
  /**
5286
5279
  * Define a reactive property on an Object.
5287
5280
  */
5288
- function defineReactive(obj, key, val, customSetter, shallow) {
5281
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
5289
5282
  const dep = new Dep();
5290
5283
  const property = Object.getOwnPropertyDescriptor(obj, key);
5291
5284
  if (property && property.configurable === false) {
@@ -5298,7 +5291,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
5298
5291
  (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
5299
5292
  val = obj[key];
5300
5293
  }
5301
- let childOb = !shallow && observe(val);
5294
+ let childOb = !shallow && observe(val, false, mock);
5302
5295
  Object.defineProperty(obj, key, {
5303
5296
  enumerable: true,
5304
5297
  configurable: true,
@@ -5346,7 +5339,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
5346
5339
  else {
5347
5340
  val = newVal;
5348
5341
  }
5349
- childOb = !shallow && observe(newVal);
5342
+ childOb = !shallow && observe(newVal, false, mock);
5350
5343
  if (process.env.NODE_ENV !== 'production') {
5351
5344
  dep.notify({
5352
5345
  type: "set" /* TriggerOpTypes.SET */,
@@ -5371,16 +5364,20 @@ function set(target, key, val) {
5371
5364
  process.env.NODE_ENV !== 'production' && warn$3(`Set operation on key "${key}" failed: target is readonly.`);
5372
5365
  return;
5373
5366
  }
5367
+ const ob = target.__ob__;
5374
5368
  if (isArray(target) && isValidArrayIndex(key)) {
5375
5369
  target.length = Math.max(target.length, key);
5376
5370
  target.splice(key, 1, val);
5371
+ // when mocking for SSR, array methods are not hijacked
5372
+ if (!ob.shallow && ob.mock) {
5373
+ observe(val, false, true);
5374
+ }
5377
5375
  return val;
5378
5376
  }
5379
5377
  if (key in target && !(key in Object.prototype)) {
5380
5378
  target[key] = val;
5381
5379
  return val;
5382
5380
  }
5383
- const ob = target.__ob__;
5384
5381
  if (target._isVue || (ob && ob.vmCount)) {
5385
5382
  process.env.NODE_ENV !== 'production' &&
5386
5383
  warn$3('Avoid adding reactive properties to a Vue instance or its root $data ' +
@@ -5391,7 +5388,7 @@ function set(target, key, val) {
5391
5388
  target[key] = val;
5392
5389
  return val;
5393
5390
  }
5394
- defineReactive(ob.value, key, val);
5391
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
5395
5392
  if (process.env.NODE_ENV !== 'production') {
5396
5393
  ob.dep.notify({
5397
5394
  type: "add" /* TriggerOpTypes.ADD */,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/compiler-sfc",
3
- "version": "2.7.2",
3
+ "version": "2.7.3",
4
4
  "description": "compiler-sfc for Vue 2",
5
5
  "main": "dist/compiler-sfc.js",
6
6
  "types": "dist/compiler-sfc.d.ts",