(defaultCase: DefaultCase)
| 564 | } |
| 565 | |
| 566 | default(defaultCase: DefaultCase): Match { |
| 567 | if (typeof defaultCase === "function") |
| 568 | this.case(intrinsic.unknown, defaultCase) |
| 569 | else if (!defaultCaseKeywords.includes(defaultCase)) |
| 570 | throwParseError(writeInvalidDefaultCaseMessage(defaultCase)) |
| 571 | |
| 572 | const shouldThrow = defaultCase === "never" || defaultCase === "assert" |
| 573 | |
| 574 | const schema: mutable<Union.Input> = { |
| 575 | branches: this.branches, |
| 576 | ordered: true |
| 577 | } |
| 578 | |
| 579 | if (shouldThrow) schema.meta = { onFail: throwOnDefault } |
| 580 | |
| 581 | let cases = this.$.node("union", schema) |
| 582 | |
| 583 | // a single-branch union reduces directly to that branch without schema.meta |
| 584 | if (shouldThrow && cases.meta.onFail !== throwOnDefault) |
| 585 | cases = cases.configureRefs({ onFail: throwOnDefault }, "self") |
| 586 | |
| 587 | if (!this.in) return this.$.fin(cases) as never |
| 588 | |
| 589 | let inputValidatedCases = this.in.pipe(cases) |
| 590 | |
| 591 | if (shouldThrow) { |
| 592 | inputValidatedCases = inputValidatedCases.configureRefs( |
| 593 | { |
| 594 | onFail: throwOnDefault |
| 595 | }, |
| 596 | "self" |
| 597 | ) |
| 598 | } |
| 599 | |
| 600 | return this.$.fin(inputValidatedCases) as never |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | export const chainedAtMessage = `A key matcher must be specified before the first case i.e. match.at('foo') or match.in<object>().at('bar')` |
no test coverage detected