mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
fix: sort filter unexpectedly modifies original array, #475
This commit is contained in:
@@ -12,7 +12,7 @@ export const reverse = (v: any[]) => [...v].reverse()
|
||||
|
||||
export function sort<T> (this: FilterImpl, arr: T[], property?: string) {
|
||||
const getValue = (obj: Scope) => property ? this.context.getFromScope(obj, property.split('.')) : obj
|
||||
return toArray(arr).sort((lhs, rhs) => {
|
||||
return [...toArray(arr)].sort((lhs, rhs) => {
|
||||
lhs = getValue(lhs)
|
||||
rhs = getValue(rhs)
|
||||
return lhs < rhs ? -1 : (lhs > rhs ? 1 : 0)
|
||||
|
||||
@@ -12,7 +12,7 @@ export class Output extends TemplateImpl<OutputToken> implements Template {
|
||||
super(token)
|
||||
this.value = new Value(token.content, liquid)
|
||||
}
|
||||
public * render (ctx: Context, emitter: Emitter): Generator<unknown, void, unknown> {
|
||||
public * render (ctx: Context, emitter: Emitter): IterableIterator<unknown> {
|
||||
const val = yield this.value.value(ctx, false)
|
||||
emitter.write(val)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user