@optique/core 1.0.0-dev.1701 → 1.0.0-dev.1705

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.
@@ -513,81 +513,77 @@ function createExclusiveComplete(parsers, options, noMatchContext, mode) {
513
513
  const syncParsers = parsers;
514
514
  return (state, exec) => {
515
515
  const activeState = normalizeExclusiveState(state);
516
- if (activeState == null) {
517
- const annotations = require_annotations.getAnnotations(state);
518
- const annotateInitial = (initial) => annotations != null && initial != null && typeof initial === "object" ? require_annotations.injectAnnotations(initial, annotations) : initial;
519
- return require_mode_dispatch.dispatchByMode(mode, () => {
520
- const emptyCtx = {
521
- buffer: [],
522
- optionsTerminated: false,
523
- usage: []
524
- };
525
- let candidateIndex = -1;
526
- let candidateCount = 0;
527
- for (let i$1 = 0; i$1 < syncParsers.length; i$1++) {
528
- const p = syncParsers[i$1];
529
- if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
530
- const parseResult = p.parse({
531
- ...emptyCtx,
532
- state: annotateInitial(p.initialState)
533
- });
534
- if (!parseResult.success || parseResult.provisional) continue;
535
- candidateCount++;
536
- if (candidateIndex < 0) candidateIndex = i$1;
537
- if (candidateCount > 1) break;
538
- }
539
- if (candidateCount === 1 && candidateIndex >= 0) {
540
- const p = syncParsers[candidateIndex];
541
- const parseResult = p.parse({
542
- ...emptyCtx,
543
- state: annotateInitial(p.initialState)
544
- });
545
- if (parseResult.success) {
546
- const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
547
- return p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
548
- }
549
- }
550
- return {
551
- success: false,
552
- error: getNoMatchError(options, noMatchContext)
553
- };
554
- }, async () => {
555
- const emptyCtx = {
556
- buffer: [],
557
- optionsTerminated: false,
558
- usage: []
559
- };
560
- let candidateIndex = -1;
561
- let candidateCount = 0;
562
- for (let i$1 = 0; i$1 < parsers.length; i$1++) {
563
- const p = parsers[i$1];
564
- if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
565
- const parseResult = await p.parse({
566
- ...emptyCtx,
567
- state: annotateInitial(p.initialState)
568
- });
569
- if (!parseResult.success || parseResult.provisional) continue;
570
- candidateCount++;
571
- if (candidateIndex < 0) candidateIndex = i$1;
572
- if (candidateCount > 1) break;
516
+ if (activeState == null) return require_mode_dispatch.dispatchByMode(mode, () => {
517
+ const emptyCtx = {
518
+ buffer: [],
519
+ optionsTerminated: false,
520
+ usage: []
521
+ };
522
+ let candidateIndex = -1;
523
+ let candidateCount = 0;
524
+ for (let i$1 = 0; i$1 < syncParsers.length; i$1++) {
525
+ const p = syncParsers[i$1];
526
+ if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
527
+ const parseResult = p.parse({
528
+ ...emptyCtx,
529
+ state: getAnnotatedChildState(state, p.initialState, p)
530
+ });
531
+ if (!parseResult.success || parseResult.provisional) continue;
532
+ candidateCount++;
533
+ if (candidateIndex < 0) candidateIndex = i$1;
534
+ if (candidateCount > 1) break;
535
+ }
536
+ if (candidateCount === 1 && candidateIndex >= 0) {
537
+ const p = syncParsers[candidateIndex];
538
+ const parseResult = p.parse({
539
+ ...emptyCtx,
540
+ state: getAnnotatedChildState(state, p.initialState, p)
541
+ });
542
+ if (parseResult.success) {
543
+ const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
544
+ return p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
573
545
  }
574
- if (candidateCount === 1 && candidateIndex >= 0 && (parsers[candidateIndex].$mode === "sync" || exec?.phase !== "parse" && exec?.phase !== "suggest")) {
575
- const p = parsers[candidateIndex];
576
- const parseResult = await p.parse({
577
- ...emptyCtx,
578
- state: annotateInitial(p.initialState)
579
- });
580
- if (parseResult.success) {
581
- const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
582
- return await p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
583
- }
546
+ }
547
+ return {
548
+ success: false,
549
+ error: getNoMatchError(options, noMatchContext)
550
+ };
551
+ }, async () => {
552
+ const emptyCtx = {
553
+ buffer: [],
554
+ optionsTerminated: false,
555
+ usage: []
556
+ };
557
+ let candidateIndex = -1;
558
+ let candidateCount = 0;
559
+ for (let i$1 = 0; i$1 < parsers.length; i$1++) {
560
+ const p = parsers[i$1];
561
+ if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
562
+ const parseResult = await p.parse({
563
+ ...emptyCtx,
564
+ state: getAnnotatedChildState(state, p.initialState, p)
565
+ });
566
+ if (!parseResult.success || parseResult.provisional) continue;
567
+ candidateCount++;
568
+ if (candidateIndex < 0) candidateIndex = i$1;
569
+ if (candidateCount > 1) break;
570
+ }
571
+ if (candidateCount === 1 && candidateIndex >= 0 && (parsers[candidateIndex].$mode === "sync" || exec?.phase !== "parse" && exec?.phase !== "suggest")) {
572
+ const p = parsers[candidateIndex];
573
+ const parseResult = await p.parse({
574
+ ...emptyCtx,
575
+ state: getAnnotatedChildState(state, p.initialState, p)
576
+ });
577
+ if (parseResult.success) {
578
+ const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
579
+ return await p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
584
580
  }
585
- return {
586
- success: false,
587
- error: getNoMatchError(options, noMatchContext)
588
- };
589
- });
590
- }
581
+ }
582
+ return {
583
+ success: false,
584
+ error: getNoMatchError(options, noMatchContext)
585
+ };
586
+ });
591
587
  const [i, result] = activeState;
592
588
  if (!result.success) return {
593
589
  success: false,
@@ -4034,10 +4030,13 @@ function conditional(discriminator, branches, defaultBranch, options) {
4034
4030
  const deferredValue = deferredDiscriminatorResult.value;
4035
4031
  const deferredBranch = syncBranches[deferredValue];
4036
4032
  if (deferredBranch) {
4033
+ const branchExec = withChildExecPath(exec, "_branch");
4037
4034
  const emptyCtx = {
4038
4035
  buffer: [],
4039
4036
  optionsTerminated: false,
4040
- usage: []
4037
+ usage: [],
4038
+ exec: branchExec,
4039
+ dependencyRegistry: exec?.dependencyRegistry
4041
4040
  };
4042
4041
  const annotatedInitial = getAnnotatedChildState(state, deferredBranch.initialState, deferredBranch);
4043
4042
  const replayResult = deferredBranch.parse({
@@ -4046,7 +4045,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
4046
4045
  });
4047
4046
  const branchState = replayResult.success ? replayResult.next.state : annotatedInitial;
4048
4047
  const annotatedBranchState = getAnnotatedChildState(state, branchState, deferredBranch);
4049
- const branchResult$1 = unwrapCompleteResult(deferredBranch.complete(annotatedBranchState, withChildExecPath(exec, "_branch")));
4048
+ const branchResult$1 = unwrapCompleteResult(deferredBranch.complete(annotatedBranchState, branchExec));
4050
4049
  if (branchResult$1.success) return {
4051
4050
  success: true,
4052
4051
  value: [deferredValue, branchResult$1.value],
@@ -4140,10 +4139,13 @@ function conditional(discriminator, branches, defaultBranch, options) {
4140
4139
  const deferredValue = deferredDiscriminatorResult.value;
4141
4140
  const deferredBranch = branches[deferredValue];
4142
4141
  if (deferredBranch) {
4142
+ const branchExec = withChildExecPath(exec, "_branch");
4143
4143
  const emptyCtx = {
4144
4144
  buffer: [],
4145
4145
  optionsTerminated: false,
4146
- usage: []
4146
+ usage: [],
4147
+ exec: branchExec,
4148
+ dependencyRegistry: exec?.dependencyRegistry
4147
4149
  };
4148
4150
  const annotatedInitial = getAnnotatedChildState(state, deferredBranch.initialState, deferredBranch);
4149
4151
  const replayResult = await deferredBranch.parse({
@@ -4152,7 +4154,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
4152
4154
  });
4153
4155
  const branchState = replayResult.success ? replayResult.next.state : annotatedInitial;
4154
4156
  const annotatedBranchState = getAnnotatedChildState(state, branchState, deferredBranch);
4155
- const branchResult$1 = unwrapCompleteResult(await deferredBranch.complete(annotatedBranchState, withChildExecPath(exec, "_branch")));
4157
+ const branchResult$1 = unwrapCompleteResult(await deferredBranch.complete(annotatedBranchState, branchExec));
4156
4158
  if (branchResult$1.success) return {
4157
4159
  success: true,
4158
4160
  value: [deferredValue, branchResult$1.value],
@@ -513,81 +513,77 @@ function createExclusiveComplete(parsers, options, noMatchContext, mode) {
513
513
  const syncParsers = parsers;
514
514
  return (state, exec) => {
515
515
  const activeState = normalizeExclusiveState(state);
516
- if (activeState == null) {
517
- const annotations = getAnnotations(state);
518
- const annotateInitial = (initial) => annotations != null && initial != null && typeof initial === "object" ? injectAnnotations(initial, annotations) : initial;
519
- return dispatchByMode(mode, () => {
520
- const emptyCtx = {
521
- buffer: [],
522
- optionsTerminated: false,
523
- usage: []
524
- };
525
- let candidateIndex = -1;
526
- let candidateCount = 0;
527
- for (let i$1 = 0; i$1 < syncParsers.length; i$1++) {
528
- const p = syncParsers[i$1];
529
- if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
530
- const parseResult = p.parse({
531
- ...emptyCtx,
532
- state: annotateInitial(p.initialState)
533
- });
534
- if (!parseResult.success || parseResult.provisional) continue;
535
- candidateCount++;
536
- if (candidateIndex < 0) candidateIndex = i$1;
537
- if (candidateCount > 1) break;
538
- }
539
- if (candidateCount === 1 && candidateIndex >= 0) {
540
- const p = syncParsers[candidateIndex];
541
- const parseResult = p.parse({
542
- ...emptyCtx,
543
- state: annotateInitial(p.initialState)
544
- });
545
- if (parseResult.success) {
546
- const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
547
- return p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
548
- }
549
- }
550
- return {
551
- success: false,
552
- error: getNoMatchError(options, noMatchContext)
553
- };
554
- }, async () => {
555
- const emptyCtx = {
556
- buffer: [],
557
- optionsTerminated: false,
558
- usage: []
559
- };
560
- let candidateIndex = -1;
561
- let candidateCount = 0;
562
- for (let i$1 = 0; i$1 < parsers.length; i$1++) {
563
- const p = parsers[i$1];
564
- if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
565
- const parseResult = await p.parse({
566
- ...emptyCtx,
567
- state: annotateInitial(p.initialState)
568
- });
569
- if (!parseResult.success || parseResult.provisional) continue;
570
- candidateCount++;
571
- if (candidateIndex < 0) candidateIndex = i$1;
572
- if (candidateCount > 1) break;
516
+ if (activeState == null) return dispatchByMode(mode, () => {
517
+ const emptyCtx = {
518
+ buffer: [],
519
+ optionsTerminated: false,
520
+ usage: []
521
+ };
522
+ let candidateIndex = -1;
523
+ let candidateCount = 0;
524
+ for (let i$1 = 0; i$1 < syncParsers.length; i$1++) {
525
+ const p = syncParsers[i$1];
526
+ if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
527
+ const parseResult = p.parse({
528
+ ...emptyCtx,
529
+ state: getAnnotatedChildState(state, p.initialState, p)
530
+ });
531
+ if (!parseResult.success || parseResult.provisional) continue;
532
+ candidateCount++;
533
+ if (candidateIndex < 0) candidateIndex = i$1;
534
+ if (candidateCount > 1) break;
535
+ }
536
+ if (candidateCount === 1 && candidateIndex >= 0) {
537
+ const p = syncParsers[candidateIndex];
538
+ const parseResult = p.parse({
539
+ ...emptyCtx,
540
+ state: getAnnotatedChildState(state, p.initialState, p)
541
+ });
542
+ if (parseResult.success) {
543
+ const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
544
+ return p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
573
545
  }
574
- if (candidateCount === 1 && candidateIndex >= 0 && (parsers[candidateIndex].$mode === "sync" || exec?.phase !== "parse" && exec?.phase !== "suggest")) {
575
- const p = parsers[candidateIndex];
576
- const parseResult = await p.parse({
577
- ...emptyCtx,
578
- state: annotateInitial(p.initialState)
579
- });
580
- if (parseResult.success) {
581
- const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
582
- return await p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
583
- }
546
+ }
547
+ return {
548
+ success: false,
549
+ error: getNoMatchError(options, noMatchContext)
550
+ };
551
+ }, async () => {
552
+ const emptyCtx = {
553
+ buffer: [],
554
+ optionsTerminated: false,
555
+ usage: []
556
+ };
557
+ let candidateIndex = -1;
558
+ let candidateCount = 0;
559
+ for (let i$1 = 0; i$1 < parsers.length; i$1++) {
560
+ const p = parsers[i$1];
561
+ if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
562
+ const parseResult = await p.parse({
563
+ ...emptyCtx,
564
+ state: getAnnotatedChildState(state, p.initialState, p)
565
+ });
566
+ if (!parseResult.success || parseResult.provisional) continue;
567
+ candidateCount++;
568
+ if (candidateIndex < 0) candidateIndex = i$1;
569
+ if (candidateCount > 1) break;
570
+ }
571
+ if (candidateCount === 1 && candidateIndex >= 0 && (parsers[candidateIndex].$mode === "sync" || exec?.phase !== "parse" && exec?.phase !== "suggest")) {
572
+ const p = parsers[candidateIndex];
573
+ const parseResult = await p.parse({
574
+ ...emptyCtx,
575
+ state: getAnnotatedChildState(state, p.initialState, p)
576
+ });
577
+ if (parseResult.success) {
578
+ const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
579
+ return await p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
584
580
  }
585
- return {
586
- success: false,
587
- error: getNoMatchError(options, noMatchContext)
588
- };
589
- });
590
- }
581
+ }
582
+ return {
583
+ success: false,
584
+ error: getNoMatchError(options, noMatchContext)
585
+ };
586
+ });
591
587
  const [i, result] = activeState;
592
588
  if (!result.success) return {
593
589
  success: false,
@@ -4034,10 +4030,13 @@ function conditional(discriminator, branches, defaultBranch, options) {
4034
4030
  const deferredValue = deferredDiscriminatorResult.value;
4035
4031
  const deferredBranch = syncBranches[deferredValue];
4036
4032
  if (deferredBranch) {
4033
+ const branchExec = withChildExecPath(exec, "_branch");
4037
4034
  const emptyCtx = {
4038
4035
  buffer: [],
4039
4036
  optionsTerminated: false,
4040
- usage: []
4037
+ usage: [],
4038
+ exec: branchExec,
4039
+ dependencyRegistry: exec?.dependencyRegistry
4041
4040
  };
4042
4041
  const annotatedInitial = getAnnotatedChildState(state, deferredBranch.initialState, deferredBranch);
4043
4042
  const replayResult = deferredBranch.parse({
@@ -4046,7 +4045,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
4046
4045
  });
4047
4046
  const branchState = replayResult.success ? replayResult.next.state : annotatedInitial;
4048
4047
  const annotatedBranchState = getAnnotatedChildState(state, branchState, deferredBranch);
4049
- const branchResult$1 = unwrapCompleteResult(deferredBranch.complete(annotatedBranchState, withChildExecPath(exec, "_branch")));
4048
+ const branchResult$1 = unwrapCompleteResult(deferredBranch.complete(annotatedBranchState, branchExec));
4050
4049
  if (branchResult$1.success) return {
4051
4050
  success: true,
4052
4051
  value: [deferredValue, branchResult$1.value],
@@ -4140,10 +4139,13 @@ function conditional(discriminator, branches, defaultBranch, options) {
4140
4139
  const deferredValue = deferredDiscriminatorResult.value;
4141
4140
  const deferredBranch = branches[deferredValue];
4142
4141
  if (deferredBranch) {
4142
+ const branchExec = withChildExecPath(exec, "_branch");
4143
4143
  const emptyCtx = {
4144
4144
  buffer: [],
4145
4145
  optionsTerminated: false,
4146
- usage: []
4146
+ usage: [],
4147
+ exec: branchExec,
4148
+ dependencyRegistry: exec?.dependencyRegistry
4147
4149
  };
4148
4150
  const annotatedInitial = getAnnotatedChildState(state, deferredBranch.initialState, deferredBranch);
4149
4151
  const replayResult = await deferredBranch.parse({
@@ -4152,7 +4154,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
4152
4154
  });
4153
4155
  const branchState = replayResult.success ? replayResult.next.state : annotatedInitial;
4154
4156
  const annotatedBranchState = getAnnotatedChildState(state, branchState, deferredBranch);
4155
- const branchResult$1 = unwrapCompleteResult(await deferredBranch.complete(annotatedBranchState, withChildExecPath(exec, "_branch")));
4157
+ const branchResult$1 = unwrapCompleteResult(await deferredBranch.complete(annotatedBranchState, branchExec));
4156
4158
  if (branchResult$1.success) return {
4157
4159
  success: true,
4158
4160
  value: [deferredValue, branchResult$1.value],
@@ -6,10 +6,10 @@ const require_parser = require('./parser.cjs');
6
6
 
7
7
  //#region src/modifiers.ts
8
8
  /**
9
- * Internal marker for optional-style wrappers (`optional()`, `withDefault()`).
10
- * Used by `object()`'s zero-consumption pass to skip these parsers, since they
11
- * should return `undefined`/default when the user provides no input rather than
12
- * running the inner parser.
9
+ * Internal marker for wrappers that should be skipped by `object()`'s
10
+ * zero-consumption pass. Set on `optional()`, `withDefault()`, and
11
+ * `prompt()`, since these wrappers have their own completion semantics
12
+ * that should not be short-circuited during parse.
13
13
  *
14
14
  * @internal
15
15
  */
@@ -4,10 +4,10 @@ import { Mode, Parser } from "./parser.cjs";
4
4
  //#region src/modifiers.d.ts
5
5
 
6
6
  /**
7
- * Internal marker for optional-style wrappers (`optional()`, `withDefault()`).
8
- * Used by `object()`'s zero-consumption pass to skip these parsers, since they
9
- * should return `undefined`/default when the user provides no input rather than
10
- * running the inner parser.
7
+ * Internal marker for wrappers that should be skipped by `object()`'s
8
+ * zero-consumption pass. Set on `optional()`, `withDefault()`, and
9
+ * `prompt()`, since these wrappers have their own completion semantics
10
+ * that should not be short-circuited during parse.
11
11
  *
12
12
  * @internal
13
13
  */
@@ -4,10 +4,10 @@ import { Mode, Parser } from "./parser.js";
4
4
  //#region src/modifiers.d.ts
5
5
 
6
6
  /**
7
- * Internal marker for optional-style wrappers (`optional()`, `withDefault()`).
8
- * Used by `object()`'s zero-consumption pass to skip these parsers, since they
9
- * should return `undefined`/default when the user provides no input rather than
10
- * running the inner parser.
7
+ * Internal marker for wrappers that should be skipped by `object()`'s
8
+ * zero-consumption pass. Set on `optional()`, `withDefault()`, and
9
+ * `prompt()`, since these wrappers have their own completion semantics
10
+ * that should not be short-circuited during parse.
11
11
  *
12
12
  * @internal
13
13
  */
package/dist/modifiers.js CHANGED
@@ -6,10 +6,10 @@ import { defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompl
6
6
 
7
7
  //#region src/modifiers.ts
8
8
  /**
9
- * Internal marker for optional-style wrappers (`optional()`, `withDefault()`).
10
- * Used by `object()`'s zero-consumption pass to skip these parsers, since they
11
- * should return `undefined`/default when the user provides no input rather than
12
- * running the inner parser.
9
+ * Internal marker for wrappers that should be skipped by `object()`'s
10
+ * zero-consumption pass. Set on `optional()`, `withDefault()`, and
11
+ * `prompt()`, since these wrappers have their own completion semantics
12
+ * that should not be short-circuited during parse.
13
13
  *
14
14
  * @internal
15
15
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1701+1135d650",
3
+ "version": "1.0.0-dev.1705+262899fd",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",