@optique/core 1.0.0-dev.1499 → 1.0.0-dev.1500
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/constructs.cjs +183 -35
- package/dist/constructs.js +183 -35
- package/dist/context.cjs +1 -39
- package/dist/context.d.cts +1 -35
- package/dist/context.d.ts +1 -35
- package/dist/context.js +1 -37
- package/dist/dependency.cjs +42 -0
- package/dist/dependency.js +42 -0
- package/dist/facade.cjs +68 -268
- package/dist/facade.js +68 -268
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/modifiers.cjs +139 -21
- package/dist/modifiers.d.cts +41 -0
- package/dist/modifiers.d.ts +41 -0
- package/dist/modifiers.js +139 -21
- package/dist/parser.cjs +6 -2
- package/dist/parser.d.cts +28 -1
- package/dist/parser.d.ts +28 -1
- package/dist/parser.js +6 -2
- package/dist/primitives.cjs +44 -2
- package/dist/primitives.js +44 -2
- package/dist/valueparser.cjs +82 -1
- package/dist/valueparser.d.cts +125 -1
- package/dist/valueparser.d.ts +125 -1
- package/dist/valueparser.js +82 -1
- package/package.json +1 -1
package/dist/dependency.cjs
CHANGED
|
@@ -204,6 +204,13 @@ function createSyncDerivedFromParser(sourceId, options) {
|
|
|
204
204
|
return {
|
|
205
205
|
$mode: "sync",
|
|
206
206
|
metavar: options.metavar,
|
|
207
|
+
get placeholder() {
|
|
208
|
+
try {
|
|
209
|
+
return options.factory(...options.defaultValues()).placeholder;
|
|
210
|
+
} catch {
|
|
211
|
+
return void 0;
|
|
212
|
+
}
|
|
213
|
+
},
|
|
207
214
|
[derivedValueParserMarker]: true,
|
|
208
215
|
[dependencyId]: sourceId,
|
|
209
216
|
[dependencyIds]: alldependencyIds,
|
|
@@ -290,6 +297,13 @@ function createAsyncDerivedFromParserFromAsyncFactory(sourceId, options) {
|
|
|
290
297
|
return {
|
|
291
298
|
$mode: "async",
|
|
292
299
|
metavar: options.metavar,
|
|
300
|
+
get placeholder() {
|
|
301
|
+
try {
|
|
302
|
+
return options.factory(...options.defaultValues()).placeholder;
|
|
303
|
+
} catch {
|
|
304
|
+
return void 0;
|
|
305
|
+
}
|
|
306
|
+
},
|
|
293
307
|
[derivedValueParserMarker]: true,
|
|
294
308
|
[dependencyId]: sourceId,
|
|
295
309
|
[dependencyIds]: alldependencyIds,
|
|
@@ -366,6 +380,13 @@ function createAsyncDerivedFromParserFromSyncFactory(sourceId, options) {
|
|
|
366
380
|
return {
|
|
367
381
|
$mode: "async",
|
|
368
382
|
metavar: options.metavar,
|
|
383
|
+
get placeholder() {
|
|
384
|
+
try {
|
|
385
|
+
return options.factory(...options.defaultValues()).placeholder;
|
|
386
|
+
} catch {
|
|
387
|
+
return void 0;
|
|
388
|
+
}
|
|
389
|
+
},
|
|
369
390
|
[derivedValueParserMarker]: true,
|
|
370
391
|
[dependencyId]: sourceId,
|
|
371
392
|
[dependencyIds]: alldependencyIds,
|
|
@@ -446,6 +467,13 @@ function createSyncDerivedParser(sourceId, options) {
|
|
|
446
467
|
return {
|
|
447
468
|
$mode: "sync",
|
|
448
469
|
metavar: options.metavar,
|
|
470
|
+
get placeholder() {
|
|
471
|
+
try {
|
|
472
|
+
return options.factory(options.defaultValue()).placeholder;
|
|
473
|
+
} catch {
|
|
474
|
+
return void 0;
|
|
475
|
+
}
|
|
476
|
+
},
|
|
449
477
|
[derivedValueParserMarker]: true,
|
|
450
478
|
[dependencyId]: sourceId,
|
|
451
479
|
parse(input) {
|
|
@@ -528,6 +556,13 @@ function createAsyncDerivedParserFromAsyncFactory(sourceId, options) {
|
|
|
528
556
|
return {
|
|
529
557
|
$mode: "async",
|
|
530
558
|
metavar: options.metavar,
|
|
559
|
+
get placeholder() {
|
|
560
|
+
try {
|
|
561
|
+
return options.factory(options.defaultValue()).placeholder;
|
|
562
|
+
} catch {
|
|
563
|
+
return void 0;
|
|
564
|
+
}
|
|
565
|
+
},
|
|
531
566
|
[derivedValueParserMarker]: true,
|
|
532
567
|
[dependencyId]: sourceId,
|
|
533
568
|
parse(input) {
|
|
@@ -600,6 +635,13 @@ function createAsyncDerivedParserFromSyncFactory(sourceId, options) {
|
|
|
600
635
|
return {
|
|
601
636
|
$mode: "async",
|
|
602
637
|
metavar: options.metavar,
|
|
638
|
+
get placeholder() {
|
|
639
|
+
try {
|
|
640
|
+
return options.factory(options.defaultValue()).placeholder;
|
|
641
|
+
} catch {
|
|
642
|
+
return void 0;
|
|
643
|
+
}
|
|
644
|
+
},
|
|
603
645
|
[derivedValueParserMarker]: true,
|
|
604
646
|
[dependencyId]: sourceId,
|
|
605
647
|
parse(input) {
|
package/dist/dependency.js
CHANGED
|
@@ -204,6 +204,13 @@ function createSyncDerivedFromParser(sourceId, options) {
|
|
|
204
204
|
return {
|
|
205
205
|
$mode: "sync",
|
|
206
206
|
metavar: options.metavar,
|
|
207
|
+
get placeholder() {
|
|
208
|
+
try {
|
|
209
|
+
return options.factory(...options.defaultValues()).placeholder;
|
|
210
|
+
} catch {
|
|
211
|
+
return void 0;
|
|
212
|
+
}
|
|
213
|
+
},
|
|
207
214
|
[derivedValueParserMarker]: true,
|
|
208
215
|
[dependencyId]: sourceId,
|
|
209
216
|
[dependencyIds]: alldependencyIds,
|
|
@@ -290,6 +297,13 @@ function createAsyncDerivedFromParserFromAsyncFactory(sourceId, options) {
|
|
|
290
297
|
return {
|
|
291
298
|
$mode: "async",
|
|
292
299
|
metavar: options.metavar,
|
|
300
|
+
get placeholder() {
|
|
301
|
+
try {
|
|
302
|
+
return options.factory(...options.defaultValues()).placeholder;
|
|
303
|
+
} catch {
|
|
304
|
+
return void 0;
|
|
305
|
+
}
|
|
306
|
+
},
|
|
293
307
|
[derivedValueParserMarker]: true,
|
|
294
308
|
[dependencyId]: sourceId,
|
|
295
309
|
[dependencyIds]: alldependencyIds,
|
|
@@ -366,6 +380,13 @@ function createAsyncDerivedFromParserFromSyncFactory(sourceId, options) {
|
|
|
366
380
|
return {
|
|
367
381
|
$mode: "async",
|
|
368
382
|
metavar: options.metavar,
|
|
383
|
+
get placeholder() {
|
|
384
|
+
try {
|
|
385
|
+
return options.factory(...options.defaultValues()).placeholder;
|
|
386
|
+
} catch {
|
|
387
|
+
return void 0;
|
|
388
|
+
}
|
|
389
|
+
},
|
|
369
390
|
[derivedValueParserMarker]: true,
|
|
370
391
|
[dependencyId]: sourceId,
|
|
371
392
|
[dependencyIds]: alldependencyIds,
|
|
@@ -446,6 +467,13 @@ function createSyncDerivedParser(sourceId, options) {
|
|
|
446
467
|
return {
|
|
447
468
|
$mode: "sync",
|
|
448
469
|
metavar: options.metavar,
|
|
470
|
+
get placeholder() {
|
|
471
|
+
try {
|
|
472
|
+
return options.factory(options.defaultValue()).placeholder;
|
|
473
|
+
} catch {
|
|
474
|
+
return void 0;
|
|
475
|
+
}
|
|
476
|
+
},
|
|
449
477
|
[derivedValueParserMarker]: true,
|
|
450
478
|
[dependencyId]: sourceId,
|
|
451
479
|
parse(input) {
|
|
@@ -528,6 +556,13 @@ function createAsyncDerivedParserFromAsyncFactory(sourceId, options) {
|
|
|
528
556
|
return {
|
|
529
557
|
$mode: "async",
|
|
530
558
|
metavar: options.metavar,
|
|
559
|
+
get placeholder() {
|
|
560
|
+
try {
|
|
561
|
+
return options.factory(options.defaultValue()).placeholder;
|
|
562
|
+
} catch {
|
|
563
|
+
return void 0;
|
|
564
|
+
}
|
|
565
|
+
},
|
|
531
566
|
[derivedValueParserMarker]: true,
|
|
532
567
|
[dependencyId]: sourceId,
|
|
533
568
|
parse(input) {
|
|
@@ -600,6 +635,13 @@ function createAsyncDerivedParserFromSyncFactory(sourceId, options) {
|
|
|
600
635
|
return {
|
|
601
636
|
$mode: "async",
|
|
602
637
|
metavar: options.metavar,
|
|
638
|
+
get placeholder() {
|
|
639
|
+
try {
|
|
640
|
+
return options.factory(options.defaultValue()).placeholder;
|
|
641
|
+
} catch {
|
|
642
|
+
return void 0;
|
|
643
|
+
}
|
|
644
|
+
},
|
|
603
645
|
[derivedValueParserMarker]: true,
|
|
604
646
|
[dependencyId]: sourceId,
|
|
605
647
|
parse(input) {
|
package/dist/facade.cjs
CHANGED
|
@@ -6,282 +6,72 @@ const require_validate = require('./validate.cjs');
|
|
|
6
6
|
const require_usage = require('./usage.cjs');
|
|
7
7
|
const require_doc = require('./doc.cjs');
|
|
8
8
|
const require_constructs = require('./constructs.cjs');
|
|
9
|
-
const require_context = require('./context.cjs');
|
|
10
9
|
const require_modifiers = require('./modifiers.cjs');
|
|
11
10
|
const require_valueparser = require('./valueparser.cjs');
|
|
12
11
|
const require_primitives = require('./primitives.cjs');
|
|
13
12
|
const require_parser = require('./parser.cjs');
|
|
14
13
|
|
|
15
14
|
//#region src/facade.ts
|
|
15
|
+
function finalizeParsedForContext(context, parsed) {
|
|
16
|
+
return context.finalizeParsed != null ? context.finalizeParsed(parsed) : parsed;
|
|
17
|
+
}
|
|
16
18
|
function isPlainObject(value$1) {
|
|
17
19
|
const proto = Object.getPrototypeOf(value$1);
|
|
18
20
|
return proto === Object.prototype || proto === null;
|
|
19
21
|
}
|
|
20
|
-
function
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
for (const key of Reflect.ownKeys(source)) {
|
|
34
|
-
if (shouldSkipCollectionOwnKey(source, key)) continue;
|
|
35
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
36
|
-
if (descriptor == null) continue;
|
|
37
|
-
if ("value" in descriptor) descriptor.value = stripPlaceholderValues(descriptor.value, seen);
|
|
38
|
-
Object.defineProperty(target, key, descriptor);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function createArrayCloneLike(value$1) {
|
|
42
|
-
try {
|
|
43
|
-
const arrayCtor = value$1.constructor;
|
|
44
|
-
return Reflect.construct(Array, [value$1.length], arrayCtor);
|
|
45
|
-
} catch {
|
|
46
|
-
return new Array(value$1.length);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function createSetCloneLike(value$1) {
|
|
50
|
-
try {
|
|
51
|
-
const setCtor = value$1.constructor;
|
|
52
|
-
return Reflect.construct(Set, [], setCtor);
|
|
53
|
-
} catch {
|
|
54
|
-
return /* @__PURE__ */ new Set();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function createMapCloneLike(value$1) {
|
|
58
|
-
try {
|
|
59
|
-
const mapCtor = value$1.constructor;
|
|
60
|
-
return Reflect.construct(Map, [], mapCtor);
|
|
61
|
-
} catch {
|
|
62
|
-
return /* @__PURE__ */ new Map();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function containsPlaceholderValues(value$1, seen = /* @__PURE__ */ new WeakSet()) {
|
|
66
|
-
if (require_context.isPlaceholderValue(value$1)) return true;
|
|
67
|
-
if (value$1 == null || typeof value$1 !== "object") return false;
|
|
68
|
-
if (seen.has(value$1)) return false;
|
|
69
|
-
seen.add(value$1);
|
|
70
|
-
if (Array.isArray(value$1)) {
|
|
71
|
-
if (value$1.some((item) => containsPlaceholderValues(item, seen))) return true;
|
|
72
|
-
return containsPlaceholderValuesInOwnProperties(value$1, seen);
|
|
73
|
-
}
|
|
74
|
-
if (value$1 instanceof Set) {
|
|
75
|
-
for (const entryValue of value$1) if (containsPlaceholderValues(entryValue, seen)) return true;
|
|
76
|
-
return containsPlaceholderValuesInOwnProperties(value$1, seen);
|
|
77
|
-
}
|
|
78
|
-
if (value$1 instanceof Map) {
|
|
79
|
-
for (const [key, entryValue] of value$1) if (containsPlaceholderValues(key, seen) || containsPlaceholderValues(entryValue, seen)) return true;
|
|
80
|
-
return containsPlaceholderValuesInOwnProperties(value$1, seen);
|
|
81
|
-
}
|
|
82
|
-
return containsPlaceholderValuesInOwnProperties(value$1, seen);
|
|
83
|
-
}
|
|
84
|
-
function stripPlaceholderValues(value$1, seen = /* @__PURE__ */ new WeakMap()) {
|
|
85
|
-
if (require_context.isPlaceholderValue(value$1)) return void 0;
|
|
86
|
-
if (value$1 == null || typeof value$1 !== "object") return value$1;
|
|
87
|
-
const cached = seen.get(value$1);
|
|
88
|
-
if (cached !== void 0) return cached;
|
|
89
|
-
if (Array.isArray(value$1)) {
|
|
90
|
-
if (!containsPlaceholderValues(value$1)) return value$1;
|
|
91
|
-
const clone$1 = createArrayCloneLike(value$1);
|
|
92
|
-
seen.set(value$1, clone$1);
|
|
93
|
-
for (let i = 0; i < value$1.length; i++) clone$1[i] = stripPlaceholderValues(value$1[i], seen);
|
|
94
|
-
copySanitizedOwnProperties(value$1, clone$1, seen);
|
|
95
|
-
return clone$1;
|
|
96
|
-
}
|
|
97
|
-
if (value$1 instanceof Set) {
|
|
98
|
-
if (!containsPlaceholderValues(value$1)) return value$1;
|
|
99
|
-
const clone$1 = createSetCloneLike(value$1);
|
|
100
|
-
seen.set(value$1, clone$1);
|
|
101
|
-
for (const entryValue of value$1) clone$1.add(stripPlaceholderValues(entryValue, seen));
|
|
102
|
-
copySanitizedOwnProperties(value$1, clone$1, seen);
|
|
103
|
-
return clone$1;
|
|
104
|
-
}
|
|
105
|
-
if (value$1 instanceof Map) {
|
|
106
|
-
if (!containsPlaceholderValues(value$1)) return value$1;
|
|
107
|
-
const clone$1 = createMapCloneLike(value$1);
|
|
108
|
-
seen.set(value$1, clone$1);
|
|
109
|
-
for (const [key, entryValue] of value$1) clone$1.set(stripPlaceholderValues(key, seen), stripPlaceholderValues(entryValue, seen));
|
|
110
|
-
copySanitizedOwnProperties(value$1, clone$1, seen);
|
|
111
|
-
return clone$1;
|
|
112
|
-
}
|
|
113
|
-
if (!isPlainObject(value$1)) {
|
|
114
|
-
if (!containsPlaceholderValues(value$1)) return value$1;
|
|
115
|
-
return createSanitizedNonPlainView(value$1, seen);
|
|
116
|
-
}
|
|
117
|
-
const clone = Object.create(Object.getPrototypeOf(value$1));
|
|
118
|
-
seen.set(value$1, clone);
|
|
119
|
-
for (const key of Reflect.ownKeys(value$1)) {
|
|
120
|
-
const descriptor = Object.getOwnPropertyDescriptor(value$1, key);
|
|
121
|
-
if (descriptor == null) continue;
|
|
122
|
-
if ("value" in descriptor) descriptor.value = stripPlaceholderValues(descriptor.value, seen);
|
|
123
|
-
Object.defineProperty(clone, key, descriptor);
|
|
124
|
-
}
|
|
125
|
-
return clone;
|
|
126
|
-
}
|
|
127
|
-
function finalizeParsedForContext(context, parsed) {
|
|
128
|
-
return context.finalizeParsed != null ? context.finalizeParsed(parsed) : parsed;
|
|
129
|
-
}
|
|
130
|
-
const SANITIZE_FAILED = Symbol("sanitizeFailed");
|
|
131
|
-
const activeSanitizations = /* @__PURE__ */ new WeakMap();
|
|
132
|
-
function callWithSanitizedOwnProperties(target, fn, args, strip, seen) {
|
|
133
|
-
let active = activeSanitizations.get(target);
|
|
134
|
-
if (active != null) active.count++;
|
|
135
|
-
else {
|
|
136
|
-
const saved = /* @__PURE__ */ new Map();
|
|
137
|
-
const sanitizedValues = /* @__PURE__ */ new Map();
|
|
138
|
-
for (const key of Reflect.ownKeys(target)) {
|
|
139
|
-
const desc = Object.getOwnPropertyDescriptor(target, key);
|
|
140
|
-
if (desc != null && "value" in desc) {
|
|
141
|
-
let stripped;
|
|
142
|
-
try {
|
|
143
|
-
stripped = strip(desc.value, seen);
|
|
144
|
-
} catch {
|
|
145
|
-
for (const [k, d] of saved) try {
|
|
146
|
-
Object.defineProperty(target, k, d);
|
|
147
|
-
} catch {}
|
|
148
|
-
return SANITIZE_FAILED;
|
|
149
|
-
}
|
|
150
|
-
if (stripped !== desc.value) try {
|
|
151
|
-
Object.defineProperty(target, key, {
|
|
152
|
-
...desc,
|
|
153
|
-
value: stripped
|
|
154
|
-
});
|
|
155
|
-
saved.set(key, desc);
|
|
156
|
-
sanitizedValues.set(key, stripped);
|
|
157
|
-
} catch {
|
|
158
|
-
for (const [k, d] of saved) try {
|
|
159
|
-
Object.defineProperty(target, k, d);
|
|
160
|
-
} catch {}
|
|
161
|
-
return SANITIZE_FAILED;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
active = {
|
|
166
|
-
saved,
|
|
167
|
-
sanitizedValues,
|
|
168
|
-
count: 1
|
|
22
|
+
function prepareParsedForContexts(parsed, deferred, deferredKeys) {
|
|
23
|
+
if (!deferred) return parsed;
|
|
24
|
+
if (deferredKeys != null && deferredKeys.size === 0 && parsed != null && typeof parsed === "object") return void 0;
|
|
25
|
+
if (deferredKeys != null && deferredKeys.size > 0 && parsed != null && typeof parsed === "object" && !isPlainObject(parsed) && !Array.isArray(parsed)) return void 0;
|
|
26
|
+
if (deferredKeys != null && deferredKeys.size > 0 && parsed != null && typeof parsed === "object" && (isPlainObject(parsed) || Array.isArray(parsed))) {
|
|
27
|
+
const getDeferredEntry = (key) => {
|
|
28
|
+
const entry = deferredKeys.get(key);
|
|
29
|
+
if (entry !== void 0) return entry;
|
|
30
|
+
if (typeof key === "string") {
|
|
31
|
+
const num = Number(key);
|
|
32
|
+
if (Number.isInteger(num)) return deferredKeys.get(num);
|
|
33
|
+
} else if (typeof key === "number") return deferredKeys.get(String(key));
|
|
34
|
+
return void 0;
|
|
169
35
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
activeSanitizations.delete(target);
|
|
176
|
-
for (const [key, desc] of active.saved) try {
|
|
177
|
-
const current = Object.getOwnPropertyDescriptor(target, key);
|
|
178
|
-
if (current == null) continue;
|
|
179
|
-
if ("value" in current && current.value !== active.sanitizedValues.get(key)) continue;
|
|
180
|
-
Object.defineProperty(target, key, desc);
|
|
181
|
-
} catch {}
|
|
36
|
+
const ownKeys = Reflect.ownKeys(parsed);
|
|
37
|
+
let hasMatchingKey = false;
|
|
38
|
+
for (const key of ownKeys) if (getDeferredEntry(key) !== void 0) {
|
|
39
|
+
hasMatchingKey = true;
|
|
40
|
+
break;
|
|
182
41
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (result instanceof Promise) return result.then((v) => {
|
|
192
|
-
release();
|
|
193
|
-
return strip(v, seen);
|
|
194
|
-
}, (e) => {
|
|
195
|
-
release();
|
|
196
|
-
throw e;
|
|
197
|
-
});
|
|
198
|
-
release();
|
|
199
|
-
return strip(result, seen);
|
|
200
|
-
}
|
|
201
|
-
function callMethodOnSanitizedTarget(fn, proxy, target, args, strip, seen) {
|
|
202
|
-
const result = callWithSanitizedOwnProperties(target, fn, args, strip, seen);
|
|
203
|
-
if (result !== SANITIZE_FAILED) return result;
|
|
204
|
-
const fallback = fn.apply(proxy, args);
|
|
205
|
-
if (fallback instanceof Promise) return fallback.then((v) => strip(v, seen));
|
|
206
|
-
return strip(fallback, seen);
|
|
207
|
-
}
|
|
208
|
-
function createSanitizedNonPlainView(value$1, seen) {
|
|
209
|
-
const methodCache = /* @__PURE__ */ new Map();
|
|
210
|
-
const proxy = new Proxy(value$1, {
|
|
211
|
-
get(target, key, receiver) {
|
|
212
|
-
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
213
|
-
if (descriptor != null && "value" in descriptor) {
|
|
214
|
-
if (!descriptor.configurable && !descriptor.writable) return descriptor.value;
|
|
215
|
-
const val = stripPlaceholderValues(descriptor.value, seen);
|
|
216
|
-
if (typeof val === "function") {
|
|
217
|
-
if (!descriptor.configurable && !descriptor.writable || /^class[\s{]/.test(Function.prototype.toString.call(val))) return val;
|
|
218
|
-
const cached = methodCache.get(key);
|
|
219
|
-
if (cached != null && cached.fn === val) return cached.wrapper;
|
|
220
|
-
const wrapper = function(...args) {
|
|
221
|
-
if (this !== proxy) return stripPlaceholderValues(val.apply(this, args), seen);
|
|
222
|
-
return callMethodOnSanitizedTarget(val, proxy, target, args, stripPlaceholderValues, seen);
|
|
223
|
-
};
|
|
224
|
-
methodCache.set(key, {
|
|
225
|
-
fn: val,
|
|
226
|
-
wrapper
|
|
227
|
-
});
|
|
228
|
-
return wrapper;
|
|
229
|
-
}
|
|
230
|
-
return val;
|
|
231
|
-
}
|
|
232
|
-
let isAccessor = false;
|
|
233
|
-
for (let proto = target; proto != null; proto = Object.getPrototypeOf(proto)) {
|
|
234
|
-
const d = Object.getOwnPropertyDescriptor(proto, key);
|
|
235
|
-
if (d != null) {
|
|
236
|
-
isAccessor = "get" in d;
|
|
42
|
+
if (hasMatchingKey) {
|
|
43
|
+
const isArray = Array.isArray(parsed);
|
|
44
|
+
let allDeferred = true;
|
|
45
|
+
for (const key of ownKeys) {
|
|
46
|
+
if (isArray && key === "length") continue;
|
|
47
|
+
const desc = Object.getOwnPropertyDescriptor(parsed, key);
|
|
48
|
+
if (desc != null && "value" in desc && getDeferredEntry(key) === void 0) {
|
|
49
|
+
allDeferred = false;
|
|
237
50
|
break;
|
|
238
51
|
}
|
|
239
52
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
return function(...args) {
|
|
257
|
-
if (this !== proxy) return stripPlaceholderValues(result.apply(this, args), seen);
|
|
258
|
-
return callMethodOnSanitizedTarget(result, proxy, target, args, stripPlaceholderValues, seen);
|
|
259
|
-
};
|
|
53
|
+
if (allDeferred) return void 0;
|
|
54
|
+
const clone = isArray ? new Array(parsed.length) : Object.create(Object.getPrototypeOf(parsed));
|
|
55
|
+
for (const key of ownKeys) {
|
|
56
|
+
const desc = Object.getOwnPropertyDescriptor(parsed, key);
|
|
57
|
+
if (desc == null) continue;
|
|
58
|
+
const entry = getDeferredEntry(key);
|
|
59
|
+
if ("value" in desc && entry !== void 0) if (entry === null) Object.defineProperty(clone, key, {
|
|
60
|
+
...desc,
|
|
61
|
+
value: void 0
|
|
62
|
+
});
|
|
63
|
+
else Object.defineProperty(clone, key, {
|
|
64
|
+
...desc,
|
|
65
|
+
value: prepareParsedForContexts(desc.value, true, entry)
|
|
66
|
+
});
|
|
67
|
+
else Object.defineProperty(clone, key, desc);
|
|
260
68
|
}
|
|
261
|
-
return
|
|
262
|
-
},
|
|
263
|
-
getOwnPropertyDescriptor(target, key) {
|
|
264
|
-
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
265
|
-
if (descriptor == null || !("value" in descriptor)) return descriptor;
|
|
266
|
-
if (!descriptor.configurable && !descriptor.writable) return descriptor;
|
|
267
|
-
return {
|
|
268
|
-
...descriptor,
|
|
269
|
-
value: stripPlaceholderValues(descriptor.value, seen)
|
|
270
|
-
};
|
|
69
|
+
return clone;
|
|
271
70
|
}
|
|
272
|
-
|
|
273
|
-
seen.set(value$1, proxy);
|
|
274
|
-
return proxy;
|
|
275
|
-
}
|
|
276
|
-
function prepareParsedForContexts(parsed) {
|
|
277
|
-
if (parsed == null || typeof parsed !== "object") return stripPlaceholderValues(parsed);
|
|
278
|
-
if (require_context.isPlaceholderValue(parsed)) return void 0;
|
|
279
|
-
if (Array.isArray(parsed) || isPlainObject(parsed) || parsed instanceof Set || parsed instanceof Map) {
|
|
280
|
-
if (!containsPlaceholderValues(parsed)) return parsed;
|
|
281
|
-
return stripPlaceholderValues(parsed);
|
|
71
|
+
return void 0;
|
|
282
72
|
}
|
|
283
|
-
if (
|
|
284
|
-
return
|
|
73
|
+
if (parsed == null || typeof parsed !== "object") return void 0;
|
|
74
|
+
return parsed;
|
|
285
75
|
}
|
|
286
76
|
function withPreparedParsedForContext(context, preparedParsed, run) {
|
|
287
77
|
return run(finalizeParsedForContext(context, preparedParsed));
|
|
@@ -1210,9 +1000,9 @@ async function collectPhase1Annotations(contexts, options) {
|
|
|
1210
1000
|
* @param options Optional context-required options to pass to each context.
|
|
1211
1001
|
* @returns Promise that resolves to merged annotations.
|
|
1212
1002
|
*/
|
|
1213
|
-
async function collectAnnotations(contexts, parsed, options) {
|
|
1003
|
+
async function collectAnnotations(contexts, parsed, options, deferred, deferredKeys) {
|
|
1214
1004
|
const annotationsList = [];
|
|
1215
|
-
const preparedParsed = prepareParsedForContexts(parsed);
|
|
1005
|
+
const preparedParsed = prepareParsedForContexts(parsed, deferred, deferredKeys);
|
|
1216
1006
|
for (const context of contexts) {
|
|
1217
1007
|
const mergedAnnotations = await withPreparedParsedForContext(context, preparedParsed, async (contextParsed) => {
|
|
1218
1008
|
const result = context.getAnnotations(contextParsed, options);
|
|
@@ -1273,9 +1063,9 @@ function needsTwoPhaseContext(context, result) {
|
|
|
1273
1063
|
* @returns Merged annotations.
|
|
1274
1064
|
* @throws Error if any context returns a Promise.
|
|
1275
1065
|
*/
|
|
1276
|
-
function collectAnnotationsSync(contexts, parsed, options) {
|
|
1066
|
+
function collectAnnotationsSync(contexts, parsed, options, deferred, deferredKeys) {
|
|
1277
1067
|
const annotationsList = [];
|
|
1278
|
-
const preparedParsed = prepareParsedForContexts(parsed);
|
|
1068
|
+
const preparedParsed = prepareParsedForContexts(parsed, deferred, deferredKeys);
|
|
1279
1069
|
for (const context of contexts) {
|
|
1280
1070
|
const mergedAnnotations = withPreparedParsedForContext(context, preparedParsed, (contextParsed) => {
|
|
1281
1071
|
const result = context.getAnnotations(contextParsed, options);
|
|
@@ -1401,14 +1191,19 @@ async function runWith(parser, programName, contexts, options) {
|
|
|
1401
1191
|
}
|
|
1402
1192
|
const augmentedParser1 = injectAnnotationsIntoParser(parser, phase1Annotations);
|
|
1403
1193
|
let firstPassResult;
|
|
1194
|
+
let firstPassDeferred;
|
|
1195
|
+
let firstPassDeferredKeys;
|
|
1404
1196
|
let firstPassFailed = false;
|
|
1405
1197
|
try {
|
|
1406
1198
|
if (parser.$mode === "async") firstPassResult = await require_parser.parseAsync(augmentedParser1, args);
|
|
1407
1199
|
else firstPassResult = require_parser.parseSync(augmentedParser1, args);
|
|
1408
1200
|
if (typeof firstPassResult === "object" && firstPassResult !== null && "success" in firstPassResult) {
|
|
1409
1201
|
const result = firstPassResult;
|
|
1410
|
-
if (result.success)
|
|
1411
|
-
|
|
1202
|
+
if (result.success) {
|
|
1203
|
+
firstPassResult = result.value;
|
|
1204
|
+
firstPassDeferred = result.deferred;
|
|
1205
|
+
firstPassDeferredKeys = result.deferredKeys;
|
|
1206
|
+
} else firstPassFailed = true;
|
|
1412
1207
|
}
|
|
1413
1208
|
} catch {
|
|
1414
1209
|
firstPassFailed = true;
|
|
@@ -1418,7 +1213,7 @@ async function runWith(parser, programName, contexts, options) {
|
|
|
1418
1213
|
if (parser.$mode === "async") return runParser(augmentedParser, programName, args, options);
|
|
1419
1214
|
return Promise.resolve(runParser(augmentedParser, programName, args, options));
|
|
1420
1215
|
}
|
|
1421
|
-
const { annotationsList: phase2AnnotationsList } = await collectAnnotations(contexts, firstPassResult, ctxOptions);
|
|
1216
|
+
const { annotationsList: phase2AnnotationsList } = await collectAnnotations(contexts, firstPassResult, ctxOptions, firstPassDeferred, firstPassDeferredKeys);
|
|
1422
1217
|
const finalAnnotations = mergeTwoPhaseAnnotations(phase1AnnotationsList, phase2AnnotationsList);
|
|
1423
1218
|
const augmentedParser2 = injectAnnotationsIntoParser(parser, finalAnnotations);
|
|
1424
1219
|
if (parser.$mode === "async") return runParser(augmentedParser2, programName, args, options);
|
|
@@ -1461,14 +1256,19 @@ function runWithSync(parser, programName, contexts, options) {
|
|
|
1461
1256
|
}
|
|
1462
1257
|
const augmentedParser1 = injectAnnotationsIntoParser(parser, phase1Annotations);
|
|
1463
1258
|
let firstPassResult;
|
|
1259
|
+
let firstPassDeferred;
|
|
1260
|
+
let firstPassDeferredKeys;
|
|
1464
1261
|
try {
|
|
1465
1262
|
const result = require_parser.parseSync(augmentedParser1, args);
|
|
1466
|
-
if (result.success)
|
|
1467
|
-
|
|
1263
|
+
if (result.success) {
|
|
1264
|
+
firstPassResult = result.value;
|
|
1265
|
+
firstPassDeferred = result.deferred;
|
|
1266
|
+
firstPassDeferredKeys = result.deferredKeys;
|
|
1267
|
+
} else return runParser(augmentedParser1, programName, args, options);
|
|
1468
1268
|
} catch {
|
|
1469
1269
|
return runParser(augmentedParser1, programName, args, options);
|
|
1470
1270
|
}
|
|
1471
|
-
const { annotationsList: phase2AnnotationsList } = collectAnnotationsSync(contexts, firstPassResult, ctxOptions);
|
|
1271
|
+
const { annotationsList: phase2AnnotationsList } = collectAnnotationsSync(contexts, firstPassResult, ctxOptions, firstPassDeferred, firstPassDeferredKeys);
|
|
1472
1272
|
const finalAnnotations = mergeTwoPhaseAnnotations(phase1AnnotationsList, phase2AnnotationsList);
|
|
1473
1273
|
const augmentedParser2 = injectAnnotationsIntoParser(parser, finalAnnotations);
|
|
1474
1274
|
return runParser(augmentedParser2, programName, args, options);
|