@optique/core 1.0.0-dev.1850 → 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.
- package/dist/annotations.cjs +32 -6
- package/dist/annotations.d.cts +1 -1
- package/dist/annotations.d.ts +1 -1
- package/dist/annotations.js +32 -6
- package/package.json +1 -1
package/dist/annotations.cjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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,7 +449,7 @@ function inheritAnnotations(source, target) {
|
|
|
423
449
|
return cloned$1;
|
|
424
450
|
}
|
|
425
451
|
if (target instanceof RegExp) {
|
|
426
|
-
const cloned$1 =
|
|
452
|
+
const cloned$1 = cloneRegExpShape(target);
|
|
427
453
|
cloned$1[annotationKey] = annotations;
|
|
428
454
|
return cloned$1;
|
|
429
455
|
}
|
|
@@ -516,7 +542,7 @@ function injectAnnotations(state, annotations) {
|
|
|
516
542
|
return cloned$1;
|
|
517
543
|
}
|
|
518
544
|
if (state instanceof RegExp) {
|
|
519
|
-
const cloned$1 =
|
|
545
|
+
const cloned$1 = cloneRegExpShape(state);
|
|
520
546
|
cloned$1[annotationKey] = protectedAnnotations;
|
|
521
547
|
return cloned$1;
|
|
522
548
|
}
|
package/dist/annotations.d.cts
CHANGED
|
@@ -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.
|
package/dist/annotations.d.ts
CHANGED
|
@@ -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.
|
package/dist/annotations.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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,7 +448,7 @@ function inheritAnnotations(source, target) {
|
|
|
422
448
|
return cloned$1;
|
|
423
449
|
}
|
|
424
450
|
if (target instanceof RegExp) {
|
|
425
|
-
const cloned$1 =
|
|
451
|
+
const cloned$1 = cloneRegExpShape(target);
|
|
426
452
|
cloned$1[annotationKey] = annotations;
|
|
427
453
|
return cloned$1;
|
|
428
454
|
}
|
|
@@ -515,7 +541,7 @@ function injectAnnotations(state, annotations) {
|
|
|
515
541
|
return cloned$1;
|
|
516
542
|
}
|
|
517
543
|
if (state instanceof RegExp) {
|
|
518
|
-
const cloned$1 =
|
|
544
|
+
const cloned$1 = cloneRegExpShape(state);
|
|
519
545
|
cloned$1[annotationKey] = protectedAnnotations;
|
|
520
546
|
return cloned$1;
|
|
521
547
|
}
|