import type { JsonValue } from "@stripe/formspec-core/internals"; import { type ParsedCommentTag } from "./comment-syntax.js"; /** * Discriminates between "build" (compile-time via tsdoc-parser.ts) and * "snapshot" (runtime via file-snapshots.ts) lowering contexts. * * Phase 1 implementations treat this as a no-op; it is accepted here for * forward-compatibility with Phase 2/3 consumer wiring. */ export type TagArgumentLowering = "build" | "snapshot"; /** * The strongly-typed result of a successful tag-argument parse. * * Each variant maps to a distinct constraint-tag semantic: * - `number` — numeric constraints (minimum, maximum, …) * - `string` — validated string result for `@pattern`; never produced for * `@const` (use `raw-string-fallback` for that) * - `boolean` — flag constraints * - `marker` — presence-only constraints (@uniqueItems) * - `json-array` — array-valued constraints (@enumOptions) * - `json-value` — arbitrary JSON constraints * - `raw-string-fallback` — ONLY produced for `@const` when the argument is * not valid JSON; signals that the value should be * treated as an opaque string literal */ export type TagArgumentValue = { readonly kind: "number"; readonly value: number; } | { readonly kind: "string"; readonly value: string; } | { readonly kind: "boolean"; readonly value: boolean; } | { readonly kind: "marker"; } | { readonly kind: "json-array"; readonly value: readonly JsonValue[]; } | { readonly kind: "json-value"; readonly value: JsonValue; } | { readonly kind: "raw-string-fallback"; readonly value: string; }; /** * Diagnostic codes emitted by {@link parseTagArgument}. * * The value-parsing codes (`INVALID_NUMERIC_VALUE`, `INVALID_NON_NEGATIVE_INTEGER`, * `INVALID_REGEX_PATTERN`) are the spec-normative codes from 002-tsdoc-grammar §6. * They replace the generic `INVALID_TAG_ARGUMENT` for the failure classes the spec * names explicitly, so a machine consumer can distinguish a non-finite numeric from * a bad length from an uncompilable pattern (D6). `INVALID_TAG_ARGUMENT` remains for * failure classes without a dedicated spec code (e.g. `@uniqueItems false`, * `@enumOptions 5`). */ export declare const TAG_ARGUMENT_DIAGNOSTIC_CODES: { readonly INVALID_TAG_ARGUMENT: "INVALID_TAG_ARGUMENT"; readonly MISSING_TAG_ARGUMENT: "MISSING_TAG_ARGUMENT"; readonly UNKNOWN_TAG: "UNKNOWN_TAG"; /** 002 §3.2 / §6 — numeric tag received NaN, Infinity, overflow, or non-decimal text. */ readonly INVALID_NUMERIC_VALUE: "INVALID_NUMERIC_VALUE"; /** 002 §3.2 / §6 — length/count tag received a negative, fractional, or non-integer value. */ readonly INVALID_NON_NEGATIVE_INTEGER: "INVALID_NON_NEGATIVE_INTEGER"; /** 002 §3.2 / §6 — `@pattern` value does not compile as an ECMAScript regex. */ readonly INVALID_REGEX_PATTERN: "INVALID_REGEX_PATTERN"; }; export type TagArgumentDiagnosticCode = (typeof TAG_ARGUMENT_DIAGNOSTIC_CODES)[keyof typeof TAG_ARGUMENT_DIAGNOSTIC_CODES]; export interface TagArgumentDiagnostic { readonly code: TagArgumentDiagnosticCode; /** * Human-readable diagnostic message. * * Both consumers surface `code` directly (via {@link mapTypedParserDiagnosticCode}), * so message content is presentational, not load-bearing for classification. The * value-parsing codes use the spec-normative message shapes from 002 §6 * (e.g. `"@minimum" expects a finite number, but received "Infinity".`). The * remaining generic-argument messages retain the historical `Expected …` phrasing. */ readonly message: string; } /** The result type returned by {@link parseTagArgument}. */ export type TagArgumentParseResult = { readonly ok: true; readonly value: TagArgumentValue; } | { readonly ok: false; readonly diagnostic: TagArgumentDiagnostic; }; /** * Constraint-tag parsing families. Each family shares a common argument * structure and is implemented by a dedicated parser in Slices A/B/C. */ export type TagFamily = "numeric" | "length" | "boolean-marker" | "string" | "json-array" | "json-value-with-fallback"; /** * Maps every built-in constraint-tag name (no leading "@") to its parsing * family. Derived from {@link BUILTIN_CONSTRAINT_DEFINITIONS} — the single * source of truth for which constraint tags exist. * * The `satisfies` guard enforces that every key in BUILTIN_CONSTRAINT_DEFINITIONS * is present here and maps to a valid TagFamily. Adding a new tag to core is * therefore either automatic (if the default mapping covers it) or a type * error (prompting the author to add an entry here). * * Family assignment rules: * "number" core type → "numeric" for value constraints; "length" for size/ * count constraints (minLength, maxLength, minItems, maxItems) * "boolean" core type → "boolean-marker" * "string" core type → "string" * "json" core type → "json-array" for enumOptions; "json-value-with-fallback" for const */ export declare const TAG_ARGUMENT_FAMILIES: { readonly minimum: "numeric"; readonly maximum: "numeric"; readonly exclusiveMinimum: "numeric"; readonly exclusiveMaximum: "numeric"; readonly multipleOf: "numeric"; readonly minLength: "length"; readonly maxLength: "length"; readonly minItems: "length"; readonly maxItems: "length"; readonly uniqueItems: "boolean-marker"; readonly pattern: "string"; readonly enumOptions: "json-array"; readonly const: "json-value-with-fallback"; }; /** * Parses a single constraint-tag argument literal for the Role C typed-parser * validation step. * * @param tagName - normalized tag name (no leading "@") * @param rawArgumentText - argument text AFTER parseTagSyntax has stripped * any path-target prefix (i.e. "effectiveText") * @param _lowering - build vs snapshot. Phase 1 implementations do not use * this; the parameter is accepted for forward-compatibility * with Phase 2/3 consumer wiring. */ export declare function parseTagArgument(tagName: string, rawArgumentText: string, _lowering: TagArgumentLowering): TagArgumentParseResult; /** * The subset of diagnostic codes that both consumers (build and snapshot) may * emit as a result of a typed-parser rejection at Role C. * * `UNKNOWN_TAG` is never included: it is structurally unreachable in any * consumer that guards the {@link parseTagArgument} call with an * `isBuiltinConstraintName` or `getTagDefinition` check. */ export type MappedTypedParserCode = "MISSING_TAG_ARGUMENT" | "INVALID_TAG_ARGUMENT" | "INVALID_NUMERIC_VALUE" | "INVALID_NON_NEGATIVE_INTEGER" | "INVALID_REGEX_PATTERN"; /** * Maps a {@link TagArgumentDiagnosticCode} from {@link parseTagArgument} to the * canonical consumer-level code emitted when the typed parser rejects an * argument at Role C. * * Both the build consumer (`tsdoc-parser.ts`) and the snapshot consumer * (`file-snapshots.ts`) previously contained identical exhaustive switches for * this mapping. This helper centralises the logic. * * @throws if `code` is `UNKNOWN_TAG` (structurally unreachable after the * `isBuiltinConstraintName` / `getTagDefinition` guard) or an unrecognised * value (exhaustiveness guard for future additions). */ export declare function mapTypedParserDiagnosticCode(code: TagArgumentDiagnosticCode, tagName: string): MappedTypedParserCode; /** * Derives the effective argument text that should be passed to * `parseTagArgument` for the Role C typed-parser validation step. * * Both the build consumer (`tsdoc-parser.ts`) and the snapshot consumer * (`file-snapshots.ts`) need to extract the same argument text from a tag * payload before Role C validation. The two consumers previously diverged: * * - Build consumer re-derives via `parseTagSyntax(tagName, rawText).argumentText` * so that path-target prefixes are stripped. `rawText` is the full payload * (may include `:field` target prefix) already chosen by * `choosePreferredPayloadText` upstream — including `TAGS_REQUIRING_RAW_TEXT` * compiler-API fallback selection. By the time this helper is called, the * preferred payload has already been selected; this helper only strips the * path-target prefix and canonicalizes the argument text. * - Snapshot consumer passed `tag.argumentText` directly (which is already * target-stripped by `parseCommentBlock`). * * This helper encodes the two cases that both consumers must handle: * 1. **Standard path** (`parsedTag` non-null): re-parse `rawText` through * `parseTagSyntax` to strip any path-target prefix and canonicalize * the argument text. For the snapshot consumer, `rawText` equals * `tag.argumentText` (already stripped), so `parseTagSyntax` is a no-op. * 2. **Orphaned fallback** (`parsedTag` null): the unified comment parser * failed to produce a tag object (e.g. malformed comment), but a raw-text * fallback from `ts.getJSDocTags()` was recovered. Return `rawText` * directly — there is no parsed tag to re-derive from. * * Both consumers call this helper with their respective `rawText` and * `parsedTag`, ensuring that the text handed to `parseTagArgument` is derived * identically regardless of consumer. * * @param tagName - normalized tag name (no leading `@`) * @param rawText - the post-`choosePreferredPayloadText` payload string, * possibly including a path-target prefix (`:field`). * `TAGS_REQUIRING_RAW_TEXT` selection is handled upstream * by `choosePreferredPayloadText` before this helper is * called. * @param parsedTag - the parsed comment tag from `parseCommentBlock`, or * `null` for orphaned compiler-API fallback entries. * * @internal */ export declare function extractEffectiveArgumentText(tagName: string, rawText: string, parsedTag: ParsedCommentTag | null): string; //# sourceMappingURL=tag-argument-parser.d.ts.map