( members: ReadonlyArray<AST.AST>, isDecoding: boolean )
| 1569 | * @internal |
| 1570 | */ |
| 1571 | export const getSearchTree = ( |
| 1572 | members: ReadonlyArray<AST.AST>, |
| 1573 | isDecoding: boolean |
| 1574 | ): { |
| 1575 | keys: { |
| 1576 | readonly [key: PropertyKey]: { |
| 1577 | buckets: { [literal: string]: ReadonlyArray<AST.AST> } |
| 1578 | literals: ReadonlyArray<AST.Literal> // this is for error messages |
| 1579 | candidates: ReadonlyArray<AST.AST> |
| 1580 | } |
| 1581 | } |
| 1582 | otherwise: ReadonlyArray<AST.AST> |
| 1583 | candidates: ReadonlyArray<AST.AST> |
| 1584 | } => { |
| 1585 | const keys: { |
| 1586 | [key: PropertyKey]: { |
| 1587 | buckets: { [literal: string]: Array<AST.AST> } |
| 1588 | literals: Array<AST.Literal> |
| 1589 | candidates: Array<AST.AST> |
| 1590 | } |
| 1591 | } = {} |
| 1592 | const otherwise: Array<AST.AST> = [] |
| 1593 | const candidates: Array<AST.AST> = [] |
| 1594 | for (let i = 0; i < members.length; i++) { |
| 1595 | const member = members[i] |
| 1596 | const tags = getLiterals(member, isDecoding) |
| 1597 | if (tags.length > 0) { |
| 1598 | candidates.push(member) |
| 1599 | for (let j = 0; j < tags.length; j++) { |
| 1600 | const [key, literal] = tags[j] |
| 1601 | const hash = String(literal.literal) |
| 1602 | keys[key] = keys[key] || { buckets: {}, literals: [], candidates: [] } |
| 1603 | const buckets = keys[key].buckets |
| 1604 | if (Object.prototype.hasOwnProperty.call(buckets, hash)) { |
| 1605 | if (j < tags.length - 1) { |
| 1606 | continue |
| 1607 | } |
| 1608 | buckets[hash].push(member) |
| 1609 | keys[key].literals.push(literal) |
| 1610 | keys[key].candidates.push(member) |
| 1611 | } else { |
| 1612 | buckets[hash] = [member] |
| 1613 | keys[key].literals.push(literal) |
| 1614 | keys[key].candidates.push(member) |
| 1615 | break |
| 1616 | } |
| 1617 | } |
| 1618 | } else { |
| 1619 | otherwise.push(member) |
| 1620 | } |
| 1621 | } |
| 1622 | return { keys, otherwise, candidates } |
| 1623 | } |
| 1624 | |
| 1625 | const dropRightRefinement = (ast: AST.AST): AST.AST => AST.isRefinement(ast) ? dropRightRefinement(ast.from) : ast |
| 1626 |
no test coverage detected