fix: where-filter null handling (#457)

This commit is contained in:
Martin Schuster
2022-01-28 22:43:38 +08:00
committed by GitHub
parent 2717dae127
commit 9da41c8a37
2 changed files with 16 additions and 1 deletions
+4 -1
View File
@@ -3,6 +3,7 @@ import { toArray } from '../../util/collection'
import { isTruthy } from '../../render/boolean'
import { FilterImpl } from '../../template/filter/filter-impl'
import { Scope } from '../../context/scope'
import { isComparable } from '../../drop/comparable'
export const join = (v: any[], arg: string) => v.join(arg === undefined ? ' ' : arg)
export const last = (v: any) => isArray(v) ? arrayLast(v) : ''
@@ -40,7 +41,9 @@ export function slice<T> (v: T[], begin: number, length = 1): T[] {
export function where<T extends object> (this: FilterImpl, arr: T[], property: string, expected?: any): T[] {
return toArray(arr).filter(obj => {
const value = this.context.getFromScope(obj, String(property).split('.'))
return expected === undefined ? isTruthy(value, this.context) : value === expected
if (expected === undefined) return isTruthy(value, this.context)
if (isComparable(expected)) return expected.equals(value)
return value === expected
})
}