@optique/core 1.0.0-dev.1852 → 1.0.0-dev.1854

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.
@@ -81,6 +81,29 @@ function defineProtectedDataProperty(context, target, key, descriptor) {
81
81
  set: () => throwReadonlyAnnotationMutation()
82
82
  });
83
83
  }
84
+ function copyRegExpMetadata(source, target, transformValue) {
85
+ const sourcePrototype = Object.getPrototypeOf(source);
86
+ if (Object.getPrototypeOf(target) !== sourcePrototype) Object.setPrototypeOf(target, sourcePrototype);
87
+ for (const key of Reflect.ownKeys(source)) {
88
+ if (key === "lastIndex") continue;
89
+ const descriptor = Object.getOwnPropertyDescriptor(source, key);
90
+ if (descriptor == null) continue;
91
+ if ("value" in descriptor && transformValue != null) {
92
+ Object.defineProperty(target, key, {
93
+ ...descriptor,
94
+ value: transformValue(descriptor.value)
95
+ });
96
+ continue;
97
+ }
98
+ Object.defineProperty(target, key, descriptor);
99
+ }
100
+ target.lastIndex = source.lastIndex;
101
+ }
102
+ function cloneRegExpShape(source) {
103
+ const cloned = new RegExp(source);
104
+ copyRegExpMetadata(source, cloned);
105
+ return cloned;
106
+ }
84
107
  function createProtectedObjectView(target, context) {
85
108
  if (Array.isArray(target)) {
86
109
  const view$1 = new Array(target.length);
@@ -231,12 +254,13 @@ function createProtectedDateView(target, context) {
231
254
  function createProtectedRegExpView(target, context) {
232
255
  const methodCache = /* @__PURE__ */ new Map();
233
256
  const cloned = new RegExp(target);
234
- cloned.lastIndex = target.lastIndex;
235
257
  const view = new Proxy(cloned, {
236
258
  get(clonedTarget, key) {
237
- const value = Reflect.get(clonedTarget, key, clonedTarget);
238
259
  if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
239
- return typeof value === "function" ? value.bind(clonedTarget) : value;
260
+ const ownDescriptor = Object.getOwnPropertyDescriptor(clonedTarget, key);
261
+ if (ownDescriptor != null && "value" in ownDescriptor) return ownDescriptor.value;
262
+ const value = Reflect.get(clonedTarget, key, clonedTarget);
263
+ return typeof value === "function" ? value.bind(clonedTarget) : protectAnnotationValue(value, context);
240
264
  },
241
265
  set() {
242
266
  throwReadonlyAnnotationMutation();
@@ -254,7 +278,9 @@ function createProtectedRegExpView(target, context) {
254
278
  throwReadonlyAnnotationMutation();
255
279
  }
256
280
  });
257
- return registerProtectedAnnotationView(context, target, view);
281
+ registerProtectedAnnotationView(context, target, view);
282
+ copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context));
283
+ return view;
258
284
  }
259
285
  function createProtectedURLSearchParamsView(target, context) {
260
286
  const methodCache = /* @__PURE__ */ new Map();
@@ -423,8 +449,7 @@ function inheritAnnotations(source, target) {
423
449
  return cloned$1;
424
450
  }
425
451
  if (target instanceof RegExp) {
426
- const cloned$1 = new RegExp(target);
427
- cloned$1.lastIndex = target.lastIndex;
452
+ const cloned$1 = cloneRegExpShape(target);
428
453
  cloned$1[annotationKey] = annotations;
429
454
  return cloned$1;
430
455
  }
@@ -517,8 +542,7 @@ function injectAnnotations(state, annotations) {
517
542
  return cloned$1;
518
543
  }
519
544
  if (state instanceof RegExp) {
520
- const cloned$1 = new RegExp(state);
521
- cloned$1.lastIndex = state.lastIndex;
545
+ const cloned$1 = cloneRegExpShape(state);
522
546
  cloned$1[annotationKey] = protectedAnnotations;
523
547
  return cloned$1;
524
548
  }
@@ -76,7 +76,7 @@ interface ParseOptions {
76
76
  * Optique treats these values as immutable input and exposes them back to
77
77
  * parsers only through protected read-only views.
78
78
  */
79
- annotations?: Annotations;
79
+ annotations?: Annotations | ReadonlyAnnotations;
80
80
  }
81
81
  /**
82
82
  * Extracts annotations from parser state.
@@ -76,7 +76,7 @@ interface ParseOptions {
76
76
  * Optique treats these values as immutable input and exposes them back to
77
77
  * parsers only through protected read-only views.
78
78
  */
79
- annotations?: Annotations;
79
+ annotations?: Annotations | ReadonlyAnnotations;
80
80
  }
81
81
  /**
82
82
  * Extracts annotations from parser state.
@@ -80,6 +80,29 @@ function defineProtectedDataProperty(context, target, key, descriptor) {
80
80
  set: () => throwReadonlyAnnotationMutation()
81
81
  });
82
82
  }
83
+ function copyRegExpMetadata(source, target, transformValue) {
84
+ const sourcePrototype = Object.getPrototypeOf(source);
85
+ if (Object.getPrototypeOf(target) !== sourcePrototype) Object.setPrototypeOf(target, sourcePrototype);
86
+ for (const key of Reflect.ownKeys(source)) {
87
+ if (key === "lastIndex") continue;
88
+ const descriptor = Object.getOwnPropertyDescriptor(source, key);
89
+ if (descriptor == null) continue;
90
+ if ("value" in descriptor && transformValue != null) {
91
+ Object.defineProperty(target, key, {
92
+ ...descriptor,
93
+ value: transformValue(descriptor.value)
94
+ });
95
+ continue;
96
+ }
97
+ Object.defineProperty(target, key, descriptor);
98
+ }
99
+ target.lastIndex = source.lastIndex;
100
+ }
101
+ function cloneRegExpShape(source) {
102
+ const cloned = new RegExp(source);
103
+ copyRegExpMetadata(source, cloned);
104
+ return cloned;
105
+ }
83
106
  function createProtectedObjectView(target, context) {
84
107
  if (Array.isArray(target)) {
85
108
  const view$1 = new Array(target.length);
@@ -230,12 +253,13 @@ function createProtectedDateView(target, context) {
230
253
  function createProtectedRegExpView(target, context) {
231
254
  const methodCache = /* @__PURE__ */ new Map();
232
255
  const cloned = new RegExp(target);
233
- cloned.lastIndex = target.lastIndex;
234
256
  const view = new Proxy(cloned, {
235
257
  get(clonedTarget, key) {
236
- const value = Reflect.get(clonedTarget, key, clonedTarget);
237
258
  if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
238
- return typeof value === "function" ? value.bind(clonedTarget) : value;
259
+ const ownDescriptor = Object.getOwnPropertyDescriptor(clonedTarget, key);
260
+ if (ownDescriptor != null && "value" in ownDescriptor) return ownDescriptor.value;
261
+ const value = Reflect.get(clonedTarget, key, clonedTarget);
262
+ return typeof value === "function" ? value.bind(clonedTarget) : protectAnnotationValue(value, context);
239
263
  },
240
264
  set() {
241
265
  throwReadonlyAnnotationMutation();
@@ -253,7 +277,9 @@ function createProtectedRegExpView(target, context) {
253
277
  throwReadonlyAnnotationMutation();
254
278
  }
255
279
  });
256
- return registerProtectedAnnotationView(context, target, view);
280
+ registerProtectedAnnotationView(context, target, view);
281
+ copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context));
282
+ return view;
257
283
  }
258
284
  function createProtectedURLSearchParamsView(target, context) {
259
285
  const methodCache = /* @__PURE__ */ new Map();
@@ -422,8 +448,7 @@ function inheritAnnotations(source, target) {
422
448
  return cloned$1;
423
449
  }
424
450
  if (target instanceof RegExp) {
425
- const cloned$1 = new RegExp(target);
426
- cloned$1.lastIndex = target.lastIndex;
451
+ const cloned$1 = cloneRegExpShape(target);
427
452
  cloned$1[annotationKey] = annotations;
428
453
  return cloned$1;
429
454
  }
@@ -516,8 +541,7 @@ function injectAnnotations(state, annotations) {
516
541
  return cloned$1;
517
542
  }
518
543
  if (state instanceof RegExp) {
519
- const cloned$1 = new RegExp(state);
520
- cloned$1.lastIndex = state.lastIndex;
544
+ const cloned$1 = cloneRegExpShape(state);
521
545
  cloned$1[annotationKey] = protectedAnnotations;
522
546
  return cloned$1;
523
547
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1852+6dd8742f",
3
+ "version": "1.0.0-dev.1854+f15dcfec",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",