{"version":3,"file":"_assertGuard.mjs","names":[],"sources":["../../src/internal/_assertGuard.ts"],"sourcesContent":["import { TypeGuardError } from \"../TypeGuardError\";\n\n/**\n * Report an assertion failure.\n *\n * When `exceptionable` is true it throws the error that `factory` makes, or a\n * TypeGuardError when `factory` is not a function; otherwise it returns false\n * so a union probe can try the next branch.\n *\n * @evidence contracts/common.md#principled-implementation When the call is exceptionable it throws an error built by the caller's factory if one is a function, and a TypeGuardError otherwise, and when it is not exceptionable it returns false so a union probe can try another branch without throwing. The factory is tested for callability because a pointwise call such as `rows.map(assertUser)` passes the element index in that position, which a bare truthiness test would call.\n * @evidence contracts/common.md#clear-and-simple-design One function with a boolean guard and one factory branch.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts A non-callable argument falls back to the default error and is not retried or wrapped; the comment explains that a create-time factory overridden by the argument cannot be recovered here.\n * @evidence contracts/common.md#meaningful-documentation The doc states the two outcomes and the factory rule; the inline comment records the pointwise hand-off failure.\n */\nexport const _assertGuard = (\n  exceptionable: boolean,\n  props: TypeGuardError.IProps,\n  factory?: (props: TypeGuardError.IProps) => Error,\n): false => {\n  if (exceptionable === true) {\n    // `factory` arrives from the generated function's second parameter, which\n    // a pointwise hand-off fills with something that is not a factory at all:\n    // `rows.map(assertUser)` passes the element index. A truthiness test then\n    // called a number and reported `factory is not a function`, hiding the\n    // real assertion failure — and only for indices other than 0. Require a\n    // callable, and fall back to TypeGuardError for everything else.\n    //\n    // A create-time factory is the default of that same parameter, so a\n    // non-callable argument has already overridden it by the time this runs\n    // and cannot be recovered here. TypeGuardError still names the property\n    // that failed, which `factory is not a function` never did.\n    if (typeof factory === \"function\") throw factory(props);\n    throw new TypeGuardError(props);\n  }\n  return false;\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,gBACX,eACA,OACA,YACU;CACV,IAAI,kBAAkB,MAAM;EAY1B,IAAI,OAAO,YAAY,YAAY,MAAM,QAAQ,KAAK;EACtD,MAAM,IAAI,eAAe,KAAK;CAChC;CACA,OAAO;AACT"}