@pierre/diffs 1.6.1 → 1.6.2

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.
@@ -1193,17 +1193,18 @@ function processLine(node, line, state) {
1193
1193
  }
1194
1194
  //#endregion
1195
1195
  //#region src/utils/setDeferredArrayItem.ts
1196
- function setDeferredArrayItem(array, index, create) {
1196
+ function setDeferredArrayItem(array, index, create, { retain = true } = {}) {
1197
1197
  let initialized = false;
1198
1198
  let cached;
1199
1199
  Object.defineProperty(array, index, {
1200
1200
  configurable: true,
1201
1201
  enumerable: true,
1202
1202
  get() {
1203
- if (!initialized) {
1204
- cached = create();
1205
- initialized = true;
1206
- }
1203
+ if (initialized) return cached;
1204
+ const value = create();
1205
+ if (!retain) return value;
1206
+ cached = value;
1207
+ initialized = true;
1207
1208
  if (Object.getOwnPropertyDescriptor(array, index)?.configurable === true) Object.defineProperty(array, index, {
1208
1209
  configurable: true,
1209
1210
  enumerable: true,