@optique/core 1.0.0-dev.552 → 1.0.0-dev.555

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/context.cjs CHANGED
@@ -4,8 +4,9 @@
4
4
  * Checks whether a context is static (returns annotations without needing
5
5
  * parsed results).
6
6
  *
7
- * A context is considered static if `getAnnotations()` called without
8
- * arguments returns a non-empty annotations object synchronously.
7
+ * A context is considered static if it declares `mode: "static"` or if
8
+ * `getAnnotations()` called without arguments returns a non-empty
9
+ * annotations object synchronously.
9
10
  *
10
11
  * @param context The source context to check.
11
12
  * @returns `true` if the context is static, `false` otherwise.
@@ -154,8 +154,9 @@ interface SourceContext<TRequiredOptions = void> {
154
154
  * Checks whether a context is static (returns annotations without needing
155
155
  * parsed results).
156
156
  *
157
- * A context is considered static if `getAnnotations()` called without
158
- * arguments returns a non-empty annotations object synchronously.
157
+ * A context is considered static if it declares `mode: "static"` or if
158
+ * `getAnnotations()` called without arguments returns a non-empty
159
+ * annotations object synchronously.
159
160
  *
160
161
  * @param context The source context to check.
161
162
  * @returns `true` if the context is static, `false` otherwise.
package/dist/context.d.ts CHANGED
@@ -154,8 +154,9 @@ interface SourceContext<TRequiredOptions = void> {
154
154
  * Checks whether a context is static (returns annotations without needing
155
155
  * parsed results).
156
156
  *
157
- * A context is considered static if `getAnnotations()` called without
158
- * arguments returns a non-empty annotations object synchronously.
157
+ * A context is considered static if it declares `mode: "static"` or if
158
+ * `getAnnotations()` called without arguments returns a non-empty
159
+ * annotations object synchronously.
159
160
  *
160
161
  * @param context The source context to check.
161
162
  * @returns `true` if the context is static, `false` otherwise.
package/dist/context.js CHANGED
@@ -3,8 +3,9 @@
3
3
  * Checks whether a context is static (returns annotations without needing
4
4
  * parsed results).
5
5
  *
6
- * A context is considered static if `getAnnotations()` called without
7
- * arguments returns a non-empty annotations object synchronously.
6
+ * A context is considered static if it declares `mode: "static"` or if
7
+ * `getAnnotations()` called without arguments returns a non-empty
8
+ * annotations object synchronously.
8
9
  *
9
10
  * @param context The source context to check.
10
11
  * @returns `true` if the context is static, `false` otherwise.
package/dist/facade.cjs CHANGED
@@ -870,13 +870,8 @@ async function collectPhase1Annotations(contexts, options) {
870
870
  let hasDynamic = false;
871
871
  for (const context of contexts) {
872
872
  const result = context.getAnnotations(void 0, options);
873
- if (result instanceof Promise) {
874
- hasDynamic = true;
875
- annotationsList.push(await result);
876
- } else {
877
- if (Object.getOwnPropertySymbols(result).length === 0) hasDynamic = true;
878
- annotationsList.push(result);
879
- }
873
+ hasDynamic ||= needsTwoPhaseContext(context, result);
874
+ annotationsList.push(result instanceof Promise ? await result : result);
880
875
  }
881
876
  return {
882
877
  annotations: mergeAnnotations(annotationsList),
@@ -914,7 +909,7 @@ function collectPhase1AnnotationsSync(contexts, options) {
914
909
  for (const context of contexts) {
915
910
  const result = context.getAnnotations(void 0, options);
916
911
  if (result instanceof Promise) throw new Error(`Context ${String(context.id)} returned a Promise in sync mode. Use runWith() or runWithAsync() for async contexts.`);
917
- if (Object.getOwnPropertySymbols(result).length === 0) hasDynamic = true;
912
+ hasDynamic ||= needsTwoPhaseContext(context, result);
918
913
  annotationsList.push(result);
919
914
  }
920
915
  return {
@@ -923,6 +918,18 @@ function collectPhase1AnnotationsSync(contexts, options) {
923
918
  };
924
919
  }
925
920
  /**
921
+ * Determines whether a context requires a second parse pass.
922
+ *
923
+ * Explicit `mode` declarations take precedence over legacy heuristics so
924
+ * static contexts are not forced into two-phase parsing when they return
925
+ * empty annotations or a Promise.
926
+ */
927
+ function needsTwoPhaseContext(context, result) {
928
+ if (context.mode !== void 0) return context.mode === "dynamic";
929
+ if (result instanceof Promise) return true;
930
+ return Object.getOwnPropertySymbols(result).length === 0;
931
+ }
932
+ /**
926
933
  * Collects annotations from all contexts synchronously.
927
934
  *
928
935
  * @param contexts Source contexts to collect annotations from.
package/dist/facade.js CHANGED
@@ -870,13 +870,8 @@ async function collectPhase1Annotations(contexts, options) {
870
870
  let hasDynamic = false;
871
871
  for (const context of contexts) {
872
872
  const result = context.getAnnotations(void 0, options);
873
- if (result instanceof Promise) {
874
- hasDynamic = true;
875
- annotationsList.push(await result);
876
- } else {
877
- if (Object.getOwnPropertySymbols(result).length === 0) hasDynamic = true;
878
- annotationsList.push(result);
879
- }
873
+ hasDynamic ||= needsTwoPhaseContext(context, result);
874
+ annotationsList.push(result instanceof Promise ? await result : result);
880
875
  }
881
876
  return {
882
877
  annotations: mergeAnnotations(annotationsList),
@@ -914,7 +909,7 @@ function collectPhase1AnnotationsSync(contexts, options) {
914
909
  for (const context of contexts) {
915
910
  const result = context.getAnnotations(void 0, options);
916
911
  if (result instanceof Promise) throw new Error(`Context ${String(context.id)} returned a Promise in sync mode. Use runWith() or runWithAsync() for async contexts.`);
917
- if (Object.getOwnPropertySymbols(result).length === 0) hasDynamic = true;
912
+ hasDynamic ||= needsTwoPhaseContext(context, result);
918
913
  annotationsList.push(result);
919
914
  }
920
915
  return {
@@ -923,6 +918,18 @@ function collectPhase1AnnotationsSync(contexts, options) {
923
918
  };
924
919
  }
925
920
  /**
921
+ * Determines whether a context requires a second parse pass.
922
+ *
923
+ * Explicit `mode` declarations take precedence over legacy heuristics so
924
+ * static contexts are not forced into two-phase parsing when they return
925
+ * empty annotations or a Promise.
926
+ */
927
+ function needsTwoPhaseContext(context, result) {
928
+ if (context.mode !== void 0) return context.mode === "dynamic";
929
+ if (result instanceof Promise) return true;
930
+ return Object.getOwnPropertySymbols(result).length === 0;
931
+ }
932
+ /**
926
933
  * Collects annotations from all contexts synchronously.
927
934
  *
928
935
  * @param contexts Source contexts to collect annotations from.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.552+30c7ea22",
3
+ "version": "1.0.0-dev.555+975ed8c5",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",