@optique/core 1.0.0-dev.1901 → 1.0.0-dev.1970
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/annotation-state.cjs +115 -60
- package/dist/annotation-state.d.cts +24 -0
- package/dist/annotation-state.d.ts +24 -0
- package/dist/annotation-state.js +114 -60
- package/dist/annotations.cjs +2 -267
- package/dist/annotations.d.cts +2 -152
- package/dist/annotations.d.ts +2 -152
- package/dist/annotations.js +2 -256
- package/dist/completion.d.cts +1 -1
- package/dist/completion.d.ts +1 -1
- package/dist/constructs.cjs +206 -238
- package/dist/constructs.d.cts +1 -1
- package/dist/constructs.d.ts +1 -1
- package/dist/constructs.js +96 -128
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/dependency-metadata.cjs +1 -1
- package/dist/dependency-metadata.d.cts +1 -1
- package/dist/dependency-metadata.d.ts +1 -1
- package/dist/dependency-metadata.js +1 -1
- package/dist/dependency-runtime.cjs +2 -2
- package/dist/dependency-runtime.js +2 -2
- package/dist/dependency.cjs +7 -1111
- package/dist/dependency.d.cts +2 -838
- package/dist/dependency.d.ts +2 -838
- package/dist/dependency.js +2 -1078
- package/dist/execution-context.cjs +56 -0
- package/dist/execution-context.js +53 -0
- package/dist/extension.cjs +87 -0
- package/dist/extension.d.cts +97 -0
- package/dist/extension.d.ts +97 -0
- package/dist/extension.js +76 -0
- package/dist/facade.cjs +19 -19
- package/dist/facade.d.cts +1 -1
- package/dist/facade.d.ts +1 -1
- package/dist/facade.js +19 -19
- package/dist/index.cjs +4 -41
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/internal/annotations.cjs +316 -0
- package/dist/internal/annotations.d.cts +140 -0
- package/dist/internal/annotations.d.ts +140 -0
- package/dist/internal/annotations.js +306 -0
- package/dist/internal/dependency.cjs +984 -0
- package/dist/internal/dependency.d.cts +539 -0
- package/dist/internal/dependency.d.ts +539 -0
- package/dist/internal/dependency.js +964 -0
- package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
- package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
- package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
- package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
- package/dist/internal/parser.cjs +728 -0
- package/dist/internal/parser.d.cts +947 -0
- package/dist/internal/parser.d.ts +947 -0
- package/dist/internal/parser.js +711 -0
- package/dist/modifiers.cjs +108 -125
- package/dist/modifiers.d.cts +1 -1
- package/dist/modifiers.d.ts +1 -1
- package/dist/modifiers.js +92 -109
- package/dist/parser.cjs +11 -743
- package/dist/parser.d.cts +3 -991
- package/dist/parser.d.ts +3 -991
- package/dist/parser.js +2 -704
- package/dist/phase2-seed.cjs +4 -4
- package/dist/phase2-seed.js +4 -4
- package/dist/primitives.cjs +39 -74
- package/dist/primitives.d.cts +1 -1
- package/dist/primitives.d.ts +1 -1
- package/dist/primitives.js +26 -61
- package/dist/program.d.cts +1 -1
- package/dist/program.d.ts +1 -1
- package/dist/valueparser.cjs +23 -23
- package/dist/valueparser.d.cts +3 -3
- package/dist/valueparser.d.ts +3 -3
- package/dist/valueparser.js +23 -23
- package/package.json +9 -9
package/dist/modifiers.js
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
|
-
import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
|
|
1
|
+
import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./internal/annotations.js";
|
|
2
2
|
import { formatMessage, message, text } from "./message.js";
|
|
3
|
-
import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } from "./mode-dispatch.js";
|
|
4
|
-
import {
|
|
5
|
-
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
6
|
-
import { defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, unmatchedNonCliDependencySourceStateMarker } from "./parser.js";
|
|
3
|
+
import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
|
|
4
|
+
import { defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
7
5
|
import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
|
|
6
|
+
import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
|
|
7
|
+
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
8
|
+
import { composeDependencyMetadata } from "./dependency-metadata.js";
|
|
8
9
|
|
|
9
10
|
//#region src/modifiers.ts
|
|
10
|
-
function withChildExecPath(exec, segment) {
|
|
11
|
-
if (exec == null) return void 0;
|
|
12
|
-
return {
|
|
13
|
-
...exec,
|
|
14
|
-
path: [...exec.path ?? [], segment]
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function mergeChildExec(parent, child) {
|
|
18
|
-
if (parent == null) return child;
|
|
19
|
-
if (child == null) return parent;
|
|
20
|
-
return {
|
|
21
|
-
...parent,
|
|
22
|
-
trace: child.trace ?? parent.trace,
|
|
23
|
-
dependencyRuntime: child.dependencyRuntime ?? parent.dependencyRuntime,
|
|
24
|
-
dependencyRegistry: child.dependencyRegistry ?? parent.dependencyRegistry,
|
|
25
|
-
commandPath: child.commandPath ?? parent.commandPath,
|
|
26
|
-
preCompletedByParser: child.preCompletedByParser ?? parent.preCompletedByParser,
|
|
27
|
-
excludedSourceFields: child.excludedSourceFields ?? parent.excludedSourceFields
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function withChildContext(context, segment, state) {
|
|
31
|
-
const exec = withChildExecPath(context.exec, segment);
|
|
32
|
-
const dependencyRegistry = context.dependencyRegistry ?? exec?.dependencyRegistry;
|
|
33
|
-
return {
|
|
34
|
-
...context,
|
|
35
|
-
state,
|
|
36
|
-
...exec != null ? {
|
|
37
|
-
exec: dependencyRegistry === exec.dependencyRegistry ? exec : {
|
|
38
|
-
...exec,
|
|
39
|
-
dependencyRegistry
|
|
40
|
-
},
|
|
41
|
-
dependencyRegistry
|
|
42
|
-
} : {}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
11
|
function isTerminalMultipleItemState(state) {
|
|
46
12
|
const unwrapped = unwrapMultipleItemState(state).value;
|
|
47
13
|
return unwrapped != null && typeof unwrapped === "object" && Object.hasOwn(unwrapped, "success") && typeof unwrapped.success === "boolean";
|
|
@@ -82,91 +48,105 @@ function unwrapMultipleItemState(state) {
|
|
|
82
48
|
function isPromiseLike(value) {
|
|
83
49
|
return value != null && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
84
50
|
}
|
|
85
|
-
function normalizeOptionalLikeCompleteResult(result) {
|
|
86
|
-
return result.success ? {
|
|
51
|
+
function normalizeOptionalLikeCompleteResult(result, shouldNormalize) {
|
|
52
|
+
return result.success && shouldNormalize ? {
|
|
87
53
|
...result,
|
|
88
54
|
value: normalizeNestedDelegatedAnnotationState(result.value)
|
|
89
55
|
} : result;
|
|
90
56
|
}
|
|
57
|
+
function shouldRetryOptionalLikeCompatibilityError(error, state) {
|
|
58
|
+
return error instanceof TypeError && state != null && typeof state === "object" && isInjectedAnnotationWrapper(state);
|
|
59
|
+
}
|
|
91
60
|
function completeOptionalLikeSync(parser, state, exec) {
|
|
92
61
|
const hasCarrier = hasDelegatedAnnotationCarrier(state);
|
|
93
|
-
const shouldRetryFalseResult = isAnnotationWrappedInitialState(state);
|
|
94
|
-
const run = (candidate) => normalizeOptionalLikeCompleteResult(parser.complete(candidate, exec));
|
|
62
|
+
const shouldRetryFalseResult = hasCarrier && isAnnotationWrappedInitialState(state);
|
|
63
|
+
const run = (candidate, shouldNormalize) => normalizeOptionalLikeCompleteResult(parser.complete(candidate, exec), shouldNormalize);
|
|
95
64
|
try {
|
|
96
|
-
const result = run(state);
|
|
97
|
-
if (!result.success && shouldRetryFalseResult) return run(normalizeDelegatedAnnotationState(state));
|
|
65
|
+
const result = run(state, hasCarrier);
|
|
66
|
+
if (!result.success && shouldRetryFalseResult) return run(normalizeDelegatedAnnotationState(state), false);
|
|
98
67
|
return result;
|
|
99
68
|
} catch (error) {
|
|
100
|
-
if (!
|
|
101
|
-
return run(normalizeDelegatedAnnotationState(state));
|
|
69
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, state)) throw error;
|
|
70
|
+
return run(normalizeDelegatedAnnotationState(state), false);
|
|
102
71
|
}
|
|
103
72
|
}
|
|
104
73
|
async function completeOptionalLikeAsync(parser, state, exec) {
|
|
105
74
|
const hasCarrier = hasDelegatedAnnotationCarrier(state);
|
|
106
|
-
const shouldRetryFalseResult = isAnnotationWrappedInitialState(state);
|
|
107
|
-
const run = async (candidate) => normalizeOptionalLikeCompleteResult(await parser.complete(candidate, exec));
|
|
75
|
+
const shouldRetryFalseResult = hasCarrier && isAnnotationWrappedInitialState(state);
|
|
76
|
+
const run = async (candidate, shouldNormalize) => normalizeOptionalLikeCompleteResult(await parser.complete(candidate, exec), shouldNormalize);
|
|
108
77
|
try {
|
|
109
|
-
const result = await run(state);
|
|
110
|
-
if (!result.success && shouldRetryFalseResult) return await run(normalizeDelegatedAnnotationState(state));
|
|
78
|
+
const result = await run(state, hasCarrier);
|
|
79
|
+
if (!result.success && shouldRetryFalseResult) return await run(normalizeDelegatedAnnotationState(state), false);
|
|
111
80
|
return result;
|
|
112
81
|
} catch (error) {
|
|
113
|
-
if (!
|
|
114
|
-
return await run(normalizeDelegatedAnnotationState(state));
|
|
82
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, state)) throw error;
|
|
83
|
+
return await run(normalizeDelegatedAnnotationState(state), false);
|
|
115
84
|
}
|
|
116
85
|
}
|
|
117
|
-
function normalizeOptionalLikePhase2Seed(seed) {
|
|
118
|
-
return seed == null ? null : {
|
|
86
|
+
function normalizeOptionalLikePhase2Seed(seed, shouldNormalize) {
|
|
87
|
+
return seed == null ? null : shouldNormalize ? {
|
|
119
88
|
...seed,
|
|
120
89
|
value: normalizeNestedDelegatedAnnotationState(seed.value)
|
|
121
|
-
};
|
|
90
|
+
} : seed;
|
|
122
91
|
}
|
|
123
92
|
function extractOptionalLikePhase2Seed(parser, state, exec) {
|
|
124
|
-
if (!Array.isArray(state) && !(state != null && typeof state === "object")) return wrapForMode(parser
|
|
93
|
+
if (!Array.isArray(state) && !(state != null && typeof state === "object")) return wrapForMode(parser.mode, null);
|
|
125
94
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
126
95
|
const hasCarrier = hasDelegatedAnnotationCarrier(innerState);
|
|
127
|
-
|
|
96
|
+
const shouldRetryFalseResult = hasCarrier && isAnnotationWrappedInitialState(innerState);
|
|
97
|
+
return dispatchByMode(parser.mode, () => {
|
|
128
98
|
try {
|
|
129
99
|
const result = parser.complete(innerState, exec);
|
|
130
|
-
if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result));
|
|
100
|
+
if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result), hasCarrier);
|
|
101
|
+
if (shouldRetryFalseResult) {
|
|
102
|
+
const fallbackState = normalizeDelegatedAnnotationState(innerState);
|
|
103
|
+
const fallbackResult = parser.complete(fallbackState, exec);
|
|
104
|
+
if (fallbackResult.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(fallbackResult), false);
|
|
105
|
+
}
|
|
131
106
|
const seed = extractPhase2Seed(parser, innerState, exec);
|
|
132
107
|
if (seed == null && hasCarrier) {
|
|
133
108
|
const fallbackState = normalizeDelegatedAnnotationState(innerState);
|
|
134
|
-
return normalizeOptionalLikePhase2Seed(extractPhase2Seed(parser, fallbackState, exec));
|
|
109
|
+
return normalizeOptionalLikePhase2Seed(extractPhase2Seed(parser, fallbackState, exec), false);
|
|
135
110
|
}
|
|
136
|
-
return normalizeOptionalLikePhase2Seed(seed);
|
|
111
|
+
return normalizeOptionalLikePhase2Seed(seed, hasCarrier);
|
|
137
112
|
} catch (error) {
|
|
138
|
-
if (!
|
|
113
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, innerState)) throw error;
|
|
139
114
|
const fallbackState = normalizeDelegatedAnnotationState(innerState);
|
|
140
115
|
const result = parser.complete(fallbackState, exec);
|
|
141
|
-
if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result));
|
|
142
|
-
return normalizeOptionalLikePhase2Seed(extractPhase2Seed(parser, fallbackState, exec));
|
|
116
|
+
if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result), false);
|
|
117
|
+
return normalizeOptionalLikePhase2Seed(extractPhase2Seed(parser, fallbackState, exec), false);
|
|
143
118
|
}
|
|
144
119
|
}, async () => {
|
|
145
120
|
try {
|
|
146
121
|
const result = await parser.complete(innerState, exec);
|
|
147
|
-
if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result));
|
|
122
|
+
if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result), hasCarrier);
|
|
123
|
+
if (shouldRetryFalseResult) {
|
|
124
|
+
const fallbackState = normalizeDelegatedAnnotationState(innerState);
|
|
125
|
+
const fallbackResult = await parser.complete(fallbackState, exec);
|
|
126
|
+
if (fallbackResult.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(fallbackResult), false);
|
|
127
|
+
}
|
|
148
128
|
const seed = await extractPhase2Seed(parser, innerState, exec);
|
|
149
129
|
if (seed == null && hasCarrier) {
|
|
150
130
|
const fallbackState = normalizeDelegatedAnnotationState(innerState);
|
|
151
|
-
return normalizeOptionalLikePhase2Seed(await extractPhase2Seed(parser, fallbackState, exec));
|
|
131
|
+
return normalizeOptionalLikePhase2Seed(await extractPhase2Seed(parser, fallbackState, exec), false);
|
|
152
132
|
}
|
|
153
|
-
return normalizeOptionalLikePhase2Seed(seed);
|
|
133
|
+
return normalizeOptionalLikePhase2Seed(seed, hasCarrier);
|
|
154
134
|
} catch (error) {
|
|
155
|
-
if (!
|
|
135
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, innerState)) throw error;
|
|
156
136
|
const fallbackState = normalizeDelegatedAnnotationState(innerState);
|
|
157
137
|
const result = await parser.complete(fallbackState, exec);
|
|
158
|
-
if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result));
|
|
159
|
-
return normalizeOptionalLikePhase2Seed(await extractPhase2Seed(parser, fallbackState, exec));
|
|
138
|
+
if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result), false);
|
|
139
|
+
return normalizeOptionalLikePhase2Seed(await extractPhase2Seed(parser, fallbackState, exec), false);
|
|
160
140
|
}
|
|
161
141
|
});
|
|
162
142
|
}
|
|
163
143
|
/**
|
|
164
144
|
* Computes the inner state to pass through to the wrapped parser inside
|
|
165
145
|
* {@link optional} / {@link withDefault}. When the outer state is an
|
|
166
|
-
* array, the inner state is `state[0]`. Otherwise
|
|
146
|
+
* array, the inner state is `state[0]`. Otherwise, including the
|
|
167
147
|
* common case where `optional()` sits at top level and the outer state
|
|
168
148
|
* is either `undefined` or an annotation wrapper from `parseOptionalLike`
|
|
169
|
-
* / `parse({ annotations })
|
|
149
|
+
* / `parse({ annotations })`, we use the wrapped parser's
|
|
170
150
|
* `initialState`, propagating annotations from the outer state so that
|
|
171
151
|
* source-binding wrappers under `optional()` / `withDefault()` (e.g.,
|
|
172
152
|
* `bindEnv()` / `bindConfig()`) can resolve their fallbacks.
|
|
@@ -176,19 +156,19 @@ function extractOptionalLikePhase2Seed(parser, state, exec) {
|
|
|
176
156
|
function deriveOptionalInnerParseState(outerState, parser) {
|
|
177
157
|
if (Array.isArray(outerState)) {
|
|
178
158
|
const innerState = outerState[0];
|
|
179
|
-
if (getAnnotations(outerState) != null && innerState != null && typeof innerState === "object") return
|
|
159
|
+
if (getAnnotations(outerState) != null && innerState != null && typeof innerState === "object") return getDelegatedAnnotationState(outerState, innerState);
|
|
180
160
|
return innerState;
|
|
181
161
|
}
|
|
182
162
|
const initial = parser.initialState;
|
|
183
163
|
if (initial != null && typeof initial !== "object") return initial;
|
|
184
|
-
return inheritAnnotations(outerState, initial);
|
|
164
|
+
return initial != null && typeof initial === "object" ? getDelegatedAnnotationState(outerState, initial) : inheritAnnotations(outerState, initial);
|
|
185
165
|
}
|
|
186
166
|
/**
|
|
187
167
|
* Internal helper for optional-style parsing logic shared by optional()
|
|
188
168
|
* and withDefault(). Handles the common pattern of:
|
|
189
169
|
* - Unwrapping optional state to inner parser state
|
|
190
|
-
* - Detecting if inner parser actually matched (state changed or no consumption)
|
|
191
|
-
* - Returning success with undefined state when inner parser fails without consuming
|
|
170
|
+
* - Detecting if the inner parser actually matched (state changed or no consumption)
|
|
171
|
+
* - Returning success with undefined state when the inner parser fails without consuming
|
|
192
172
|
* @internal
|
|
193
173
|
*/
|
|
194
174
|
function parseOptionalStyleSync(context, parser) {
|
|
@@ -215,9 +195,12 @@ async function parseOptionalStyleAsync(context, parser) {
|
|
|
215
195
|
* Internal helper to process optional-style parse results.
|
|
216
196
|
* @internal
|
|
217
197
|
*/
|
|
198
|
+
function hasOptionalLikeParseStateChanged(previousState, nextState) {
|
|
199
|
+
return previousState !== nextState && normalizeDelegatedAnnotationState(previousState) !== normalizeDelegatedAnnotationState(nextState);
|
|
200
|
+
}
|
|
218
201
|
function processOptionalStyleResult(result, innerState, context) {
|
|
219
202
|
if (result.success) {
|
|
220
|
-
if (result.next.state
|
|
203
|
+
if (hasOptionalLikeParseStateChanged(innerState, result.next.state) || result.consumed.length === 0) return {
|
|
221
204
|
success: true,
|
|
222
205
|
...result.provisional ? { provisional: true } : {},
|
|
223
206
|
next: {
|
|
@@ -249,7 +232,7 @@ function processOptionalStyleResult(result, innerState, context) {
|
|
|
249
232
|
* {@link withDefault} before delegating to the inner parser's hook.
|
|
250
233
|
*
|
|
251
234
|
* When state is an array, the adapter unwraps `state[0]` and propagates
|
|
252
|
-
* annotations from the outer array. Non-array objects (e.g
|
|
235
|
+
* annotations from the outer array. Non-array objects (e.g. PromptBindState
|
|
253
236
|
* from `prompt()`) are passed through directly. `undefined` returns `false`
|
|
254
237
|
* without calling the inner hook.
|
|
255
238
|
*
|
|
@@ -266,7 +249,7 @@ function adaptShouldDeferCompletion(innerCheck, parser) {
|
|
|
266
249
|
if (!result && shouldRetryFalseResult) return innerCheck(normalizeDelegatedAnnotationState(innerState), exec);
|
|
267
250
|
return result;
|
|
268
251
|
} catch (error) {
|
|
269
|
-
if (!
|
|
252
|
+
if (!shouldRetryOptionalLikeCompatibilityError(error, innerState)) throw error;
|
|
270
253
|
return innerCheck(normalizeDelegatedAnnotationState(innerState), exec);
|
|
271
254
|
}
|
|
272
255
|
}
|
|
@@ -324,7 +307,7 @@ function optional(parser) {
|
|
|
324
307
|
for await (const s of suggestions) yield s;
|
|
325
308
|
}
|
|
326
309
|
const optionalParser = {
|
|
327
|
-
|
|
310
|
+
mode: parser.mode,
|
|
328
311
|
$valueType: [],
|
|
329
312
|
$stateType: [],
|
|
330
313
|
...parser[unmatchedNonCliDependencySourceStateMarker] === true ? { [unmatchedNonCliDependencySourceStateMarker]: true } : {},
|
|
@@ -355,13 +338,13 @@ function optional(parser) {
|
|
|
355
338
|
return extractOptionalLikePhase2Seed(parser, state, exec);
|
|
356
339
|
},
|
|
357
340
|
parse(context) {
|
|
358
|
-
return dispatchByMode(parser
|
|
341
|
+
return dispatchByMode(parser.mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
359
342
|
},
|
|
360
343
|
complete(state, exec) {
|
|
361
344
|
if (!Array.isArray(state)) {
|
|
362
345
|
const delegateToInner = (resolvedInnerState) => {
|
|
363
|
-
const innerResult = dispatchByMode(parser
|
|
364
|
-
return mapModeValue(parser
|
|
346
|
+
const innerResult = dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, resolvedInnerState, exec), async () => await completeOptionalLikeAsync(parser, resolvedInnerState, exec));
|
|
347
|
+
return mapModeValue(parser.mode, innerResult, (result) => result.success ? result : {
|
|
365
348
|
success: true,
|
|
366
349
|
value: void 0
|
|
367
350
|
});
|
|
@@ -373,7 +356,7 @@ function optional(parser) {
|
|
|
373
356
|
const sourceMetadata = parser.dependencyMetadata?.source;
|
|
374
357
|
if (sourceMetadata?.preservesSourceValue !== false && sourceMetadata?.getMissingSourceValue != null) {
|
|
375
358
|
const delegatedState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
376
|
-
return dispatchByMode(parser
|
|
359
|
+
return dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, delegatedState, exec), async () => await completeOptionalLikeAsync(parser, delegatedState, exec));
|
|
377
360
|
}
|
|
378
361
|
if (parser[unmatchedNonCliDependencySourceStateMarker] === true && state != null && typeof state === "object") {
|
|
379
362
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
@@ -385,10 +368,10 @@ function optional(parser) {
|
|
|
385
368
|
};
|
|
386
369
|
}
|
|
387
370
|
const innerElement = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
388
|
-
return dispatchByMode(parser
|
|
371
|
+
return dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerElement, exec), async () => await completeOptionalLikeAsync(parser, innerElement, exec));
|
|
389
372
|
},
|
|
390
373
|
suggest(context, prefix) {
|
|
391
|
-
return dispatchIterableByMode(parser
|
|
374
|
+
return dispatchIterableByMode(parser.mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
392
375
|
},
|
|
393
376
|
getDocFragments(state, defaultValue) {
|
|
394
377
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
|
|
@@ -413,7 +396,7 @@ function optional(parser) {
|
|
|
413
396
|
const innerValidate = parser.validateValue.bind(parser);
|
|
414
397
|
Object.defineProperty(optionalParser, "validateValue", {
|
|
415
398
|
value(v) {
|
|
416
|
-
if (v === void 0) return wrapForMode(parser
|
|
399
|
+
if (v === void 0) return wrapForMode(parser.mode, {
|
|
417
400
|
success: true,
|
|
418
401
|
value: v
|
|
419
402
|
});
|
|
@@ -493,7 +476,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
493
476
|
for await (const s of suggestions) yield s;
|
|
494
477
|
}
|
|
495
478
|
const withDefaultParser = {
|
|
496
|
-
|
|
479
|
+
mode: parser.mode,
|
|
497
480
|
$valueType: [],
|
|
498
481
|
$stateType: [],
|
|
499
482
|
...parser[unmatchedNonCliDependencySourceStateMarker] === true ? { [unmatchedNonCliDependencySourceStateMarker]: true } : {},
|
|
@@ -523,7 +506,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
523
506
|
return extractOptionalLikePhase2Seed(parser, state, exec);
|
|
524
507
|
},
|
|
525
508
|
parse(context) {
|
|
526
|
-
return dispatchByMode(parser
|
|
509
|
+
return dispatchByMode(parser.mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
527
510
|
},
|
|
528
511
|
complete(state, exec) {
|
|
529
512
|
function evaluateDefault() {
|
|
@@ -536,12 +519,12 @@ function withDefault(parser, defaultValue, options) {
|
|
|
536
519
|
if (!Array.isArray(state)) {
|
|
537
520
|
if (typeof parser.shouldDeferCompletion === "function" && state != null && typeof state === "object") {
|
|
538
521
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
539
|
-
const innerResult = dispatchByMode(parser
|
|
522
|
+
const innerResult = dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerState, exec), async () => await completeOptionalLikeAsync(parser, innerState, exec));
|
|
540
523
|
return innerResult;
|
|
541
524
|
}
|
|
542
525
|
if (parser[unmatchedNonCliDependencySourceStateMarker] === true && state != null && typeof state === "object") {
|
|
543
526
|
const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
544
|
-
const innerResult = dispatchByMode(parser
|
|
527
|
+
const innerResult = dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerState, exec), async () => await completeOptionalLikeAsync(parser, innerState, exec));
|
|
545
528
|
const handleInnerResult = (result) => {
|
|
546
529
|
if (result.success && result.value !== void 0) return result;
|
|
547
530
|
try {
|
|
@@ -556,7 +539,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
556
539
|
};
|
|
557
540
|
}
|
|
558
541
|
};
|
|
559
|
-
return mapModeValue(parser
|
|
542
|
+
return mapModeValue(parser.mode, innerResult, handleInnerResult);
|
|
560
543
|
}
|
|
561
544
|
try {
|
|
562
545
|
const value = evaluateDefault();
|
|
@@ -572,10 +555,10 @@ function withDefault(parser, defaultValue, options) {
|
|
|
572
555
|
}
|
|
573
556
|
}
|
|
574
557
|
const innerElement = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
|
|
575
|
-
return dispatchByMode(parser
|
|
558
|
+
return dispatchByMode(parser.mode, () => completeOptionalLikeSync(syncParser, innerElement, exec), async () => await completeOptionalLikeAsync(parser, innerElement, exec));
|
|
576
559
|
},
|
|
577
560
|
suggest(context, prefix) {
|
|
578
|
-
return dispatchIterableByMode(parser
|
|
561
|
+
return dispatchIterableByMode(parser.mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
579
562
|
},
|
|
580
563
|
getDocFragments(state, upperDefaultValue) {
|
|
581
564
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
|
|
@@ -737,7 +720,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
737
720
|
*/
|
|
738
721
|
function map(parser, transform) {
|
|
739
722
|
const complete = (state, exec) => {
|
|
740
|
-
return mapModeValue(parser
|
|
723
|
+
return mapModeValue(parser.mode, parser.complete(state, exec), (result) => {
|
|
741
724
|
if (!result.success) return result;
|
|
742
725
|
if (result.deferred) try {
|
|
743
726
|
return {
|
|
@@ -763,7 +746,7 @@ function map(parser, transform) {
|
|
|
763
746
|
$valueType: [],
|
|
764
747
|
complete,
|
|
765
748
|
[extractPhase2SeedKey](state, exec) {
|
|
766
|
-
return mapModeValue(parser
|
|
749
|
+
return mapModeValue(parser.mode, completeOrExtractPhase2Seed(parser, state, exec), (seed) => {
|
|
767
750
|
if (seed == null) return null;
|
|
768
751
|
if (seed.deferred) try {
|
|
769
752
|
return {
|
|
@@ -1104,7 +1087,7 @@ function multiple(parser, options = {}) {
|
|
|
1104
1087
|
};
|
|
1105
1088
|
};
|
|
1106
1089
|
const resultParser = {
|
|
1107
|
-
|
|
1090
|
+
mode: parser.mode,
|
|
1108
1091
|
$valueType: [],
|
|
1109
1092
|
$stateType: [],
|
|
1110
1093
|
priority: parser.priority,
|
|
@@ -1125,10 +1108,10 @@ function multiple(parser, options = {}) {
|
|
|
1125
1108
|
}, ...innerNodes] : innerNodes;
|
|
1126
1109
|
},
|
|
1127
1110
|
parse(context) {
|
|
1128
|
-
return dispatchByMode(parser
|
|
1111
|
+
return dispatchByMode(parser.mode, () => parseSync(context), () => parseAsync(context));
|
|
1129
1112
|
},
|
|
1130
1113
|
complete(state, exec) {
|
|
1131
|
-
return dispatchByMode(parser
|
|
1114
|
+
return dispatchByMode(parser.mode, () => {
|
|
1132
1115
|
const result = [];
|
|
1133
1116
|
const deferredIndices = /* @__PURE__ */ new Map();
|
|
1134
1117
|
let hasDeferred = false;
|
|
@@ -1167,7 +1150,7 @@ function multiple(parser, options = {}) {
|
|
|
1167
1150
|
});
|
|
1168
1151
|
},
|
|
1169
1152
|
[extractPhase2SeedKey](state, exec) {
|
|
1170
|
-
return dispatchByMode(parser
|
|
1153
|
+
return dispatchByMode(parser.mode, () => {
|
|
1171
1154
|
const values = [];
|
|
1172
1155
|
const deferredIndices = /* @__PURE__ */ new Map();
|
|
1173
1156
|
let hasDeferred = false;
|
|
@@ -1217,7 +1200,7 @@ function multiple(parser, options = {}) {
|
|
|
1217
1200
|
const currentItemState = context.state.at(-1);
|
|
1218
1201
|
const canExtendCurrent = currentItemState != null && !isTerminalMultipleItemState(currentItemState);
|
|
1219
1202
|
const canOpenNew = context.state.length < max;
|
|
1220
|
-
if (!canExtendCurrent && !canOpenNew) return dispatchIterableByMode(parser
|
|
1203
|
+
if (!canExtendCurrent && !canOpenNew) return dispatchIterableByMode(parser.mode, function* () {}, async function* () {});
|
|
1221
1204
|
const itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
|
|
1222
1205
|
const suggestInitialState = canExtendCurrent ? currentItemState : inheritAnnotations(context.state, parser.initialState);
|
|
1223
1206
|
const suggestFallbackState = unwrapInjectedWrapper(suggestInitialState);
|
|
@@ -1260,7 +1243,7 @@ function multiple(parser, options = {}) {
|
|
|
1260
1243
|
description
|
|
1261
1244
|
]);
|
|
1262
1245
|
};
|
|
1263
|
-
return dispatchIterableByMode(parser
|
|
1246
|
+
return dispatchIterableByMode(parser.mode, function* () {
|
|
1264
1247
|
const selectedValues = collectSelectedValuesSync();
|
|
1265
1248
|
const emitted = /* @__PURE__ */ new Set();
|
|
1266
1249
|
const yieldUnique = function* (suggestions) {
|
|
@@ -1393,15 +1376,15 @@ function multiple(parser, options = {}) {
|
|
|
1393
1376
|
value(values) {
|
|
1394
1377
|
if (!Array.isArray(values)) {
|
|
1395
1378
|
const actualType = values === null ? "null" : typeof values;
|
|
1396
|
-
return wrapForMode(parser
|
|
1379
|
+
return wrapForMode(parser.mode, {
|
|
1397
1380
|
success: false,
|
|
1398
1381
|
error: message`Expected an array of values, but received ${actualType}.`
|
|
1399
1382
|
});
|
|
1400
1383
|
}
|
|
1401
1384
|
const arity = validateArity(values);
|
|
1402
|
-
if (!arity.success) return wrapForMode(parser
|
|
1403
|
-
if (innerValidate == null) return wrapForMode(parser
|
|
1404
|
-
return dispatchByMode(parser
|
|
1385
|
+
if (!arity.success) return wrapForMode(parser.mode, arity);
|
|
1386
|
+
if (innerValidate == null) return wrapForMode(parser.mode, arity);
|
|
1387
|
+
return dispatchByMode(parser.mode, () => {
|
|
1405
1388
|
let changed = false;
|
|
1406
1389
|
const normalized = [];
|
|
1407
1390
|
for (const v of values) {
|
|
@@ -1519,7 +1502,7 @@ function nonEmpty(parser) {
|
|
|
1519
1502
|
return processNonEmptyResult(result);
|
|
1520
1503
|
};
|
|
1521
1504
|
const nonEmptyParser = {
|
|
1522
|
-
|
|
1505
|
+
mode: parser.mode,
|
|
1523
1506
|
$valueType: parser.$valueType,
|
|
1524
1507
|
$stateType: parser.$stateType,
|
|
1525
1508
|
priority: parser.priority,
|
|
@@ -1536,7 +1519,7 @@ function nonEmpty(parser) {
|
|
|
1536
1519
|
}] : []);
|
|
1537
1520
|
},
|
|
1538
1521
|
parse(context) {
|
|
1539
|
-
return dispatchByMode(parser
|
|
1522
|
+
return dispatchByMode(parser.mode, () => parseSync(context), () => parseAsync(context));
|
|
1540
1523
|
},
|
|
1541
1524
|
complete(state, exec) {
|
|
1542
1525
|
return parser.complete(state, exec);
|