@optique/core 0.7.3 → 0.7.5

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.
@@ -728,8 +728,11 @@ function merge(...args) {
728
728
  for (let i = 0; i < parsers.length; i++) {
729
729
  const parser = parsers[i];
730
730
  let parserState;
731
- if (parser.initialState === void 0) parserState = void 0;
732
- else if (parser.initialState && typeof parser.initialState === "object") if (context.state && typeof context.state === "object") {
731
+ if (parser.initialState === void 0) {
732
+ const key = `__parser_${i}`;
733
+ if (context.state && typeof context.state === "object" && key in context.state) parserState = context.state[key];
734
+ else parserState = void 0;
735
+ } else if (parser.initialState && typeof parser.initialState === "object") if (context.state && typeof context.state === "object") {
733
736
  const extractedState = {};
734
737
  for (const field in parser.initialState) extractedState[field] = field in context.state ? context.state[field] : parser.initialState[field];
735
738
  parserState = extractedState;
@@ -728,8 +728,11 @@ function merge(...args) {
728
728
  for (let i = 0; i < parsers.length; i++) {
729
729
  const parser = parsers[i];
730
730
  let parserState;
731
- if (parser.initialState === void 0) parserState = void 0;
732
- else if (parser.initialState && typeof parser.initialState === "object") if (context.state && typeof context.state === "object") {
731
+ if (parser.initialState === void 0) {
732
+ const key = `__parser_${i}`;
733
+ if (context.state && typeof context.state === "object" && key in context.state) parserState = context.state[key];
734
+ else parserState = void 0;
735
+ } else if (parser.initialState && typeof parser.initialState === "object") if (context.state && typeof context.state === "object") {
733
736
  const extractedState = {};
734
737
  for (const field in parser.initialState) extractedState[field] = field in context.state ? context.state[field] : parser.initialState[field];
735
738
  parserState = extractedState;
@@ -81,7 +81,7 @@ declare class WithDefaultError extends Error {
81
81
  * or the default value if the wrapped parser fails to match
82
82
  * (union type {@link TValue} | {@link TDefault}).
83
83
  */
84
- declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault)): Parser<TValue | TDefault, [TState] | undefined>;
84
+ declare function withDefault<TValue, TState, const TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault)): Parser<TValue | TDefault, [TState] | undefined>;
85
85
  /**
86
86
  * Creates a parser that makes another parser use a default value when it fails
87
87
  * to match or consume input. This is similar to {@link optional}, but instead
@@ -100,7 +100,7 @@ declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<T
100
100
  * (union type {@link TValue} | {@link TDefault}).
101
101
  * @since 0.5.0
102
102
  */
103
- declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): Parser<TValue | TDefault, [TState] | undefined>;
103
+ declare function withDefault<TValue, TState, const TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): Parser<TValue | TDefault, [TState] | undefined>;
104
104
  /**
105
105
  * Creates a parser that transforms the result value of another parser using
106
106
  * a mapping function. This enables value transformation while preserving
@@ -81,7 +81,7 @@ declare class WithDefaultError extends Error {
81
81
  * or the default value if the wrapped parser fails to match
82
82
  * (union type {@link TValue} | {@link TDefault}).
83
83
  */
84
- declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault)): Parser<TValue | TDefault, [TState] | undefined>;
84
+ declare function withDefault<TValue, TState, const TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault)): Parser<TValue | TDefault, [TState] | undefined>;
85
85
  /**
86
86
  * Creates a parser that makes another parser use a default value when it fails
87
87
  * to match or consume input. This is similar to {@link optional}, but instead
@@ -100,7 +100,7 @@ declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<T
100
100
  * (union type {@link TValue} | {@link TDefault}).
101
101
  * @since 0.5.0
102
102
  */
103
- declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): Parser<TValue | TDefault, [TState] | undefined>;
103
+ declare function withDefault<TValue, TState, const TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): Parser<TValue | TDefault, [TState] | undefined>;
104
104
  /**
105
105
  * Creates a parser that transforms the result value of another parser using
106
106
  * a mapping function. This enables value transformation while preserving
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",