msgpackr 1.7.0 → 1.7.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.js CHANGED
@@ -188,7 +188,7 @@
188
188
 
189
189
  if (position == srcEnd) {
190
190
  // finished reading this source, cleanup references
191
- if (currentStructures?.restoreStructures)
191
+ if (currentStructures && currentStructures.restoreStructures)
192
192
  restoreStructures();
193
193
  currentStructures = null;
194
194
  src = null;
@@ -203,7 +203,7 @@
203
203
  // else more to read, but we are reading sequentially, so don't clear source yet
204
204
  return result
205
205
  } catch(error) {
206
- if (currentStructures?.restoreStructures)
206
+ if (currentStructures && currentStructures.restoreStructures)
207
207
  restoreStructures();
208
208
  clearSource();
209
209
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
@@ -1186,12 +1186,11 @@
1186
1186
  writeStruct(value);
1187
1187
  else
1188
1188
  pack(value);
1189
- if (bundledStrings$1) {
1190
- writeBundles(start, pack);
1191
- }
1192
- packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1193
1189
  if (referenceMap && referenceMap.idsToInsert) {
1194
- position$1 += referenceMap.idsToInsert.length * 6;
1190
+ let incrementPosition = referenceMap.idsToInsert.length * 6;
1191
+ if (bundledStrings$1)
1192
+ writeBundles(start, pack, incrementPosition);
1193
+ position$1 += incrementPosition;
1195
1194
  if (position$1 > safeEnd)
1196
1195
  makeRoom(position$1);
1197
1196
  packr.offset = position$1;
@@ -1199,6 +1198,9 @@
1199
1198
  referenceMap = null;
1200
1199
  return serialized
1201
1200
  }
1201
+ if (bundledStrings$1)
1202
+ writeBundles(start, pack, 0);
1203
+ packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1202
1204
  if (encodeOptions & REUSE_BUFFER_MODE) {
1203
1205
  target.start = start;
1204
1206
  target.end = position$1;
@@ -1966,9 +1968,9 @@
1966
1968
  return serialized
1967
1969
  }
1968
1970
 
1969
- function writeBundles(start, pack) {
1971
+ function writeBundles(start, pack, incrementPosition) {
1970
1972
  if (bundledStrings$1.length > 0) {
1971
- targetView.setUint32(bundledStrings$1.position + start, position$1 - bundledStrings$1.position - start);
1973
+ targetView.setUint32(bundledStrings$1.position + start, position$1 + incrementPosition - bundledStrings$1.position - start);
1972
1974
  let writeStrings = bundledStrings$1;
1973
1975
  bundledStrings$1 = null;
1974
1976
  pack(writeStrings[0]);