msgpackr 1.11.5 → 1.11.7

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/test.js CHANGED
@@ -1338,9 +1338,13 @@
1338
1338
  hasSharedUpdate = false;
1339
1339
  let encodingError;
1340
1340
  try {
1341
- if (packr.randomAccessStructure && value && value.constructor && value.constructor === Object)
1342
- writeStruct(value);
1343
- else
1341
+ if (packr.randomAccessStructure && value && value.constructor) {
1342
+ if (value.constructor === Object) writeStruct(value); // simple object
1343
+ else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1344
+ // allow user classes, if they don't need special handling (but do use toJSON if available)
1345
+ writeStruct(value.toJSON ? value.toJSON() : value);
1346
+ } else pack(value);
1347
+ } else
1344
1348
  pack(value);
1345
1349
  let lastBundle = bundledStrings;
1346
1350
  if (bundledStrings)