@rohal12/spindle 0.64.28 → 0.64.29

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.
@@ -6538,17 +6538,21 @@ var isArrayIndex = (key) => /^(?:0|[1-9]\d*)$/.test(key);
6538
6538
  var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
6539
6539
  /** `ns[key]` if `ns` holds it as an own property, else undefined. */
6540
6540
  var ownValue = (ns, key) => ns && hasOwn(ns, key) ? ns[key] : void 0;
6541
- /**
6542
- * Set an own enumerable property. A "__proto__" key is defined as an own
6543
- * property (as JSON.parse does) instead of replacing the prototype.
6544
- */
6545
- function setOwn(target, key, value) {
6546
- if (key === "__proto__") Object.defineProperty(target, key, {
6541
+ /** Define an own data field without invoking an inherited accessor. */
6542
+ function defineData(target, key, value) {
6543
+ Object.defineProperty(target, key, {
6547
6544
  value,
6548
6545
  enumerable: true,
6549
6546
  writable: true,
6550
6547
  configurable: true
6551
6548
  });
6549
+ }
6550
+ /**
6551
+ * Set an own enumerable property. A "__proto__" key is defined as an own
6552
+ * property (as JSON.parse does) instead of replacing the prototype.
6553
+ */
6554
+ function setOwn(target, key, value) {
6555
+ if (key === "__proto__") defineData(target, key, value);
6552
6556
  else target[key] = value;
6553
6557
  }
6554
6558
  /**
@@ -7662,14 +7666,6 @@ var isObject = (v) => typeof v === "object" && v !== null;
7662
7666
  /** Whether `v` is a plain object (as devalue revives one). */
7663
7667
  var isPlainData = (v) => isObject(v) && Object.getPrototypeOf(v) === Object.prototype;
7664
7668
  var malformedClass = (name) => /* @__PURE__ */ new TypeError(`spindle: Malformed data for class "${name}"`);
7665
- var defineData = (target, key, value) => {
7666
- Object.defineProperty(target, key, {
7667
- value,
7668
- enumerable: true,
7669
- writable: true,
7670
- configurable: true
7671
- });
7672
- };
7673
7669
  /**
7674
7670
  * A reducer extracts string keys, so devalue never sees the symbol keys of
7675
7671
  * the original object: refuse them here, as it does for a plain object.
@@ -8011,12 +8007,7 @@ var builtinName = atomicName;
8011
8007
  */
8012
8008
  function shallowCopy(value) {
8013
8009
  const copy = Array.isArray(value) ? new Array(value.length) : Object.create(Object.getPrototypeOf(value));
8014
- for (const key of Object.keys(value)) Object.defineProperty(copy, key, {
8015
- value: value[key],
8016
- enumerable: true,
8017
- writable: true,
8018
- configurable: true
8019
- });
8010
+ for (const key of Object.keys(value)) defineData(copy, key, value[key]);
8020
8011
  return copy;
8021
8012
  }
8022
8013
  /**
@@ -8129,7 +8120,7 @@ function builtinLike(obj, empty, made, value) {
8129
8120
  made(empty);
8130
8121
  if (registeredClassName(obj) === void 0) return empty;
8131
8122
  Object.setPrototypeOf(empty, Object.getPrototypeOf(obj));
8132
- for (const key of extraKeys(obj)) setOwn(empty, key, value(key));
8123
+ for (const key of extraKeys(obj)) defineData(empty, key, value(key));
8133
8124
  return empty;
8134
8125
  }
8135
8126
  function deepClone(value, options = {}) {
@@ -8144,10 +8135,10 @@ function deepClone(value, options = {}) {
8144
8135
  * save refuses them, which a copy must not hide.
8145
8136
  */
8146
8137
  function copyKeys(obj, copy) {
8147
- for (const key of Object.keys(obj)) setOwn(copy, key, clone(obj[key]));
8138
+ for (const key of Object.keys(obj)) defineData(copy, key, clone(obj[key]));
8148
8139
  for (const sym of Object.getOwnPropertySymbols(obj)) {
8149
8140
  if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) continue;
8150
- copy[sym] = clone(obj[sym]);
8141
+ defineData(copy, sym, clone(obj[sym]));
8151
8142
  }
8152
8143
  return copy;
8153
8144
  }
@@ -8195,7 +8186,7 @@ function deepClone(value, options = {}) {
8195
8186
  if (seen.has(obj)) return seen.get(obj);
8196
8187
  if (Array.isArray(val)) {
8197
8188
  const arr = builtin(obj, new Array(val.length));
8198
- for (const key of arrayIndices(val)) arr[Number(key)] = clone(val[Number(key)]);
8189
+ for (const key of arrayIndices(val)) defineData(arr, key, clone(val[Number(key)]));
8199
8190
  return arr;
8200
8191
  }
8201
8192
  if (val instanceof Map) {
@@ -8321,13 +8312,13 @@ function shareEqual(prev, curr) {
8321
8312
  }
8322
8313
  if (Array.isArray(c) && Array.isArray(p)) {
8323
8314
  const out = collection(new Array(c.length));
8324
- for (const key of arrayIndices(c)) out[Number(key)] = shareKey(key);
8315
+ for (const key of arrayIndices(c)) defineData(out, key, shareKey(key));
8325
8316
  return out;
8326
8317
  }
8327
8318
  if (mergesWith(p, c, false)) {
8328
8319
  const out = Object.create(Object.getPrototypeOf(c));
8329
8320
  done.set(c, out);
8330
- for (const key of Object.keys(cr)) setOwn(out, key, shareKey(key));
8321
+ for (const key of Object.keys(cr)) defineData(out, key, shareKey(key));
8331
8322
  return out;
8332
8323
  }
8333
8324
  return fresh(c);
@@ -8925,6 +8916,13 @@ function clonerFor(target, paths) {
8925
8916
  settle
8926
8917
  });
8927
8918
  }
8919
+ /** Adopt setter inputs into a draft, retaining references to owned state. */
8920
+ function adoptStateValues(target) {
8921
+ const held = locateObjects(namespacesOf(useStoryStore.getState()), []);
8922
+ const scope = getActiveMutationScope();
8923
+ if (scope) for (const [value, path] of locateObjects(scope, [])) held.set(value, path);
8924
+ return clonerFor(target, held);
8925
+ }
8928
8926
  /** One cloner per target copy, made when first used. */
8929
8927
  var clonersFor = (paths) => {
8930
8928
  const made = /* @__PURE__ */ new Map();
@@ -14549,6 +14547,11 @@ function readWholeQuoted(src) {
14549
14547
  const quoted = readQuoted(src, 0);
14550
14548
  return quoted && quoted.end === src.length ? quoted.value : null;
14551
14549
  }
14550
+ /** A dialog body's passage name, optionally enclosed in matching quotes. */
14551
+ function readPassageBody(src) {
14552
+ const name = src.trim();
14553
+ return readWholeQuoted(name) ?? name;
14554
+ }
14552
14555
  /**
14553
14556
  * Strip an optional quote from each end of an unquoted-or-loosely-quoted
14554
14557
  * argument (`"Red`, `Red'`), leaving at least one character. This is the
@@ -15332,7 +15335,7 @@ function* codeAndText(src, tokens, parametersOf) {
15332
15335
  const written = text.trim();
15333
15336
  yield {
15334
15337
  kind: "passage",
15335
- name: written.replace(/^["']|["']$/g, ""),
15338
+ name: readPassageBody(written),
15336
15339
  offset: token.end + text.indexOf(written),
15337
15340
  length: written.length,
15338
15341
  macro: name,
@@ -21029,12 +21032,7 @@ var FOCUSABLE = [
21029
21032
  */
21030
21033
  function isAvailable(el) {
21031
21034
  if (!isRendered(el)) return false;
21032
- for (let at = el; at; at = composedParent(at)) {
21033
- if (at.hasAttribute("hidden") || at.hasAttribute("inert")) return false;
21034
- if (at.ownerDocument.defaultView?.getComputedStyle(at).display === "none") return false;
21035
- const parent = composedParent(at);
21036
- if (parent?.localName === "details" && !parent.hasAttribute("open") && at !== Array.from(parent.children).find((child) => child.localName === "summary")) return false;
21037
- }
21035
+ for (let at = el; at; at = composedParent(at)) if (at.hasAttribute("inert")) return false;
21038
21036
  return !el.matches(":disabled");
21039
21037
  }
21040
21038
  /** The `tabindex` of `el` as an integer, or null when absent or invalid. */
@@ -22767,10 +22765,13 @@ function warnIfUndeclared(isTransient, key) {
22767
22765
  warnedUndeclared.add(label);
22768
22766
  console.warn(`spindle: Story.set() wrote ${label}, which is not declared in ${isTransient ? "StoryTransients" : "StoryVariables"}. Passages cannot reference it; check the name or declare it.`);
22769
22767
  }
22770
- /** Set a single variable on an Immer draft, resolving dot-paths if present. */
22771
- function setOne(draft, name, value) {
22772
- const { isTransient, key } = parseName(name);
22773
- setByPath(isTransient ? draft.transient : draft.variables, key.split("."), value);
22768
+ /** Adopt the whole batch before writes can replace state-owned inputs. */
22769
+ function setEntries(draft, entries, adopt) {
22770
+ const adopted = entries.map(([name, value]) => [name, adopt(value)]);
22771
+ for (const [name, value] of adopted) {
22772
+ const { isTransient, key } = parseName(name);
22773
+ setByPath(isTransient ? draft.transient : draft.variables, key.split("."), value);
22774
+ }
22774
22775
  }
22775
22776
  /**
22776
22777
  * The history index `index` names (the current moment's when left out), or
@@ -22808,12 +22809,13 @@ function createStoryAPI() {
22808
22809
  }
22809
22810
  if (entries.some(([k]) => k.includes("."))) {
22810
22811
  mutateState((work, adopt) => {
22811
- for (const [k, v] of entries) setOne(work, k, adopt(v));
22812
+ setEntries(work, entries, adopt);
22812
22813
  });
22813
22814
  return;
22814
22815
  }
22815
22816
  useStoryStore.getState().updateVariables((draft) => {
22816
- for (const [k, v] of entries) setOne(draft, k, v);
22817
+ const adopt = adoptStateValues(draft);
22818
+ setEntries(draft, entries, adopt);
22817
22819
  });
22818
22820
  },
22819
22821
  goto: storeAction("navigate"),
@@ -26139,7 +26141,7 @@ defineMacro({
26139
26141
  const [open, setOpen] = ctx.hooks.useState(false);
26140
26142
  const { noclose } = ctx.args;
26141
26143
  const label = ctx.resolve(ctx.args.label ?? "") ?? "";
26142
- const passageName = ctx.collectText(children).trim().replace(/^["']|["']$/g, "");
26144
+ const passageName = readPassageBody(ctx.collectText(children));
26143
26145
  const openDialog = () => setOpen(true);
26144
26146
  const action = useControlAction({
26145
26147
  type: "open-dialog",
@@ -10975,6 +10975,11 @@ function readWholeQuoted(src) {
10975
10975
  const quoted = readQuoted(src, 0);
10976
10976
  return quoted && quoted.end === src.length ? quoted.value : null;
10977
10977
  }
10978
+ /** A dialog body's passage name, optionally enclosed in matching quotes. */
10979
+ function readPassageBody(src) {
10980
+ const name = src.trim();
10981
+ return readWholeQuoted(name) ?? name;
10982
+ }
10978
10983
  /**
10979
10984
  * Strip an optional quote from each end of an unquoted-or-loosely-quoted
10980
10985
  * argument (`"Red`, `Red'`), leaving at least one character. This is the
@@ -11760,7 +11765,7 @@ function* codeAndText(src, tokens, parametersOf) {
11760
11765
  const written = text.trim();
11761
11766
  yield {
11762
11767
  kind: "passage",
11763
- name: written.replace(/^["']|["']$/g, ""),
11768
+ name: readPassageBody(written),
11764
11769
  offset: token.end + text.indexOf(written),
11765
11770
  length: written.length,
11766
11771
  macro: name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.64.28",
3
+ "version": "0.64.29",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -1,7 +1,7 @@
1
1
  // Class registry for preserving class instances across clone/save/load cycles.
2
2
 
3
3
  import { parse, stringify } from 'devalue';
4
- import { hasOwn } from './utils/namespace';
4
+ import { defineData, hasOwn } from './utils/namespace';
5
5
  import {
6
6
  arrayIndices,
7
7
  extraKeys,
@@ -155,16 +155,6 @@ const isPlainData = (v: unknown): v is Record<string, unknown> =>
155
155
  const malformedClass = (name: string): TypeError =>
156
156
  new TypeError(`spindle: Malformed data for class "${name}"`);
157
157
 
158
- const defineData = (target: object, key: string, value: unknown): void => {
159
- // Define, so that a "__proto__" key stays a key (devalue refuses it)
160
- Object.defineProperty(target, key, {
161
- value,
162
- enumerable: true,
163
- writable: true,
164
- configurable: true,
165
- });
166
- };
167
-
168
158
  /**
169
159
  * A reducer extracts string keys, so devalue never sees the symbol keys of
170
160
  * the original object: refuse them here, as it does for a plain object.
package/src/code-check.ts CHANGED
@@ -55,7 +55,7 @@ import {
55
55
  type PassageTarget,
56
56
  } from './components/macros/macro-args';
57
57
  import { subMacroParameters } from './components/macros/option-utils';
58
- import { splitArgSpans } from './components/macros/arg-utils';
58
+ import { readPassageBody, splitArgSpans } from './components/macros/arg-utils';
59
59
  import { effectiveNamedDefinitions, NameMap } from './utils/macro-names';
60
60
  import { hasOwn } from './utils/namespace';
61
61
  import { isBuiltinBlockMacro, isRawMacro } from './markup/ast';
@@ -532,7 +532,7 @@ export function* codeAndText(
532
532
  const written = text.trim();
533
533
  yield {
534
534
  kind: 'passage',
535
- name: written.replace(/^["']|["']$/g, ''),
535
+ name: readPassageBody(written),
536
536
  offset: token.end + text.indexOf(written),
537
537
  length: written.length,
538
538
  macro: name,
@@ -1,6 +1,7 @@
1
1
  import { renderActionButton, useControlAction } from '../../hooks/use-action';
2
2
  import { defineMacro } from '../../define-macro';
3
3
  import { PassageDialog } from '../PassageDialog';
4
+ import { readPassageBody } from './arg-utils';
4
5
 
5
6
  defineMacro({
6
7
  name: 'dialog',
@@ -15,10 +16,7 @@ defineMacro({
15
16
 
16
17
  const { noclose } = ctx.args;
17
18
  const label = ctx.resolve!(ctx.args.label ?? '') ?? '';
18
- const passageName = ctx
19
- .collectText(children)
20
- .trim()
21
- .replace(/^["']|["']$/g, '');
19
+ const passageName = readPassageBody(ctx.collectText(children));
22
20
  const openDialog = () => setOpen(true);
23
21
 
24
22
  // Its own type: the menubar's Saves and Settings are `dialog` (#540)
@@ -74,6 +74,12 @@ export function readWholeQuoted(src: string): string | null {
74
74
  return quoted && quoted.end === src.length ? quoted.value : null;
75
75
  }
76
76
 
77
+ /** A dialog body's passage name, optionally enclosed in matching quotes. */
78
+ export function readPassageBody(src: string): string {
79
+ const name = src.trim();
80
+ return readWholeQuoted(name) ?? name;
81
+ }
82
+
77
83
  /**
78
84
  * Strip an optional quote from each end of an unquoted-or-loosely-quoted
79
85
  * argument (`"Red`, `Red'`), leaving at least one character. This is the
@@ -116,6 +116,16 @@ function clonerFor(
116
116
  return (value) => deepClone(value, { keepUnregistered: true, seen, settle });
117
117
  }
118
118
 
119
+ /** Adopt setter inputs into a draft, retaining references to owned state. */
120
+ export function adoptStateValues(target: VariableNamespaces): Cloner {
121
+ const held = locateObjects(namespacesOf(useStoryStore.getState()), []);
122
+ const scope = getActiveMutationScope();
123
+ if (scope) {
124
+ for (const [value, path] of locateObjects(scope, [])) held.set(value, path);
125
+ }
126
+ return clonerFor(target, held);
127
+ }
128
+
119
129
  /** One cloner per target copy, made when first used. */
120
130
  const clonersFor = (
121
131
  paths?: (target: object) => ReadonlyMap<object, ObjectPath>,
@@ -28,21 +28,10 @@ const FOCUSABLE = [
28
28
  */
29
29
  function isAvailable(el: HTMLElement): boolean {
30
30
  if (!isRendered(el)) return false;
31
- // Visibility and inertness of a host apply to its whole shadow tree too.
31
+ // Rendered visibility includes CSS overrides of hidden, until-found
32
+ // contents, closed details and shadow trees. Inertness is independent.
32
33
  for (let at: Element | null = el; at; at = composedParent(at)) {
33
- if (at.hasAttribute('hidden') || at.hasAttribute('inert')) return false;
34
- if (at.ownerDocument.defaultView?.getComputedStyle(at).display === 'none')
35
- return false;
36
- const parent = composedParent(at);
37
- if (
38
- parent?.localName === 'details' &&
39
- !parent.hasAttribute('open') &&
40
- at !==
41
- Array.from(parent.children).find(
42
- (child) => child.localName === 'summary',
43
- )
44
- )
45
- return false;
34
+ if (at.hasAttribute('inert')) return false;
46
35
  }
47
36
  // Also covers controls disabled by a <fieldset disabled> ancestor
48
37
  return !el.matches(':disabled');
package/src/story-api.ts CHANGED
@@ -26,6 +26,7 @@ import { registerClass } from './class-registry';
26
26
  import {
27
27
  frozenCopy,
28
28
  readOnlyValue,
29
+ adoptStateValues,
29
30
  getActiveMutationScope,
30
31
  mutateState,
31
32
  } from './execute-mutation';
@@ -282,12 +283,18 @@ function warnIfUndeclared(isTransient: boolean, key: string): void {
282
283
  );
283
284
  }
284
285
 
285
- /** Set a single variable on an Immer draft, resolving dot-paths if present. */
286
- function setOne(draft: VariableNamespaces, name: string, value: unknown): void {
287
- const { isTransient, key } = parseName(name);
288
- const namespace = isTransient ? draft.transient : draft.variables;
289
-
290
- setByPath(namespace, key.split('.'), value);
286
+ /** Adopt the whole batch before writes can replace state-owned inputs. */
287
+ function setEntries(
288
+ draft: VariableNamespaces,
289
+ entries: readonly [string, unknown][],
290
+ adopt: (value: unknown) => unknown,
291
+ ): void {
292
+ const adopted = entries.map(([name, value]) => [name, adopt(value)] as const);
293
+ for (const [name, value] of adopted) {
294
+ const { isTransient, key } = parseName(name);
295
+ const namespace = isTransient ? draft.transient : draft.variables;
296
+ setByPath(namespace, key.split('.'), value);
297
+ }
291
298
  }
292
299
 
293
300
  /**
@@ -345,22 +352,20 @@ function createStoryAPI(): StoryAPI {
345
352
  warnIfUndeclared(isTransient, key);
346
353
  if (!isTransient) recordHookWrite(key.split('.'));
347
354
  }
348
- // One store update for all keys, so watchers see them together. Made
349
- // while mutation code runs ({do}, ctx.mutate, watcher run actions), it
350
- // follows the code's own pending writes (program order, #215): see
351
- // routeStoreUpdate.
355
+ // One store update for all keys, in program order with any running
356
+ // mutation. Nested writes use the mutation merge to preserve aliases.
352
357
  if (entries.some(([k]) => k.includes('.'))) {
353
- // A write below a variable goes through the commit mutation code
354
- // uses (nested in the running code, if any: it continues from the
355
- // code's pending writes, and they are committed first): an update of a draft would give the written path new
356
- // objects and leave the other references to the old ones (#295).
357
358
  mutateState((work, adopt) => {
358
- for (const [k, v] of entries) setOne(work, k, adopt(v));
359
+ setEntries(work, entries, adopt);
359
360
  });
360
361
  return;
361
362
  }
362
363
  useStoryStore.getState().updateVariables((draft) => {
363
- for (const [k, v] of entries) setOne(draft, k, v);
364
+ // One adopter for the batch keeps shared references and cycles,
365
+ // including references to state already owned by the running code.
366
+ // Freezing caller inputs alone cannot protect mutable internal slots.
367
+ const adopt = adoptStateValues(draft);
368
+ setEntries(draft, entries, adopt);
364
369
  });
365
370
  },
366
371
 
package/src/structural.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  // Temporal values, with shared references and cycles.
11
11
 
12
12
  import { registeredClassName } from './class-registry';
13
- import { hasOwn, setOwn } from './utils/namespace';
13
+ import { defineData, hasOwn } from './utils/namespace';
14
14
  import { deleteByPath, getByPath, setByPath } from './utils/object-path';
15
15
  import {
16
16
  ERROR_HIDDEN_KEYS,
@@ -54,7 +54,7 @@ function builtinLike<C extends object>(
54
54
  made(empty);
55
55
  if (registeredClassName(obj) === undefined) return empty;
56
56
  Object.setPrototypeOf(empty, Object.getPrototypeOf(obj) as object);
57
- for (const key of extraKeys(obj)) setOwn(empty, key, value(key));
57
+ for (const key of extraKeys(obj)) defineData(empty, key, value(key));
58
58
  return empty;
59
59
  }
60
60
 
@@ -102,13 +102,11 @@ export function deepClone<T>(value: T, options: DeepCloneOptions = {}): T {
102
102
  */
103
103
  function copyKeys(obj: object, copy: object): object {
104
104
  for (const key of Object.keys(obj)) {
105
- setOwn(copy, key, clone((obj as Record<string, unknown>)[key]));
105
+ defineData(copy, key, clone((obj as Record<string, unknown>)[key]));
106
106
  }
107
107
  for (const sym of Object.getOwnPropertySymbols(obj)) {
108
108
  if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) continue;
109
- (copy as Record<symbol, unknown>)[sym] = clone(
110
- (obj as Record<symbol, unknown>)[sym],
111
- );
109
+ defineData(copy, sym, clone((obj as Record<symbol, unknown>)[sym]));
112
110
  }
113
111
  return copy;
114
112
  }
@@ -184,7 +182,7 @@ export function deepClone<T>(value: T, options: DeepCloneOptions = {}): T {
184
182
  // Holes stay holes
185
183
  const arr = builtin(obj, new Array(val.length) as unknown[]);
186
184
  for (const key of arrayIndices(val))
187
- arr[Number(key)] = clone(val[Number(key)]);
185
+ defineData(arr, key, clone(val[Number(key)]));
188
186
  return arr;
189
187
  }
190
188
 
@@ -360,13 +358,13 @@ export function shareEqual<T>(prev: unknown, curr: T): T {
360
358
  }
361
359
  if (Array.isArray(c) && Array.isArray(p)) {
362
360
  const out = collection(new Array(c.length) as unknown[]);
363
- for (const key of arrayIndices(c)) out[Number(key)] = shareKey(key);
361
+ for (const key of arrayIndices(c)) defineData(out, key, shareKey(key));
364
362
  return out;
365
363
  }
366
364
  if (mergesWith(p, c, false)) {
367
365
  const out = Object.create(Object.getPrototypeOf(c) as object | null);
368
366
  done.set(c, out);
369
- for (const key of Object.keys(cr)) setOwn(out, key, shareKey(key));
367
+ for (const key of Object.keys(cr)) defineData(out, key, shareKey(key));
370
368
  return out;
371
369
  }
372
370
  return fresh(c);
@@ -52,18 +52,27 @@ export const ownValue = (
52
52
  key: string,
53
53
  ): unknown => (ns && hasOwn(ns, key) ? (ns as Namespace)[key] : undefined);
54
54
 
55
+ /** Define an own data field without invoking an inherited accessor. */
56
+ export function defineData(
57
+ target: object,
58
+ key: PropertyKey,
59
+ value: unknown,
60
+ ): void {
61
+ Object.defineProperty(target, key, {
62
+ value,
63
+ enumerable: true,
64
+ writable: true,
65
+ configurable: true,
66
+ });
67
+ }
68
+
55
69
  /**
56
70
  * Set an own enumerable property. A "__proto__" key is defined as an own
57
71
  * property (as JSON.parse does) instead of replacing the prototype.
58
72
  */
59
73
  export function setOwn(target: object, key: string, value: unknown): void {
60
74
  if (key === '__proto__') {
61
- Object.defineProperty(target, key, {
62
- value,
63
- enumerable: true,
64
- writable: true,
65
- configurable: true,
66
- });
75
+ defineData(target, key, value);
67
76
  } else {
68
77
  (target as Record<string, unknown>)[key] = value;
69
78
  }
@@ -1,6 +1,6 @@
1
1
  import { current as draftState, isDraft, original } from 'immer';
2
2
  import { registeredClassName } from '../class-registry';
3
- import { hasOwn, isArrayIndex } from './namespace';
3
+ import { defineData, hasOwn, isArrayIndex } from './namespace';
4
4
  import { atomicName } from './value-kinds';
5
5
 
6
6
  /**
@@ -56,12 +56,7 @@ export function shallowCopy(value: object): Record<string, unknown> {
56
56
  // Define rather than assign (Object.assign), so that a "__proto__" key
57
57
  // stays a key instead of replacing the copy's prototype
58
58
  for (const key of Object.keys(value)) {
59
- Object.defineProperty(copy, key, {
60
- value: (value as Record<string, unknown>)[key],
61
- enumerable: true,
62
- writable: true,
63
- configurable: true,
64
- });
59
+ defineData(copy, key, (value as Record<string, unknown>)[key]);
65
60
  }
66
61
  return copy as Record<string, unknown>;
67
62
  }