* Checks if a simple comparison can be optimized
(expression: BasicExpression, collection: CollectionLike<T, TKey>)
| 577 | * Checks if a simple comparison can be optimized |
| 578 | */ |
| 579 | function canOptimizeSimpleComparison< |
| 580 | T extends object, |
| 581 | TKey extends string | number, |
| 582 | >(expression: BasicExpression, collection: CollectionLike<T, TKey>): boolean { |
| 583 | if (expression.type !== `func` || expression.args.length !== 2) { |
| 584 | return false |
| 585 | } |
| 586 | |
| 587 | const leftArg = expression.args[0]! |
| 588 | const rightArg = expression.args[1]! |
| 589 | |
| 590 | // Check both directions: field op value AND value op field |
| 591 | let fieldPath: Array<string> | null = null |
| 592 | |
| 593 | if (leftArg.type === `ref` && rightArg.type === `val`) { |
| 594 | fieldPath = (leftArg as any).path |
| 595 | } else if (leftArg.type === `val` && rightArg.type === `ref`) { |
| 596 | fieldPath = (rightArg as any).path |
| 597 | } |
| 598 | |
| 599 | if (fieldPath) { |
| 600 | const index = findIndexForField(collection, fieldPath) |
| 601 | return index !== undefined |
| 602 | } |
| 603 | |
| 604 | return false |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * Optimizes AND expressions |
no test coverage detected