@optique/core 1.0.0-dev.1868 → 1.0.0-dev.1872

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.
@@ -157,6 +157,16 @@ function tryCloneRegExpSubclass(source) {
157
157
  return void 0;
158
158
  }
159
159
  }
160
+ function tryCloneArraySubclass(source) {
161
+ const cloneConstructor = resolveCloneConstructor(source);
162
+ if (cloneConstructor == null) return void 0;
163
+ try {
164
+ const cloned = Reflect.apply(Array.from, cloneConstructor, [source]);
165
+ return Array.isArray(cloned) ? cloned : void 0;
166
+ } catch {
167
+ return void 0;
168
+ }
169
+ }
160
170
  function tryCloneURLSearchParamsSubclass(source) {
161
171
  const cloneConstructor = resolveCloneConstructor(source);
162
172
  if (cloneConstructor == null) return void 0;
@@ -251,7 +261,8 @@ function cloneRegExpShape(source) {
251
261
  }
252
262
  function createProtectedObjectView(target, context) {
253
263
  if (Array.isArray(target)) {
254
- const view$1 = Object.setPrototypeOf([], Object.getPrototypeOf(target));
264
+ const targetPrototype = Object.getPrototypeOf(target);
265
+ const view$1 = targetPrototype === Array.prototype || targetPrototype === null ? Object.setPrototypeOf([], targetPrototype) : tryCloneArraySubclass(target) ?? [];
255
266
  view$1.length = target.length;
256
267
  registerProtectedAnnotationView(context, target, view$1);
257
268
  for (const key of Reflect.ownKeys(target)) {
@@ -596,21 +607,23 @@ function injectAnnotationsWithContext(state, annotations, context) {
596
607
  return cloned$1;
597
608
  }
598
609
  if (isInjectedAnnotationWrapper(state)) {
599
- state[annotationKey] = protectedAnnotations;
600
- return state;
610
+ const cloned$1 = Object.create(Object.getPrototypeOf(state), Object.getOwnPropertyDescriptors(state));
611
+ cloned$1[annotationKey] = protectedAnnotations;
612
+ injectedAnnotationWrappers.add(cloned$1);
613
+ return cloned$1;
601
614
  }
602
615
  if (state instanceof Date) {
603
- const cloned$1 = new Date(state.getTime());
616
+ const cloned$1 = tryCloneDateSubclass(state) ?? new Date(state.getTime());
604
617
  cloned$1[annotationKey] = protectedAnnotations;
605
618
  return cloned$1;
606
619
  }
607
620
  if (state instanceof Map) {
608
- const cloned$1 = new Map(state);
621
+ const cloned$1 = tryCloneMapSubclass(state, state) ?? new Map(state);
609
622
  cloned$1[annotationKey] = protectedAnnotations;
610
623
  return cloned$1;
611
624
  }
612
625
  if (state instanceof Set) {
613
- const cloned$1 = new Set(state);
626
+ const cloned$1 = tryCloneSetSubclass(state, state) ?? new Set(state);
614
627
  cloned$1[annotationKey] = protectedAnnotations;
615
628
  return cloned$1;
616
629
  }
@@ -702,17 +715,17 @@ function inheritAnnotations(source, target) {
702
715
  return cloned$1;
703
716
  }
704
717
  if (target instanceof Date) {
705
- const cloned$1 = new Date(target.getTime());
718
+ const cloned$1 = tryCloneDateSubclass(target) ?? new Date(target.getTime());
706
719
  cloned$1[annotationKey] = annotations;
707
720
  return cloned$1;
708
721
  }
709
722
  if (target instanceof Map) {
710
- const cloned$1 = new Map(target);
723
+ const cloned$1 = tryCloneMapSubclass(target, target) ?? new Map(target);
711
724
  cloned$1[annotationKey] = annotations;
712
725
  return cloned$1;
713
726
  }
714
727
  if (target instanceof Set) {
715
- const cloned$1 = new Set(target);
728
+ const cloned$1 = tryCloneSetSubclass(target, target) ?? new Set(target);
716
729
  cloned$1[annotationKey] = annotations;
717
730
  return cloned$1;
718
731
  }
@@ -156,6 +156,16 @@ function tryCloneRegExpSubclass(source) {
156
156
  return void 0;
157
157
  }
158
158
  }
159
+ function tryCloneArraySubclass(source) {
160
+ const cloneConstructor = resolveCloneConstructor(source);
161
+ if (cloneConstructor == null) return void 0;
162
+ try {
163
+ const cloned = Reflect.apply(Array.from, cloneConstructor, [source]);
164
+ return Array.isArray(cloned) ? cloned : void 0;
165
+ } catch {
166
+ return void 0;
167
+ }
168
+ }
159
169
  function tryCloneURLSearchParamsSubclass(source) {
160
170
  const cloneConstructor = resolveCloneConstructor(source);
161
171
  if (cloneConstructor == null) return void 0;
@@ -250,7 +260,8 @@ function cloneRegExpShape(source) {
250
260
  }
251
261
  function createProtectedObjectView(target, context) {
252
262
  if (Array.isArray(target)) {
253
- const view$1 = Object.setPrototypeOf([], Object.getPrototypeOf(target));
263
+ const targetPrototype = Object.getPrototypeOf(target);
264
+ const view$1 = targetPrototype === Array.prototype || targetPrototype === null ? Object.setPrototypeOf([], targetPrototype) : tryCloneArraySubclass(target) ?? [];
254
265
  view$1.length = target.length;
255
266
  registerProtectedAnnotationView(context, target, view$1);
256
267
  for (const key of Reflect.ownKeys(target)) {
@@ -595,21 +606,23 @@ function injectAnnotationsWithContext(state, annotations, context) {
595
606
  return cloned$1;
596
607
  }
597
608
  if (isInjectedAnnotationWrapper(state)) {
598
- state[annotationKey] = protectedAnnotations;
599
- return state;
609
+ const cloned$1 = Object.create(Object.getPrototypeOf(state), Object.getOwnPropertyDescriptors(state));
610
+ cloned$1[annotationKey] = protectedAnnotations;
611
+ injectedAnnotationWrappers.add(cloned$1);
612
+ return cloned$1;
600
613
  }
601
614
  if (state instanceof Date) {
602
- const cloned$1 = new Date(state.getTime());
615
+ const cloned$1 = tryCloneDateSubclass(state) ?? new Date(state.getTime());
603
616
  cloned$1[annotationKey] = protectedAnnotations;
604
617
  return cloned$1;
605
618
  }
606
619
  if (state instanceof Map) {
607
- const cloned$1 = new Map(state);
620
+ const cloned$1 = tryCloneMapSubclass(state, state) ?? new Map(state);
608
621
  cloned$1[annotationKey] = protectedAnnotations;
609
622
  return cloned$1;
610
623
  }
611
624
  if (state instanceof Set) {
612
- const cloned$1 = new Set(state);
625
+ const cloned$1 = tryCloneSetSubclass(state, state) ?? new Set(state);
613
626
  cloned$1[annotationKey] = protectedAnnotations;
614
627
  return cloned$1;
615
628
  }
@@ -701,17 +714,17 @@ function inheritAnnotations(source, target) {
701
714
  return cloned$1;
702
715
  }
703
716
  if (target instanceof Date) {
704
- const cloned$1 = new Date(target.getTime());
717
+ const cloned$1 = tryCloneDateSubclass(target) ?? new Date(target.getTime());
705
718
  cloned$1[annotationKey] = annotations;
706
719
  return cloned$1;
707
720
  }
708
721
  if (target instanceof Map) {
709
- const cloned$1 = new Map(target);
722
+ const cloned$1 = tryCloneMapSubclass(target, target) ?? new Map(target);
710
723
  cloned$1[annotationKey] = annotations;
711
724
  return cloned$1;
712
725
  }
713
726
  if (target instanceof Set) {
714
- const cloned$1 = new Set(target);
727
+ const cloned$1 = tryCloneSetSubclass(target, target) ?? new Set(target);
715
728
  cloned$1[annotationKey] = annotations;
716
729
  return cloned$1;
717
730
  }
package/dist/facade.cjs CHANGED
@@ -1620,7 +1620,7 @@ function runWithAsync(parser, programName, contexts, options) {
1620
1620
  * @returns A new parser with annotations in its initial state.
1621
1621
  */
1622
1622
  function injectAnnotationsIntoParser(parser, annotations) {
1623
- const newInitialState = require_annotations.injectAnnotations(parser.initialState, annotations);
1623
+ const newInitialState = require_annotations.injectFreshRunAnnotations(parser.initialState, annotations);
1624
1624
  const descriptors = { ...Object.getOwnPropertyDescriptors(parser) };
1625
1625
  const initialState = descriptors.initialState;
1626
1626
  descriptors.initialState = initialState == null ? {
package/dist/facade.js CHANGED
@@ -1,4 +1,4 @@
1
- import { injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
1
+ import { injectFreshRunAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
2
2
  import { commandLine, formatMessage, lineBreak, message, optionName, text, value } from "./message.js";
3
3
  import { bash, fish, nu, pwsh, zsh } from "./completion.js";
4
4
  import { validateCommandNames, validateContextIds, validateMetaNameCollisions, validateOptionNames, validateProgramName } from "./validate.js";
@@ -1620,7 +1620,7 @@ function runWithAsync(parser, programName, contexts, options) {
1620
1620
  * @returns A new parser with annotations in its initial state.
1621
1621
  */
1622
1622
  function injectAnnotationsIntoParser(parser, annotations) {
1623
- const newInitialState = injectAnnotations(parser.initialState, annotations);
1623
+ const newInitialState = injectFreshRunAnnotations(parser.initialState, annotations);
1624
1624
  const descriptors = { ...Object.getOwnPropertyDescriptors(parser) };
1625
1625
  const initialState = descriptors.initialState;
1626
1626
  descriptors.initialState = initialState == null ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1868+54bdb27a",
3
+ "version": "1.0.0-dev.1872+bf32b1c5",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",