* Checks if an IN array expression can be optimized
(expression: BasicExpression, collection: CollectionLike<T, TKey>)
| 788 | * Checks if an IN array expression can be optimized |
| 789 | */ |
| 790 | function canOptimizeInArrayExpression< |
| 791 | T extends object, |
| 792 | TKey extends string | number, |
| 793 | >(expression: BasicExpression, collection: CollectionLike<T, TKey>): boolean { |
| 794 | if (expression.type !== `func` || expression.args.length !== 2) { |
| 795 | return false |
| 796 | } |
| 797 | |
| 798 | const fieldArg = expression.args[0]! |
| 799 | const arrayArg = expression.args[1]! |
| 800 | |
| 801 | if ( |
| 802 | fieldArg.type === `ref` && |
| 803 | arrayArg.type === `val` && |
| 804 | Array.isArray((arrayArg as any).value) |
| 805 | ) { |
| 806 | const fieldPath = (fieldArg as any).path |
| 807 | const index = findIndexForField(collection, fieldPath) |
| 808 | return index !== undefined |
| 809 | } |
| 810 | |
| 811 | return false |
| 812 | } |
no test coverage detected