( def: unknown, $: InternalScope )
| 1535 | } |
| 1536 | |
| 1537 | export const deferDefinition = ( |
| 1538 | def: unknown, |
| 1539 | $: InternalScope |
| 1540 | ): BaseRoot | undefined => { |
| 1541 | if (!canDefer($)) return |
| 1542 | if (deferred.has(def as object)) return def as BaseRoot |
| 1543 | if (typeof def === "string") { |
| 1544 | const facts = scanLeaf(def) |
| 1545 | // a string could be what another route has reached once nodes exist, and |
| 1546 | // it's few and cached, so it's parsed from then on |
| 1547 | return ( |
| 1548 | !facts || facts.defaults ? undefined |
| 1549 | : lastCreated ? ($.nodesByKey.get(facts.key) as never) |
| 1550 | : defer(facts, $, () => $.parseDef(def)) |
| 1551 | ) |
| 1552 | } |
| 1553 | if (def instanceof RegExp) { |
| 1554 | const facts = regexFacts(def) |
| 1555 | return facts && defer(facts, $, () => $.parseDef(def)) |
| 1556 | } |
| 1557 | if (typeof def !== "object" || !def || !isPlainObject(def)) return |
| 1558 | const facts: Facts = { |
| 1559 | key: "", |
| 1560 | domains: objectBits, |
| 1561 | pure: true, |
| 1562 | literal: true |
| 1563 | } |
| 1564 | let literal: Dict | undefined |
| 1565 | try { |
| 1566 | literal = walkLiteral(def as Dict, facts) |
| 1567 | } catch { |
| 1568 | return |
| 1569 | } |
| 1570 | if (!literal) return |
| 1571 | const copy = literal |
| 1572 | return defer(facts, $, () => $.parseDef(copy)) |
| 1573 | } |
no test coverage detected