Skip to content

Commit 7c8a9f1

Browse files
committed
Cleanup round 1
1 parent 183f240 commit 7c8a9f1

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

packages/jinja/src/runtime.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -747,13 +747,10 @@ export class Interpreter {
747747
case "length":
748748
return new IntegerValue(operand.value.length);
749749
case "reverse":
750-
// Create a copy to avoid mutating the original array
751750
return new ArrayValue(operand.value.slice().reverse());
752751
case "sort": {
753-
// Create a copy to avoid mutating the original array
754-
const arrayCopy = operand.value.slice();
755752
return new ArrayValue(
756-
arrayCopy.sort((a, b) => {
753+
operand.value.slice().sort((a, b) => {
757754
if (a.type !== b.type) {
758755
throw new Error(`Cannot compare different types: ${a.type} and ${b.type}`);
759756
}
@@ -936,14 +933,14 @@ export class Interpreter {
936933
if (operand instanceof ArrayValue) {
937934
switch (filterName) {
938935
case "sort": {
939-
// https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.sort
936+
// https://jinja.palletsprojects.com/en/stable/templates/#jinja-filters.sort
940937
// Parameters:
941938
// - reverse: Sort descending instead of ascending
942939
// - case_sensitive: When sorting strings, sort upper and lower case separately
943940
// - attribute: When sorting objects or dicts, an attribute or key to sort by
944941
// eslint-disable-next-line @typescript-eslint/no-unused-vars
945942
const [_args, kwargs] = this.evaluateArguments(filter.args, environment);
946-
943+
947944
const reverse = kwargs.get("reverse") ?? new BooleanValue(false);
948945
if (!(reverse instanceof BooleanValue)) {
949946
throw new Error("reverse must be a boolean");

0 commit comments

Comments
 (0)