@lwc/engine-core 8.1.0-alpha.5 → 8.1.1

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.
package/dist/index.cjs.js CHANGED
@@ -293,6 +293,26 @@ function shouldBeFormAssociated(Ctor) {
293
293
  const reactiveObserversToVMs = new WeakMap();
294
294
  const targetsToPropertyKeys = new WeakMap();
295
295
  let mutationLogs = [];
296
+ // Create a human-readable member access notation like `obj.foo` or `arr[1]`,
297
+ // handling edge cases like `obj[Symbol("bar")]` and `obj["spaces here"]`
298
+ function toPrettyMemberNotation(parent, child) {
299
+ if (shared.isUndefined(parent)) {
300
+ // Bare prop, just stringify the child
301
+ return shared.toString(child);
302
+ }
303
+ else if (!shared.isString(child)) {
304
+ // Symbol/number, e.g. `obj[Symbol("foo")]` or `obj[1234]`
305
+ return `${shared.toString(parent)}[${shared.toString(child)}]`;
306
+ }
307
+ else if (/^\w+$/.test(child)) {
308
+ // Dot-notation-safe string, e.g. `obj.foo`
309
+ return `${shared.toString(parent)}.${child}`;
310
+ }
311
+ else {
312
+ // Bracket-notation-requiring string, e.g. `obj["prop with spaces"]`
313
+ return `${shared.toString(parent)}[${JSON.stringify(child)}]`;
314
+ }
315
+ }
296
316
  /**
297
317
  * Flush all the logs we've written so far and return the current logs.
298
318
  */
@@ -323,23 +343,7 @@ function logMutation(reactiveObserver, target, key) {
323
343
  }
324
344
  }
325
345
  else {
326
- const stringKey = shared.toString(key);
327
- let prop;
328
- if (shared.isUndefined(parentKey)) {
329
- prop = stringKey;
330
- }
331
- else if (!shared.isString(key)) {
332
- // symbol/number, e.g. `obj[Symbol("foo")]` or `obj[1234]`
333
- prop = `${shared.toString(parentKey)}[${stringKey}]`;
334
- }
335
- else if (/^\w+$/.test(stringKey)) {
336
- // Human-readable prop like `items[0].name` on a deep object/array
337
- prop = `${shared.toString(parentKey)}.${stringKey}`;
338
- }
339
- else {
340
- // e.g. `obj["prop with spaces"]`
341
- prop = `${shared.toString(parentKey)}[${JSON.stringify(stringKey)}]`;
342
- }
346
+ const prop = toPrettyMemberNotation(parentKey, key);
343
347
  shared.ArrayPush.call(mutationLogs, { vm, prop });
344
348
  }
345
349
  }
@@ -377,7 +381,7 @@ function trackTargetForMutationLogging(key, target) {
377
381
  // Deeply traverse arrays and objects to track every object within
378
382
  if (shared.isArray(target)) {
379
383
  for (let i = 0; i < target.length; i++) {
380
- trackTargetForMutationLogging(`${shared.toString(key)}[${i}]`, target[i]);
384
+ trackTargetForMutationLogging(toPrettyMemberNotation(key, i), target[i]);
381
385
  }
382
386
  }
383
387
  else {
@@ -386,10 +390,10 @@ function trackTargetForMutationLogging(key, target) {
386
390
  // https://github.com/salesforce/observable-membrane/blob/b85417f/src/base-handler.ts#L142-L143
387
391
  // Note this code path is very hot, hence doing two separate for-loops rather than creating a new array.
388
392
  for (const prop of shared.getOwnPropertyNames(target)) {
389
- trackTargetForMutationLogging(`${shared.toString(key)}.${shared.toString(prop)}`, target[prop]);
393
+ trackTargetForMutationLogging(toPrettyMemberNotation(key, prop), target[prop]);
390
394
  }
391
395
  for (const prop of shared.getOwnPropertySymbols(target)) {
392
- trackTargetForMutationLogging(`${shared.toString(key)}[${shared.toString(prop)}]`, target[prop]);
396
+ trackTargetForMutationLogging(toPrettyMemberNotation(key, prop), target[prop]);
393
397
  }
394
398
  }
395
399
  }
@@ -8412,5 +8416,5 @@ exports.swapTemplate = swapTemplate;
8412
8416
  exports.track = track;
8413
8417
  exports.unwrap = unwrap;
8414
8418
  exports.wire = wire;
8415
- /** version: 8.1.0-alpha.5 */
8419
+ /** version: 8.1.1 */
8416
8420
  //# sourceMappingURL=index.cjs.js.map