( members: ReadonlyArray<AST.AST>, isDecoding: boolean )
| 1551 | * @internal |
| 1552 | */ |
| 1553 | export const getSearchTree = ( |
| 1554 | members: ReadonlyArray<AST.AST>, |
| 1555 | isDecoding: boolean |
| 1556 | ): { |
| 1557 | keys: { |
| 1558 | readonly [key: PropertyKey]: { |
| 1559 | buckets: { [literal: string]: ReadonlyArray<AST.AST> } |
| 1560 | literals: ReadonlyArray<AST.Literal> // this is for error messages |
| 1561 | candidates: ReadonlyArray<AST.AST> |
| 1562 | } |
| 1563 | } |
| 1564 | otherwise: ReadonlyArray<AST.AST> |
| 1565 | candidates: ReadonlyArray<AST.AST> |
| 1566 | } => { |
| 1567 | const keys: { |
| 1568 | [key: PropertyKey]: { |
| 1569 | buckets: { [literal: string]: Array<AST.AST> } |
| 1570 | literals: Array<AST.Literal> |
| 1571 | candidates: Array<AST.AST> |
| 1572 | } |
| 1573 | } = {} |
| 1574 | const otherwise: Array<AST.AST> = [] |
| 1575 | const candidates: Array<AST.AST> = [] |
| 1576 | for (let i = 0; i < members.length; i++) { |
| 1577 | const member = members[i] |
| 1578 | const tags = getLiterals(member, isDecoding) |
| 1579 | if (tags.length > 0) { |
| 1580 | candidates.push(member) |
| 1581 | for (let j = 0; j < tags.length; j++) { |
| 1582 | const [key, literal] = tags[j] |
| 1583 | const hash = String(literal.literal) |
| 1584 | keys[key] = keys[key] || { buckets: {}, literals: [], candidates: [] } |
| 1585 | const buckets = keys[key].buckets |
| 1586 | if (Object.prototype.hasOwnProperty.call(buckets, hash)) { |
| 1587 | if (j < tags.length - 1) { |
| 1588 | continue |
| 1589 | } |
| 1590 | buckets[hash].push(member) |
| 1591 | keys[key].literals.push(literal) |
| 1592 | keys[key].candidates.push(member) |
| 1593 | } else { |
| 1594 | buckets[hash] = [member] |
| 1595 | keys[key].literals.push(literal) |
| 1596 | keys[key].candidates.push(member) |
| 1597 | break |
| 1598 | } |
| 1599 | } |
| 1600 | } else { |
| 1601 | otherwise.push(member) |
| 1602 | } |
| 1603 | } |
| 1604 | return { keys, otherwise, candidates } |
| 1605 | } |
| 1606 | |
| 1607 | const dropRightRefinement = (ast: AST.AST): AST.AST => AST.isRefinement(ast) ? dropRightRefinement(ast.from) : ast |
| 1608 |
no test coverage detected
searching dependent graphs…