@optique/core 1.4.0-dev.2661 → 1.4.0-dev.2664

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.
@@ -28,6 +28,15 @@ function getPassThroughFailure(context, capturePriority$1 = -Infinity) {
28
28
  * @internal
29
29
  */
30
30
  function withPassThroughFailure(context, failure, capturePriority$1 = -Infinity) {
31
+ const incoming = context;
32
+ if (incoming[passThroughFailure]?.own != null) {
33
+ const { own: _own,...hint } = incoming[passThroughFailure];
34
+ const stripped = {
35
+ ...context,
36
+ [passThroughFailure]: hint
37
+ };
38
+ context = stripped;
39
+ }
31
40
  const token = context.buffer[0];
32
41
  const existing = getPassThroughFailure(context);
33
42
  if (existing != null && existing.priority < capturePriority$1) {
@@ -48,11 +57,39 @@ function withPassThroughFailure(context, failure, capturePriority$1 = -Infinity)
48
57
  };
49
58
  return hinted;
50
59
  }
51
- /** Retains a child's rejected option failure only at the parent's cursor. @internal */
60
+ /** Reads locally originated diagnostics at the same cursor. @internal */
61
+ function getOwnConsumingFailure(context) {
62
+ const hinted = context;
63
+ const hint = hinted[passThroughFailure];
64
+ return hint?.buffer === context.buffer && hint.optionsTerminated === context.optionsTerminated ? hint.own : void 0;
65
+ }
66
+ /**
67
+ * Returns a successful child's local diagnostic to its parent without merging
68
+ * its provenance with an inherited sibling diagnostic. Both share a cursor.
69
+ * @internal
70
+ */
71
+ function withReturnedConsumingFailure(context, failure) {
72
+ const next = withPassThroughFailure(context, failure);
73
+ if (failure == null || getPassThroughFailure(next) == null) return next;
74
+ const token = next.buffer[0];
75
+ if (next.optionsTerminated || token == null || token === "--" || !/^[-/+]/.test(token) || failure.failure.consumed < 1) return next;
76
+ const hinted = next;
77
+ const hint = hinted[passThroughFailure];
78
+ if (hint == null) return next;
79
+ const returned = {
80
+ ...next,
81
+ [passThroughFailure]: {
82
+ ...hint,
83
+ own: failure
84
+ }
85
+ };
86
+ return returned;
87
+ }
88
+ /** Retains a child's own rejected option failure at the parent's cursor. @internal */
52
89
  function retainConsumingFailureHint(current, context, next) {
53
90
  if (next.buffer !== context.buffer || next.optionsTerminated !== context.optionsTerminated) return current;
54
- const hint = getPassThroughFailure(next);
55
- return hint == null ? current : retainConsumingFailure(current, hint.failure, hint.priority);
91
+ const own = getOwnConsumingFailure(next);
92
+ return own == null || own === getOwnConsumingFailure(context) ? current : retainConsumingFailure(current, own.failure, own.priority);
56
93
  }
57
94
  const capturePriority = Symbol("capturePriority");
58
95
  /** Checks for capture through usage-preserving wrappers. @internal */
@@ -208,6 +245,24 @@ function delegateKnownCompletion(wrapper, inner) {
208
245
  enumerable: true
209
246
  });
210
247
  }
248
+ /**
249
+ * Installs option and capture inspection from one pure child-state selector.
250
+ * Static children retain capture metadata even when no child is selected yet.
251
+ * Selection must not execute parsing, completion, or user callbacks. Potential
252
+ * alternatives remain candidates until parse-time replay or canSkip resolves
253
+ * them; inspection cannot safely predict opaque custom parser callbacks.
254
+ * @internal
255
+ */
256
+ function defineReachableChildren(parser, children, select) {
257
+ defineOptionMatch(parser, (state, token) => combineOptionMatches(select(state).map((child) => {
258
+ const match = getOptionMatch(child.parser, child.state, token);
259
+ return match == null || !child.continuesCommand ? match : {
260
+ ...match,
261
+ continuesCommand: true
262
+ };
263
+ })));
264
+ definePassThroughPriority(parser, children, (state, token) => combinePassThroughPriorities(select(state).map((child) => getPassThroughPriority(child.parser, child.state, token))));
265
+ }
211
266
 
212
267
  //#endregion
213
- export { combineOptionMatches, combinePassThroughPriorities, defineKnownCompletion, defineKnownCompletionLookup, defineOptionMatch, definePassThroughPriority, delegateKnownCompletion, getKnownCompletion, getOptionMatch, getPassThroughFailure, getPassThroughFailureHint, getPassThroughPriority, hasPassThroughUsage, matchesOptionToken, retainConsumingFailure, retainConsumingFailureHint, withPassThroughFailure };
268
+ export { defineKnownCompletion, defineKnownCompletionLookup, definePassThroughPriority, defineReachableChildren, delegateKnownCompletion, getKnownCompletion, getOptionMatch, getPassThroughFailure, getPassThroughFailureHint, getPassThroughPriority, hasPassThroughUsage, matchesOptionToken, retainConsumingFailure, retainConsumingFailureHint, withPassThroughFailure, withReturnedConsumingFailure };
@@ -480,8 +480,10 @@ function optional(parser) {
480
480
  require_internal_parser.defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
481
481
  require_internal_parser.defineInheritedAnnotationParser(optionalParser);
482
482
  require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
483
- require_passthrough.defineOptionMatch(optionalParser, (state, token) => require_passthrough.getOptionMatch(parser, normalizeOptionalLikeSuggestState(state, parser.initialState, parser), token));
484
- require_passthrough.definePassThroughPriority(optionalParser, [parser], (state, token) => require_passthrough.getPassThroughPriority(parser, normalizeOptionalLikeSuggestState(state, parser.initialState, parser), token));
483
+ require_passthrough.defineReachableChildren(optionalParser, [parser], (state) => [{
484
+ parser,
485
+ state: deriveOptionalInnerParseState(state, parser)
486
+ }]);
485
487
  require_passthrough.defineKnownCompletionLookup(optionalParser, (state) => require_passthrough.getKnownCompletion(parser, deriveOptionalInnerParseState(state, parser)));
486
488
  return fluent(require_short_option.scopeParser(optionalParser, require_short_option.combinedOptionScope([parser])));
487
489
  }
@@ -734,8 +736,10 @@ function withDefault(parser, defaultValue, options) {
734
736
  require_internal_parser.defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
735
737
  require_internal_parser.defineInheritedAnnotationParser(withDefaultParser);
736
738
  require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
737
- require_passthrough.defineOptionMatch(withDefaultParser, (state, token) => require_passthrough.getOptionMatch(parser, normalizeOptionalLikeSuggestState(state, parser.initialState, parser), token));
738
- require_passthrough.definePassThroughPriority(withDefaultParser, [parser], (state, token) => require_passthrough.getPassThroughPriority(parser, normalizeOptionalLikeSuggestState(state, parser.initialState, parser), token));
739
+ require_passthrough.defineReachableChildren(withDefaultParser, [parser], (state) => [{
740
+ parser,
741
+ state: deriveOptionalInnerParseState(state, parser)
742
+ }]);
739
743
  require_passthrough.defineKnownCompletionLookup(withDefaultParser, (state) => require_passthrough.getKnownCompletion(parser, deriveOptionalInnerParseState(state, parser)));
740
744
  return fluent(require_short_option.scopeParser(withDefaultParser, require_short_option.combinedOptionScope([parser])));
741
745
  }
@@ -1195,12 +1199,28 @@ function multiple(parser, options = {}) {
1195
1199
  parser,
1196
1200
  state
1197
1201
  }] : []);
1202
+ const selectItems = (state) => {
1203
+ const current = state.at(-1);
1204
+ return [...current != null && !isTerminalMultipleItemState(current) ? [{
1205
+ parser,
1206
+ state: current,
1207
+ index: state.length - 1,
1208
+ fresh: false
1209
+ }] : [], ...state.length < max ? [{
1210
+ parser,
1211
+ state: parser.initialState,
1212
+ index: state.length,
1213
+ fresh: true
1214
+ }] : []];
1215
+ };
1198
1216
  const canExtendMultipleItem = (state, itemIndex, exec) => state != null && !isTerminalMultipleItemState(state) && (isMatchedCommandParserState(parser, state) || parser.canSkip?.(state, require_execution_context.withChildExecPath(exec, itemIndex)) !== true);
1199
1217
  const parseSync = (context) => {
1200
- const currentItemState = context.state.at(-1);
1201
- const currentItemIndex = context.state.length - 1;
1202
- const canExtendCurrent = canExtendMultipleItem(currentItemState, currentItemIndex, context.exec);
1203
- const canOpenFreshItem = context.state.length < max;
1218
+ const items = selectItems(context.state);
1219
+ const current = items.find((item) => !item.fresh);
1220
+ const fresh = items.find((item) => item.fresh);
1221
+ const currentItemState = current?.state;
1222
+ const canExtendCurrent = current != null && canExtendMultipleItem(current.state, current.index, context.exec);
1223
+ const canOpenFreshItem = fresh != null;
1204
1224
  if (!canExtendCurrent && !canOpenFreshItem) return {
1205
1225
  success: true,
1206
1226
  next: context,
@@ -1208,7 +1228,7 @@ function multiple(parser, options = {}) {
1208
1228
  };
1209
1229
  let added = !canExtendCurrent;
1210
1230
  let itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
1211
- const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : require_internal_annotations.inheritAnnotations(context.state, syncParser.initialState);
1231
+ const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : require_internal_annotations.inheritAnnotations(context.state, fresh?.state ?? parser.initialState);
1212
1232
  let result = parseSyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, currentItemStateWithAnnotations));
1213
1233
  if (!result.success) {
1214
1234
  if (result.consumed !== 0) return result;
@@ -1278,10 +1298,12 @@ function multiple(parser, options = {}) {
1278
1298
  };
1279
1299
  };
1280
1300
  const parseAsync = async (context) => {
1281
- const currentItemState = context.state.at(-1);
1282
- const currentItemIndex = context.state.length - 1;
1283
- const canExtendCurrent = canExtendMultipleItem(currentItemState, currentItemIndex, context.exec);
1284
- const canOpenFreshItem = context.state.length < max;
1301
+ const items = selectItems(context.state);
1302
+ const current = items.find((item) => !item.fresh);
1303
+ const fresh = items.find((item) => item.fresh);
1304
+ const currentItemState = current?.state;
1305
+ const canExtendCurrent = current != null && canExtendMultipleItem(current.state, current.index, context.exec);
1306
+ const canOpenFreshItem = fresh != null;
1285
1307
  if (!canExtendCurrent && !canOpenFreshItem) return {
1286
1308
  success: true,
1287
1309
  next: context,
@@ -1289,7 +1311,7 @@ function multiple(parser, options = {}) {
1289
1311
  };
1290
1312
  let added = !canExtendCurrent;
1291
1313
  let itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
1292
- const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : require_internal_annotations.inheritAnnotations(context.state, parser.initialState);
1314
+ const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : require_internal_annotations.inheritAnnotations(context.state, fresh?.state ?? parser.initialState);
1293
1315
  let result = await parseAsyncWithUnwrappedFallback(require_execution_context.withChildContext(context, itemIndex, currentItemStateWithAnnotations));
1294
1316
  if (!result.success) {
1295
1317
  if (result.consumed !== 0) return result;
@@ -1722,19 +1744,10 @@ function multiple(parser, options = {}) {
1722
1744
  enumerable: false
1723
1745
  });
1724
1746
  }
1725
- const matchingItem = (state) => {
1726
- const current = state.at(-1);
1727
- if (current != null && !isTerminalMultipleItemState(current)) return { state: unwrapInjectedWrapper(current) };
1728
- return state.length < max ? { state: parser.initialState } : void 0;
1729
- };
1730
- require_passthrough.defineOptionMatch(resultParser, (state, token) => {
1731
- const item = matchingItem(state);
1732
- return item == null ? void 0 : require_passthrough.getOptionMatch(parser, item.state, token);
1733
- });
1734
- require_passthrough.definePassThroughPriority(resultParser, [parser], (state, token) => {
1735
- const item = matchingItem(state);
1736
- return item == null ? void 0 : require_passthrough.getPassThroughPriority(parser, item.state, token);
1737
- });
1747
+ require_passthrough.defineReachableChildren(resultParser, [parser], (state) => selectItems(state).map((item) => ({
1748
+ parser,
1749
+ state: unwrapInjectedWrapper(item.state)
1750
+ })));
1738
1751
  return fluent(require_short_option.scopeParser(resultParser, require_short_option.repeatedOptionScope(parser)));
1739
1752
  }
1740
1753
  /**
@@ -1871,8 +1884,10 @@ function nonEmpty(parser) {
1871
1884
  enumerable: false
1872
1885
  });
1873
1886
  require_dependency_runtime.defineForwardedEffectfulSchedulingNodes(nonEmptyParser, parser);
1874
- require_passthrough.defineOptionMatch(nonEmptyParser, (state, token) => require_passthrough.getOptionMatch(parser, state, token));
1875
- require_passthrough.definePassThroughPriority(nonEmptyParser, [parser], (state, token) => require_passthrough.getPassThroughPriority(parser, state, token));
1887
+ require_passthrough.defineReachableChildren(nonEmptyParser, [parser], (state) => [{
1888
+ parser,
1889
+ state
1890
+ }]);
1876
1891
  return fluent(require_short_option.scopeParser(nonEmptyParser, require_short_option.combinedOptionScope([parser])));
1877
1892
  }
1878
1893
  const fluentParserMarker = Symbol.for("@optique/core/fluent");
package/dist/modifiers.js CHANGED
@@ -6,7 +6,7 @@ import { defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingO
6
6
  import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
7
7
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
8
8
  import { combinedOptionScope, repeatedOptionScope, scopeParser } from "./short-option.js";
9
- import { defineKnownCompletionLookup, defineOptionMatch, definePassThroughPriority, getKnownCompletion, getOptionMatch, getPassThroughPriority } from "./internal/passthrough.js";
9
+ import { defineKnownCompletionLookup, defineReachableChildren, getKnownCompletion } from "./internal/passthrough.js";
10
10
  import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
11
11
  import { composeDependencyMetadata } from "./dependency-metadata.js";
12
12
 
@@ -480,8 +480,10 @@ function optional(parser) {
480
480
  defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
481
481
  defineInheritedAnnotationParser(optionalParser);
482
482
  defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
483
- defineOptionMatch(optionalParser, (state, token) => getOptionMatch(parser, normalizeOptionalLikeSuggestState(state, parser.initialState, parser), token));
484
- definePassThroughPriority(optionalParser, [parser], (state, token) => getPassThroughPriority(parser, normalizeOptionalLikeSuggestState(state, parser.initialState, parser), token));
483
+ defineReachableChildren(optionalParser, [parser], (state) => [{
484
+ parser,
485
+ state: deriveOptionalInnerParseState(state, parser)
486
+ }]);
485
487
  defineKnownCompletionLookup(optionalParser, (state) => getKnownCompletion(parser, deriveOptionalInnerParseState(state, parser)));
486
488
  return fluent(scopeParser(optionalParser, combinedOptionScope([parser])));
487
489
  }
@@ -734,8 +736,10 @@ function withDefault(parser, defaultValue, options) {
734
736
  defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
735
737
  defineInheritedAnnotationParser(withDefaultParser);
736
738
  defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
737
- defineOptionMatch(withDefaultParser, (state, token) => getOptionMatch(parser, normalizeOptionalLikeSuggestState(state, parser.initialState, parser), token));
738
- definePassThroughPriority(withDefaultParser, [parser], (state, token) => getPassThroughPriority(parser, normalizeOptionalLikeSuggestState(state, parser.initialState, parser), token));
739
+ defineReachableChildren(withDefaultParser, [parser], (state) => [{
740
+ parser,
741
+ state: deriveOptionalInnerParseState(state, parser)
742
+ }]);
739
743
  defineKnownCompletionLookup(withDefaultParser, (state) => getKnownCompletion(parser, deriveOptionalInnerParseState(state, parser)));
740
744
  return fluent(scopeParser(withDefaultParser, combinedOptionScope([parser])));
741
745
  }
@@ -1195,12 +1199,28 @@ function multiple(parser, options = {}) {
1195
1199
  parser,
1196
1200
  state
1197
1201
  }] : []);
1202
+ const selectItems = (state) => {
1203
+ const current = state.at(-1);
1204
+ return [...current != null && !isTerminalMultipleItemState(current) ? [{
1205
+ parser,
1206
+ state: current,
1207
+ index: state.length - 1,
1208
+ fresh: false
1209
+ }] : [], ...state.length < max ? [{
1210
+ parser,
1211
+ state: parser.initialState,
1212
+ index: state.length,
1213
+ fresh: true
1214
+ }] : []];
1215
+ };
1198
1216
  const canExtendMultipleItem = (state, itemIndex, exec) => state != null && !isTerminalMultipleItemState(state) && (isMatchedCommandParserState(parser, state) || parser.canSkip?.(state, withChildExecPath(exec, itemIndex)) !== true);
1199
1217
  const parseSync = (context) => {
1200
- const currentItemState = context.state.at(-1);
1201
- const currentItemIndex = context.state.length - 1;
1202
- const canExtendCurrent = canExtendMultipleItem(currentItemState, currentItemIndex, context.exec);
1203
- const canOpenFreshItem = context.state.length < max;
1218
+ const items = selectItems(context.state);
1219
+ const current = items.find((item) => !item.fresh);
1220
+ const fresh = items.find((item) => item.fresh);
1221
+ const currentItemState = current?.state;
1222
+ const canExtendCurrent = current != null && canExtendMultipleItem(current.state, current.index, context.exec);
1223
+ const canOpenFreshItem = fresh != null;
1204
1224
  if (!canExtendCurrent && !canOpenFreshItem) return {
1205
1225
  success: true,
1206
1226
  next: context,
@@ -1208,7 +1228,7 @@ function multiple(parser, options = {}) {
1208
1228
  };
1209
1229
  let added = !canExtendCurrent;
1210
1230
  let itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
1211
- const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : inheritAnnotations(context.state, syncParser.initialState);
1231
+ const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : inheritAnnotations(context.state, fresh?.state ?? parser.initialState);
1212
1232
  let result = parseSyncWithUnwrappedFallback(withChildContext(context, itemIndex, currentItemStateWithAnnotations));
1213
1233
  if (!result.success) {
1214
1234
  if (result.consumed !== 0) return result;
@@ -1278,10 +1298,12 @@ function multiple(parser, options = {}) {
1278
1298
  };
1279
1299
  };
1280
1300
  const parseAsync = async (context) => {
1281
- const currentItemState = context.state.at(-1);
1282
- const currentItemIndex = context.state.length - 1;
1283
- const canExtendCurrent = canExtendMultipleItem(currentItemState, currentItemIndex, context.exec);
1284
- const canOpenFreshItem = context.state.length < max;
1301
+ const items = selectItems(context.state);
1302
+ const current = items.find((item) => !item.fresh);
1303
+ const fresh = items.find((item) => item.fresh);
1304
+ const currentItemState = current?.state;
1305
+ const canExtendCurrent = current != null && canExtendMultipleItem(current.state, current.index, context.exec);
1306
+ const canOpenFreshItem = fresh != null;
1285
1307
  if (!canExtendCurrent && !canOpenFreshItem) return {
1286
1308
  success: true,
1287
1309
  next: context,
@@ -1289,7 +1311,7 @@ function multiple(parser, options = {}) {
1289
1311
  };
1290
1312
  let added = !canExtendCurrent;
1291
1313
  let itemIndex = canExtendCurrent ? context.state.length - 1 : context.state.length;
1292
- const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : inheritAnnotations(context.state, parser.initialState);
1314
+ const currentItemStateWithAnnotations = canExtendCurrent ? currentItemState : inheritAnnotations(context.state, fresh?.state ?? parser.initialState);
1293
1315
  let result = await parseAsyncWithUnwrappedFallback(withChildContext(context, itemIndex, currentItemStateWithAnnotations));
1294
1316
  if (!result.success) {
1295
1317
  if (result.consumed !== 0) return result;
@@ -1722,19 +1744,10 @@ function multiple(parser, options = {}) {
1722
1744
  enumerable: false
1723
1745
  });
1724
1746
  }
1725
- const matchingItem = (state) => {
1726
- const current = state.at(-1);
1727
- if (current != null && !isTerminalMultipleItemState(current)) return { state: unwrapInjectedWrapper(current) };
1728
- return state.length < max ? { state: parser.initialState } : void 0;
1729
- };
1730
- defineOptionMatch(resultParser, (state, token) => {
1731
- const item = matchingItem(state);
1732
- return item == null ? void 0 : getOptionMatch(parser, item.state, token);
1733
- });
1734
- definePassThroughPriority(resultParser, [parser], (state, token) => {
1735
- const item = matchingItem(state);
1736
- return item == null ? void 0 : getPassThroughPriority(parser, item.state, token);
1737
- });
1747
+ defineReachableChildren(resultParser, [parser], (state) => selectItems(state).map((item) => ({
1748
+ parser,
1749
+ state: unwrapInjectedWrapper(item.state)
1750
+ })));
1738
1751
  return fluent(scopeParser(resultParser, repeatedOptionScope(parser)));
1739
1752
  }
1740
1753
  /**
@@ -1871,8 +1884,10 @@ function nonEmpty(parser) {
1871
1884
  enumerable: false
1872
1885
  });
1873
1886
  defineForwardedEffectfulSchedulingNodes(nonEmptyParser, parser);
1874
- defineOptionMatch(nonEmptyParser, (state, token) => getOptionMatch(parser, state, token));
1875
- definePassThroughPriority(nonEmptyParser, [parser], (state, token) => getPassThroughPriority(parser, state, token));
1887
+ defineReachableChildren(nonEmptyParser, [parser], (state) => [{
1888
+ parser,
1889
+ state
1890
+ }]);
1876
1891
  return fluent(scopeParser(nonEmptyParser, combinedOptionScope([parser])));
1877
1892
  }
1878
1893
  const fluentParserMarker = Symbol.for("@optique/core/fluent");
@@ -1544,6 +1544,15 @@ function command(name, parser, options = {}) {
1544
1544
  const isAsync = parser.mode === "async";
1545
1545
  const syncInnerParser = parser;
1546
1546
  const asyncInnerParser = parser;
1547
+ const getChildState = (state, active) => getCommandParseChildState(state, active[0] === "matched" ? parser.initialState : active[1], parser);
1548
+ const selectChild = (state) => {
1549
+ const active = normalizeCommandState(state);
1550
+ return active == null ? void 0 : {
1551
+ parser,
1552
+ state: getChildState(state, active),
1553
+ continuesCommand: true
1554
+ };
1555
+ };
1547
1556
  const commandScope = require_short_option.selectableOptionScope(() => /* @__PURE__ */ new Set());
1548
1557
  const enteredScope = require_short_option.combinedOptionScope([parser], [name]);
1549
1558
  const result = {
@@ -1625,7 +1634,7 @@ function command(name, parser, options = {}) {
1625
1634
  consumed: context.buffer.slice(0, 1)
1626
1635
  };
1627
1636
  } else if (state[0] === "matched" || state[0] === "parsing") {
1628
- const innerState = state[0] === "matched" ? getCommandParseChildState(context.state, parser.initialState, parser) : getCommandParseChildState(context.state, state[1], parser);
1637
+ const innerState = getChildState(context.state, state);
1629
1638
  const wrapState = (parseResult) => {
1630
1639
  if (parseResult.success) {
1631
1640
  const mergedExec = require_execution_context.mergeChildExec(context.exec, parseResult.next.exec);
@@ -1794,21 +1803,9 @@ function command(name, parser, options = {}) {
1794
1803
  configurable: true,
1795
1804
  enumerable: false
1796
1805
  });
1797
- require_passthrough.definePassThroughPriority(result, [parser], (state, token) => {
1798
- const active = normalizeCommandState(state);
1799
- if (active == null) return void 0;
1800
- const childState = active[0] === "matched" ? parser.initialState : active[1];
1801
- return require_passthrough.getPassThroughPriority(parser, getCommandParseChildState(state, childState, parser), token);
1802
- });
1803
- require_passthrough.defineOptionMatch(result, (state, token) => {
1804
- const active = normalizeCommandState(state);
1805
- if (active == null) return void 0;
1806
- const childState = active[0] === "matched" ? parser.initialState : active[1];
1807
- const match = require_passthrough.getOptionMatch(parser, getCommandParseChildState(state, childState, parser), token);
1808
- return match == null ? void 0 : {
1809
- ...match,
1810
- continuesCommand: true
1811
- };
1806
+ require_passthrough.defineReachableChildren(result, [parser], (state) => {
1807
+ const child = selectChild(state);
1808
+ return child == null ? [] : [child];
1812
1809
  });
1813
1810
  return require_modifiers.fluent(require_short_option.scopeParser(result, commandScope.source, (context) => {
1814
1811
  if (normalizeCommandState(context.state) != null) commandScope.select(context, enteredScope);
@@ -9,7 +9,7 @@ import { getWrappedChildParseState, getWrappedChildState, isAnnotationWrappedIni
9
9
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
10
10
  import { extractLeadingCommandNames } from "./usage-internals.js";
11
11
  import { attachedValuePrefix, combinedOptionScope, fullNameOwnsToken, prefixSuggestion, scopeParser, selectableOptionScope } from "./short-option.js";
12
- import { defineKnownCompletion, defineOptionMatch, definePassThroughPriority, getOptionMatch, getPassThroughFailure, getPassThroughPriority } from "./internal/passthrough.js";
12
+ import { defineKnownCompletion, definePassThroughPriority, defineReachableChildren, getPassThroughFailure } from "./internal/passthrough.js";
13
13
  import { hiddenCommandAliasesKey } from "./internal/command-alias.js";
14
14
  import { completeOrExtractPhase2Seed, extractPhase2SeedKey } from "./phase2-seed.js";
15
15
  import { extractDependencyMetadata } from "./dependency-metadata.js";
@@ -1544,6 +1544,15 @@ function command(name, parser, options = {}) {
1544
1544
  const isAsync = parser.mode === "async";
1545
1545
  const syncInnerParser = parser;
1546
1546
  const asyncInnerParser = parser;
1547
+ const getChildState = (state, active) => getCommandParseChildState(state, active[0] === "matched" ? parser.initialState : active[1], parser);
1548
+ const selectChild = (state) => {
1549
+ const active = normalizeCommandState(state);
1550
+ return active == null ? void 0 : {
1551
+ parser,
1552
+ state: getChildState(state, active),
1553
+ continuesCommand: true
1554
+ };
1555
+ };
1547
1556
  const commandScope = selectableOptionScope(() => /* @__PURE__ */ new Set());
1548
1557
  const enteredScope = combinedOptionScope([parser], [name]);
1549
1558
  const result = {
@@ -1625,7 +1634,7 @@ function command(name, parser, options = {}) {
1625
1634
  consumed: context.buffer.slice(0, 1)
1626
1635
  };
1627
1636
  } else if (state[0] === "matched" || state[0] === "parsing") {
1628
- const innerState = state[0] === "matched" ? getCommandParseChildState(context.state, parser.initialState, parser) : getCommandParseChildState(context.state, state[1], parser);
1637
+ const innerState = getChildState(context.state, state);
1629
1638
  const wrapState = (parseResult) => {
1630
1639
  if (parseResult.success) {
1631
1640
  const mergedExec = mergeChildExec(context.exec, parseResult.next.exec);
@@ -1794,21 +1803,9 @@ function command(name, parser, options = {}) {
1794
1803
  configurable: true,
1795
1804
  enumerable: false
1796
1805
  });
1797
- definePassThroughPriority(result, [parser], (state, token) => {
1798
- const active = normalizeCommandState(state);
1799
- if (active == null) return void 0;
1800
- const childState = active[0] === "matched" ? parser.initialState : active[1];
1801
- return getPassThroughPriority(parser, getCommandParseChildState(state, childState, parser), token);
1802
- });
1803
- defineOptionMatch(result, (state, token) => {
1804
- const active = normalizeCommandState(state);
1805
- if (active == null) return void 0;
1806
- const childState = active[0] === "matched" ? parser.initialState : active[1];
1807
- const match = getOptionMatch(parser, getCommandParseChildState(state, childState, parser), token);
1808
- return match == null ? void 0 : {
1809
- ...match,
1810
- continuesCommand: true
1811
- };
1806
+ defineReachableChildren(result, [parser], (state) => {
1807
+ const child = selectChild(state);
1808
+ return child == null ? [] : [child];
1812
1809
  });
1813
1810
  return fluent(scopeParser(result, commandScope.source, (context) => {
1814
1811
  if (normalizeCommandState(context.state) != null) commandScope.select(context, enteredScope);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.4.0-dev.2661",
3
+ "version": "1.4.0-dev.2664",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -237,7 +237,7 @@
237
237
  },
238
238
  "sideEffects": false,
239
239
  "devDependencies": {
240
- "@optique/env": "1.4.0-dev.2661+04e7de36",
240
+ "@optique/env": "1.4.0-dev.2664+6f258296",
241
241
  "@types/node": "^24.0.0",
242
242
  "fast-check": "^4.7.0",
243
243
  "tsdown": "^0.13.0",