@optique/core 1.0.0-dev.1891 → 1.0.0-dev.1895

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.
@@ -87,6 +87,83 @@ function normalizeDelegatedAnnotationState(state) {
87
87
  function hasDelegatedAnnotationCarrier(state) {
88
88
  return state != null && typeof state === "object" && (require_annotations.isInjectedAnnotationWrapper(state) || annotationViewTargets.has(state));
89
89
  }
90
+ function isPendingNestedNormalizationAlias(originalValue, normalizedValue, seen) {
91
+ if (originalValue == null || typeof originalValue !== "object") return false;
92
+ const entry = seen.get(originalValue);
93
+ return entry != null && !entry.finalized && entry.clone === normalizedValue;
94
+ }
95
+ /**
96
+ * Recursively removes delegated annotation carriers from plain-object and array
97
+ * structures.
98
+ *
99
+ * Nested plain objects and arrays are shallow-cloned only when a delegated
100
+ * carrier is found below them. Non-plain objects are unwrapped at the top
101
+ * level and then preserved as-is to avoid mutating or reconstructing class
102
+ * instances.
103
+ *
104
+ * @param value The candidate value to normalize.
105
+ * @param seen Tracks already-normalized objects so cyclic values keep their
106
+ * shape.
107
+ * @returns The original value when no delegated carriers are present, or a
108
+ * normalized clone with delegated carriers removed.
109
+ * @internal
110
+ */
111
+ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ new WeakMap()) {
112
+ const normalized = normalizeDelegatedAnnotationState(value);
113
+ if (normalized == null || typeof normalized !== "object") return normalized;
114
+ const source = normalized;
115
+ const existing = seen.get(source);
116
+ if (existing != null) return existing.finalized ? existing.result : existing.clone;
117
+ if (Array.isArray(source)) {
118
+ let changed$1 = false;
119
+ const clone$1 = require_annotations.annotateFreshArray(source, source.slice());
120
+ const entry$1 = {
121
+ clone: clone$1,
122
+ finalized: false,
123
+ result: clone$1
124
+ };
125
+ seen.set(source, entry$1);
126
+ for (let i = 0; i < source.length; i++) {
127
+ const nextValue = normalizeNestedDelegatedAnnotationState(source[i], seen);
128
+ if (nextValue !== source[i]) {
129
+ clone$1[i] = nextValue;
130
+ if (!isPendingNestedNormalizationAlias(source[i], nextValue, seen)) changed$1 = true;
131
+ }
132
+ }
133
+ entry$1.finalized = true;
134
+ entry$1.result = changed$1 ? clone$1 : source;
135
+ return changed$1 ? clone$1 : source;
136
+ }
137
+ const proto = Object.getPrototypeOf(source);
138
+ if (proto !== Object.prototype && proto !== null) return normalized;
139
+ const descriptors = Object.getOwnPropertyDescriptors(source);
140
+ let changed = false;
141
+ const clone = Object.create(proto);
142
+ const entry = {
143
+ clone,
144
+ finalized: false,
145
+ result: clone
146
+ };
147
+ seen.set(source, entry);
148
+ for (const key of Reflect.ownKeys(descriptors)) {
149
+ const descriptor = descriptors[key];
150
+ if (descriptor != null && "value" in descriptor) {
151
+ const nextValue = normalizeNestedDelegatedAnnotationState(descriptor.value, seen);
152
+ if (nextValue !== descriptor.value) {
153
+ descriptors[key] = {
154
+ ...descriptor,
155
+ value: nextValue
156
+ };
157
+ if (!isPendingNestedNormalizationAlias(descriptor.value, nextValue, seen)) changed = true;
158
+ }
159
+ }
160
+ }
161
+ entry.finalized = true;
162
+ entry.result = changed ? clone : source;
163
+ if (!changed) return source;
164
+ Object.defineProperties(clone, descriptors);
165
+ return clone;
166
+ }
90
167
  /**
91
168
  * Creates a short-lived delegated state that exposes the parent's annotations
92
169
  * regardless of the child state's runtime shape.
@@ -103,9 +180,10 @@ function hasDelegatedAnnotationCarrier(state) {
103
180
  */
104
181
  function getDelegatedAnnotationState(parentState, childState) {
105
182
  const annotations = require_annotations.getAnnotations(parentState);
106
- if (annotations === void 0 || require_annotations.getAnnotations(childState) === annotations) return childState;
183
+ if (annotations === void 0) return childState;
184
+ if (require_annotations.isInjectedAnnotationWrapper(childState)) return require_annotations.injectAnnotations(normalizeInjectedAnnotationState(childState), annotations);
185
+ if (require_annotations.getAnnotations(childState) === annotations) return childState;
107
186
  if (childState == null || typeof childState !== "object") return require_annotations.injectAnnotations(childState, annotations);
108
- if (require_annotations.isInjectedAnnotationWrapper(childState)) return require_annotations.injectAnnotations(childState, annotations);
109
187
  if (isNonPlainDelegatedObject(childState)) return withAnnotationView(childState, annotations);
110
188
  return require_annotations.inheritAnnotations(parentState, childState);
111
189
  }
@@ -201,5 +279,6 @@ exports.hasDelegatedAnnotationCarrier = hasDelegatedAnnotationCarrier;
201
279
  exports.isAnnotationWrappedInitialState = isAnnotationWrappedInitialState;
202
280
  exports.normalizeDelegatedAnnotationState = normalizeDelegatedAnnotationState;
203
281
  exports.normalizeInjectedAnnotationState = normalizeInjectedAnnotationState;
282
+ exports.normalizeNestedDelegatedAnnotationState = normalizeNestedDelegatedAnnotationState;
204
283
  exports.reconcileObjectChildState = reconcileObjectChildState;
205
284
  exports.unwrapAnnotationView = unwrapAnnotationView;
@@ -1,4 +1,4 @@
1
- import { annotationKey, getAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
1
+ import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
2
2
  import { inheritParentAnnotationsKey } from "./parser.js";
3
3
 
4
4
  //#region src/annotation-state.ts
@@ -87,6 +87,83 @@ function normalizeDelegatedAnnotationState(state) {
87
87
  function hasDelegatedAnnotationCarrier(state) {
88
88
  return state != null && typeof state === "object" && (isInjectedAnnotationWrapper(state) || annotationViewTargets.has(state));
89
89
  }
90
+ function isPendingNestedNormalizationAlias(originalValue, normalizedValue, seen) {
91
+ if (originalValue == null || typeof originalValue !== "object") return false;
92
+ const entry = seen.get(originalValue);
93
+ return entry != null && !entry.finalized && entry.clone === normalizedValue;
94
+ }
95
+ /**
96
+ * Recursively removes delegated annotation carriers from plain-object and array
97
+ * structures.
98
+ *
99
+ * Nested plain objects and arrays are shallow-cloned only when a delegated
100
+ * carrier is found below them. Non-plain objects are unwrapped at the top
101
+ * level and then preserved as-is to avoid mutating or reconstructing class
102
+ * instances.
103
+ *
104
+ * @param value The candidate value to normalize.
105
+ * @param seen Tracks already-normalized objects so cyclic values keep their
106
+ * shape.
107
+ * @returns The original value when no delegated carriers are present, or a
108
+ * normalized clone with delegated carriers removed.
109
+ * @internal
110
+ */
111
+ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ new WeakMap()) {
112
+ const normalized = normalizeDelegatedAnnotationState(value);
113
+ if (normalized == null || typeof normalized !== "object") return normalized;
114
+ const source = normalized;
115
+ const existing = seen.get(source);
116
+ if (existing != null) return existing.finalized ? existing.result : existing.clone;
117
+ if (Array.isArray(source)) {
118
+ let changed$1 = false;
119
+ const clone$1 = annotateFreshArray(source, source.slice());
120
+ const entry$1 = {
121
+ clone: clone$1,
122
+ finalized: false,
123
+ result: clone$1
124
+ };
125
+ seen.set(source, entry$1);
126
+ for (let i = 0; i < source.length; i++) {
127
+ const nextValue = normalizeNestedDelegatedAnnotationState(source[i], seen);
128
+ if (nextValue !== source[i]) {
129
+ clone$1[i] = nextValue;
130
+ if (!isPendingNestedNormalizationAlias(source[i], nextValue, seen)) changed$1 = true;
131
+ }
132
+ }
133
+ entry$1.finalized = true;
134
+ entry$1.result = changed$1 ? clone$1 : source;
135
+ return changed$1 ? clone$1 : source;
136
+ }
137
+ const proto = Object.getPrototypeOf(source);
138
+ if (proto !== Object.prototype && proto !== null) return normalized;
139
+ const descriptors = Object.getOwnPropertyDescriptors(source);
140
+ let changed = false;
141
+ const clone = Object.create(proto);
142
+ const entry = {
143
+ clone,
144
+ finalized: false,
145
+ result: clone
146
+ };
147
+ seen.set(source, entry);
148
+ for (const key of Reflect.ownKeys(descriptors)) {
149
+ const descriptor = descriptors[key];
150
+ if (descriptor != null && "value" in descriptor) {
151
+ const nextValue = normalizeNestedDelegatedAnnotationState(descriptor.value, seen);
152
+ if (nextValue !== descriptor.value) {
153
+ descriptors[key] = {
154
+ ...descriptor,
155
+ value: nextValue
156
+ };
157
+ if (!isPendingNestedNormalizationAlias(descriptor.value, nextValue, seen)) changed = true;
158
+ }
159
+ }
160
+ }
161
+ entry.finalized = true;
162
+ entry.result = changed ? clone : source;
163
+ if (!changed) return source;
164
+ Object.defineProperties(clone, descriptors);
165
+ return clone;
166
+ }
90
167
  /**
91
168
  * Creates a short-lived delegated state that exposes the parent's annotations
92
169
  * regardless of the child state's runtime shape.
@@ -103,9 +180,10 @@ function hasDelegatedAnnotationCarrier(state) {
103
180
  */
104
181
  function getDelegatedAnnotationState(parentState, childState) {
105
182
  const annotations = getAnnotations(parentState);
106
- if (annotations === void 0 || getAnnotations(childState) === annotations) return childState;
183
+ if (annotations === void 0) return childState;
184
+ if (isInjectedAnnotationWrapper(childState)) return injectAnnotations(normalizeInjectedAnnotationState(childState), annotations);
185
+ if (getAnnotations(childState) === annotations) return childState;
107
186
  if (childState == null || typeof childState !== "object") return injectAnnotations(childState, annotations);
108
- if (isInjectedAnnotationWrapper(childState)) return injectAnnotations(childState, annotations);
109
187
  if (isNonPlainDelegatedObject(childState)) return withAnnotationView(childState, annotations);
110
188
  return inheritAnnotations(parentState, childState);
111
189
  }
@@ -193,4 +271,4 @@ function reconcileObjectChildState(parentState, childState) {
193
271
  }
194
272
 
195
273
  //#endregion
196
- export { annotationViewTargets, getDelegatedAnnotationState, getWrappedChildParseState, getWrappedChildState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeInjectedAnnotationState, reconcileObjectChildState, unwrapAnnotationView };
274
+ export { annotationViewTargets, getDelegatedAnnotationState, getWrappedChildParseState, getWrappedChildState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeInjectedAnnotationState, normalizeNestedDelegatedAnnotationState, reconcileObjectChildState, unwrapAnnotationView };
@@ -85,58 +85,72 @@ function isPromiseLike(value) {
85
85
  function normalizeOptionalLikeCompleteResult(result) {
86
86
  return result.success ? {
87
87
  ...result,
88
- value: require_annotation_state.normalizeDelegatedAnnotationState(result.value)
88
+ value: require_annotation_state.normalizeNestedDelegatedAnnotationState(result.value)
89
89
  } : result;
90
90
  }
91
91
  function completeOptionalLikeSync(parser, state, exec) {
92
- const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(state);
92
+ const hasCarrier = require_annotation_state.hasDelegatedAnnotationCarrier(state);
93
93
  try {
94
- const result = parser.complete(state, exec);
95
- if (!result.success && require_annotation_state.hasDelegatedAnnotationCarrier(state)) return normalizeOptionalLikeCompleteResult(parser.complete(fallbackState, exec));
96
- return normalizeOptionalLikeCompleteResult(result);
94
+ return normalizeOptionalLikeCompleteResult(parser.complete(state, exec));
97
95
  } catch (error) {
98
- if (!require_annotation_state.hasDelegatedAnnotationCarrier(state)) throw error;
96
+ if (!hasCarrier) throw error;
97
+ const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(state);
99
98
  return normalizeOptionalLikeCompleteResult(parser.complete(fallbackState, exec));
100
99
  }
101
100
  }
102
101
  async function completeOptionalLikeAsync(parser, state, exec) {
103
- const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(state);
102
+ const hasCarrier = require_annotation_state.hasDelegatedAnnotationCarrier(state);
104
103
  try {
105
- const result = await parser.complete(state, exec);
106
- if (!result.success && require_annotation_state.hasDelegatedAnnotationCarrier(state)) return normalizeOptionalLikeCompleteResult(await parser.complete(fallbackState, exec));
107
- return normalizeOptionalLikeCompleteResult(result);
104
+ return normalizeOptionalLikeCompleteResult(await parser.complete(state, exec));
108
105
  } catch (error) {
109
- if (!require_annotation_state.hasDelegatedAnnotationCarrier(state)) throw error;
106
+ if (!hasCarrier) throw error;
107
+ const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(state);
110
108
  return normalizeOptionalLikeCompleteResult(await parser.complete(fallbackState, exec));
111
109
  }
112
110
  }
113
111
  function normalizeOptionalLikePhase2Seed(seed) {
114
112
  return seed == null ? null : {
115
113
  ...seed,
116
- value: require_annotation_state.normalizeDelegatedAnnotationState(seed.value)
114
+ value: require_annotation_state.normalizeNestedDelegatedAnnotationState(seed.value)
117
115
  };
118
116
  }
119
117
  function extractOptionalLikePhase2Seed(parser, state, exec) {
120
118
  if (!Array.isArray(state) && !(state != null && typeof state === "object")) return require_mode_dispatch.wrapForMode(parser.$mode, null);
121
119
  const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
122
- const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(innerState);
120
+ const hasCarrier = require_annotation_state.hasDelegatedAnnotationCarrier(innerState);
123
121
  return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
124
122
  try {
125
- const seed = require_phase2_seed.completeOrExtractPhase2Seed(parser, innerState, exec);
126
- if (seed == null && require_annotation_state.hasDelegatedAnnotationCarrier(innerState)) return normalizeOptionalLikePhase2Seed(require_phase2_seed.completeOrExtractPhase2Seed(parser, fallbackState, exec));
123
+ const result = parser.complete(innerState, exec);
124
+ if (result.success) return normalizeOptionalLikePhase2Seed(require_phase2_seed.phase2SeedFromValueResult(result));
125
+ const seed = require_phase2_seed.extractPhase2Seed(parser, innerState, exec);
126
+ if (seed == null && hasCarrier) {
127
+ const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(innerState);
128
+ return normalizeOptionalLikePhase2Seed(require_phase2_seed.extractPhase2Seed(parser, fallbackState, exec));
129
+ }
127
130
  return normalizeOptionalLikePhase2Seed(seed);
128
131
  } catch (error) {
129
- if (!require_annotation_state.hasDelegatedAnnotationCarrier(innerState)) throw error;
130
- return normalizeOptionalLikePhase2Seed(require_phase2_seed.completeOrExtractPhase2Seed(parser, fallbackState, exec));
132
+ if (!hasCarrier) throw error;
133
+ const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(innerState);
134
+ const result = parser.complete(fallbackState, exec);
135
+ if (result.success) return normalizeOptionalLikePhase2Seed(require_phase2_seed.phase2SeedFromValueResult(result));
136
+ return normalizeOptionalLikePhase2Seed(require_phase2_seed.extractPhase2Seed(parser, fallbackState, exec));
131
137
  }
132
138
  }, async () => {
133
139
  try {
134
- const seed = await require_phase2_seed.completeOrExtractPhase2Seed(parser, innerState, exec);
135
- if (seed == null && require_annotation_state.hasDelegatedAnnotationCarrier(innerState)) return normalizeOptionalLikePhase2Seed(await require_phase2_seed.completeOrExtractPhase2Seed(parser, fallbackState, exec));
140
+ const result = await parser.complete(innerState, exec);
141
+ if (result.success) return normalizeOptionalLikePhase2Seed(require_phase2_seed.phase2SeedFromValueResult(result));
142
+ const seed = await require_phase2_seed.extractPhase2Seed(parser, innerState, exec);
143
+ if (seed == null && hasCarrier) {
144
+ const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(innerState);
145
+ return normalizeOptionalLikePhase2Seed(await require_phase2_seed.extractPhase2Seed(parser, fallbackState, exec));
146
+ }
136
147
  return normalizeOptionalLikePhase2Seed(seed);
137
148
  } catch (error) {
138
- if (!require_annotation_state.hasDelegatedAnnotationCarrier(innerState)) throw error;
139
- return normalizeOptionalLikePhase2Seed(await require_phase2_seed.completeOrExtractPhase2Seed(parser, fallbackState, exec));
149
+ if (!hasCarrier) throw error;
150
+ const fallbackState = require_annotation_state.normalizeDelegatedAnnotationState(innerState);
151
+ const result = await parser.complete(fallbackState, exec);
152
+ if (result.success) return normalizeOptionalLikePhase2Seed(require_phase2_seed.phase2SeedFromValueResult(result));
153
+ return normalizeOptionalLikePhase2Seed(await require_phase2_seed.extractPhase2Seed(parser, fallbackState, exec));
140
154
  }
141
155
  });
142
156
  }
package/dist/modifiers.js CHANGED
@@ -2,9 +2,9 @@ import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations,
2
2
  import { formatMessage, message, text } from "./message.js";
3
3
  import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } from "./mode-dispatch.js";
4
4
  import { composeDependencyMetadata } from "./dependency-metadata.js";
5
- import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey } from "./phase2-seed.js";
5
+ import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
6
6
  import { defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, unmatchedNonCliDependencySourceStateMarker } from "./parser.js";
7
- import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, normalizeDelegatedAnnotationState } from "./annotation-state.js";
7
+ import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
8
8
 
9
9
  //#region src/modifiers.ts
10
10
  function withChildExecPath(exec, segment) {
@@ -85,58 +85,72 @@ function isPromiseLike(value) {
85
85
  function normalizeOptionalLikeCompleteResult(result) {
86
86
  return result.success ? {
87
87
  ...result,
88
- value: normalizeDelegatedAnnotationState(result.value)
88
+ value: normalizeNestedDelegatedAnnotationState(result.value)
89
89
  } : result;
90
90
  }
91
91
  function completeOptionalLikeSync(parser, state, exec) {
92
- const fallbackState = normalizeDelegatedAnnotationState(state);
92
+ const hasCarrier = hasDelegatedAnnotationCarrier(state);
93
93
  try {
94
- const result = parser.complete(state, exec);
95
- if (!result.success && hasDelegatedAnnotationCarrier(state)) return normalizeOptionalLikeCompleteResult(parser.complete(fallbackState, exec));
96
- return normalizeOptionalLikeCompleteResult(result);
94
+ return normalizeOptionalLikeCompleteResult(parser.complete(state, exec));
97
95
  } catch (error) {
98
- if (!hasDelegatedAnnotationCarrier(state)) throw error;
96
+ if (!hasCarrier) throw error;
97
+ const fallbackState = normalizeDelegatedAnnotationState(state);
99
98
  return normalizeOptionalLikeCompleteResult(parser.complete(fallbackState, exec));
100
99
  }
101
100
  }
102
101
  async function completeOptionalLikeAsync(parser, state, exec) {
103
- const fallbackState = normalizeDelegatedAnnotationState(state);
102
+ const hasCarrier = hasDelegatedAnnotationCarrier(state);
104
103
  try {
105
- const result = await parser.complete(state, exec);
106
- if (!result.success && hasDelegatedAnnotationCarrier(state)) return normalizeOptionalLikeCompleteResult(await parser.complete(fallbackState, exec));
107
- return normalizeOptionalLikeCompleteResult(result);
104
+ return normalizeOptionalLikeCompleteResult(await parser.complete(state, exec));
108
105
  } catch (error) {
109
- if (!hasDelegatedAnnotationCarrier(state)) throw error;
106
+ if (!hasCarrier) throw error;
107
+ const fallbackState = normalizeDelegatedAnnotationState(state);
110
108
  return normalizeOptionalLikeCompleteResult(await parser.complete(fallbackState, exec));
111
109
  }
112
110
  }
113
111
  function normalizeOptionalLikePhase2Seed(seed) {
114
112
  return seed == null ? null : {
115
113
  ...seed,
116
- value: normalizeDelegatedAnnotationState(seed.value)
114
+ value: normalizeNestedDelegatedAnnotationState(seed.value)
117
115
  };
118
116
  }
119
117
  function extractOptionalLikePhase2Seed(parser, state, exec) {
120
118
  if (!Array.isArray(state) && !(state != null && typeof state === "object")) return wrapForMode(parser.$mode, null);
121
119
  const innerState = normalizeOptionalLikeInnerState(state, parser.initialState, parser);
122
- const fallbackState = normalizeDelegatedAnnotationState(innerState);
120
+ const hasCarrier = hasDelegatedAnnotationCarrier(innerState);
123
121
  return dispatchByMode(parser.$mode, () => {
124
122
  try {
125
- const seed = completeOrExtractPhase2Seed(parser, innerState, exec);
126
- if (seed == null && hasDelegatedAnnotationCarrier(innerState)) return normalizeOptionalLikePhase2Seed(completeOrExtractPhase2Seed(parser, fallbackState, exec));
123
+ const result = parser.complete(innerState, exec);
124
+ if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result));
125
+ const seed = extractPhase2Seed(parser, innerState, exec);
126
+ if (seed == null && hasCarrier) {
127
+ const fallbackState = normalizeDelegatedAnnotationState(innerState);
128
+ return normalizeOptionalLikePhase2Seed(extractPhase2Seed(parser, fallbackState, exec));
129
+ }
127
130
  return normalizeOptionalLikePhase2Seed(seed);
128
131
  } catch (error) {
129
- if (!hasDelegatedAnnotationCarrier(innerState)) throw error;
130
- return normalizeOptionalLikePhase2Seed(completeOrExtractPhase2Seed(parser, fallbackState, exec));
132
+ if (!hasCarrier) throw error;
133
+ const fallbackState = normalizeDelegatedAnnotationState(innerState);
134
+ const result = parser.complete(fallbackState, exec);
135
+ if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result));
136
+ return normalizeOptionalLikePhase2Seed(extractPhase2Seed(parser, fallbackState, exec));
131
137
  }
132
138
  }, async () => {
133
139
  try {
134
- const seed = await completeOrExtractPhase2Seed(parser, innerState, exec);
135
- if (seed == null && hasDelegatedAnnotationCarrier(innerState)) return normalizeOptionalLikePhase2Seed(await completeOrExtractPhase2Seed(parser, fallbackState, exec));
140
+ const result = await parser.complete(innerState, exec);
141
+ if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result));
142
+ const seed = await extractPhase2Seed(parser, innerState, exec);
143
+ if (seed == null && hasCarrier) {
144
+ const fallbackState = normalizeDelegatedAnnotationState(innerState);
145
+ return normalizeOptionalLikePhase2Seed(await extractPhase2Seed(parser, fallbackState, exec));
146
+ }
136
147
  return normalizeOptionalLikePhase2Seed(seed);
137
148
  } catch (error) {
138
- if (!hasDelegatedAnnotationCarrier(innerState)) throw error;
139
- return normalizeOptionalLikePhase2Seed(await completeOrExtractPhase2Seed(parser, fallbackState, exec));
149
+ if (!hasCarrier) throw error;
150
+ const fallbackState = normalizeDelegatedAnnotationState(innerState);
151
+ const result = await parser.complete(fallbackState, exec);
152
+ if (result.success) return normalizeOptionalLikePhase2Seed(phase2SeedFromValueResult(result));
153
+ return normalizeOptionalLikePhase2Seed(await extractPhase2Seed(parser, fallbackState, exec));
140
154
  }
141
155
  });
142
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1891+f32e7ae2",
3
+ "version": "1.0.0-dev.1895+42aa2942",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",