fix: sort filter unexpectedly modifies original array, #475

This commit is contained in:
Harttle
2022-02-20 13:03:40 +08:00
parent ab5e245fba
commit dbc0497386
4 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
}