Skip to content

Commit c2ced2a

Browse files
committed
Formatting
1 parent 61d92b6 commit c2ced2a

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

packages/jinja/src/runtime.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ export function setupGlobals(env: Environment): void {
590590
* @returns The value at the attribute path, or UndefinedValue if not found
591591
*/
592592
function getAttributeValue(item: AnyRuntimeValue, attributePath: string): AnyRuntimeValue {
593-
const parts = attributePath.split('.');
593+
const parts = attributePath.split(".");
594594
let value: AnyRuntimeValue = item;
595-
595+
596596
for (const part of parts) {
597597
if (value instanceof ObjectValue) {
598598
value = value.value.get(part) ?? new UndefinedValue();
@@ -607,7 +607,7 @@ function getAttributeValue(item: AnyRuntimeValue, attributePath: string): AnyRun
607607
return new UndefinedValue();
608608
}
609609
}
610-
610+
611611
return value;
612612
}
613613

@@ -641,7 +641,8 @@ function compareRuntimeValues(a: AnyRuntimeValue, b: AnyRuntimeValue, caseSensit
641641
}
642642

643643
// Check if value is numeric-like (IntegerValue, FloatValue, or BooleanValue)
644-
const isNumericLike = (v: AnyRuntimeValue): boolean => v instanceof IntegerValue || v instanceof FloatValue || v instanceof BooleanValue;
644+
const isNumericLike = (v: AnyRuntimeValue): boolean =>
645+
v instanceof IntegerValue || v instanceof FloatValue || v instanceof BooleanValue;
645646

646647
const getNumericValue = (v: AnyRuntimeValue): number => {
647648
if (v instanceof BooleanValue) {
@@ -870,9 +871,7 @@ export class Interpreter {
870871
return new ArrayValue(operand.value.slice().reverse());
871872
case "sort": {
872873
// Default case-insensitive sort using the shared comparison helper
873-
return new ArrayValue(
874-
operand.value.slice().sort((a, b) => compareRuntimeValues(a, b, false))
875-
);
874+
return new ArrayValue(operand.value.slice().sort((a, b) => compareRuntimeValues(a, b, false)));
876875
}
877876
case "join":
878877
return new StringValue(operand.value.map((x) => x.value).join(""));
@@ -1067,7 +1066,9 @@ export class Interpreter {
10671066
}
10681067

10691068
const attribute = args.at(2) ?? kwargs.get("attribute") ?? new NullValue();
1070-
if (!(attribute instanceof StringValue || attribute instanceof IntegerValue || attribute instanceof NullValue)) {
1069+
if (
1070+
!(attribute instanceof StringValue || attribute instanceof IntegerValue || attribute instanceof NullValue)
1071+
) {
10711072
throw new Error("attribute must be a string, integer, or null");
10721073
}
10731074

@@ -1083,7 +1084,7 @@ export class Interpreter {
10831084

10841085
// Create a copy of the array to sort
10851086
const arrayCopy = operand.value.slice();
1086-
1087+
10871088
arrayCopy.sort((a, b) => {
10881089
const aVal = getSortValue(a);
10891090
const bVal = getSortValue(b);
@@ -1145,9 +1146,9 @@ export class Interpreter {
11451146
if (!(item instanceof ObjectValue)) {
11461147
throw new Error("items in map must be an object");
11471148
}
1148-
1149+
11491150
const value = getAttributeValue(item, attr.value);
1150-
return value instanceof UndefinedValue ? (defaultValue ?? new UndefinedValue()) : value;
1151+
return value instanceof UndefinedValue ? defaultValue ?? new UndefinedValue() : value;
11511152
});
11521153
return new ArrayValue(mapped);
11531154
} else {

packages/jinja/test/templates.test.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,57 +4595,57 @@ const TEST_CONTEXT = {
45954595
SORT_CASE_INSENSITIVE: {},
45964596
SORT_ATTRIBUTE_SIMPLE: {
45974597
users: [
4598-
{ name: 'Charlie', age: 30 },
4599-
{ name: 'Alice', age: 25 },
4600-
{ name: 'Bob', age: 35 }
4601-
]
4598+
{ name: "Charlie", age: 30 },
4599+
{ name: "Alice", age: 25 },
4600+
{ name: "Bob", age: 35 },
4601+
],
46024602
},
46034603
SORT_ATTRIBUTE_REVERSE: {
46044604
users: [
4605-
{ name: 'Charlie', age: 30 },
4606-
{ name: 'Alice', age: 25 },
4607-
{ name: 'Bob', age: 35 }
4608-
]
4605+
{ name: "Charlie", age: 30 },
4606+
{ name: "Alice", age: 25 },
4607+
{ name: "Bob", age: 35 },
4608+
],
46094609
},
46104610
SORT_ATTRIBUTE_DOT_NOTATION: {
46114611
items: [
4612-
{ name: 'item1', details: { priority: 3 } },
4613-
{ name: 'item2', details: { priority: 1 } },
4614-
{ name: 'item3', details: { priority: 2 } }
4615-
]
4612+
{ name: "item1", details: { priority: 3 } },
4613+
{ name: "item2", details: { priority: 1 } },
4614+
{ name: "item3", details: { priority: 2 } },
4615+
],
46164616
},
46174617
SORT_CHAINED: {
46184618
users: [
4619-
{ name: 'Charlie', age: 30 },
4620-
{ name: 'Alice', age: 30 },
4621-
{ name: 'Bob', age: 35 },
4622-
{ name: 'David', age: 25 }
4623-
]
4619+
{ name: "Charlie", age: 30 },
4620+
{ name: "Alice", age: 30 },
4621+
{ name: "Bob", age: 35 },
4622+
{ name: "David", age: 25 },
4623+
],
46244624
},
46254625
SORT_STABLE: {
46264626
items: [
4627-
{ name: 'apple', category: 'fruit' },
4628-
{ name: 'carrot', category: 'vegetable' },
4629-
{ name: 'banana', category: 'fruit' },
4630-
{ name: 'broccoli', category: 'vegetable' }
4631-
]
4627+
{ name: "apple", category: "fruit" },
4628+
{ name: "carrot", category: "vegetable" },
4629+
{ name: "banana", category: "fruit" },
4630+
{ name: "broccoli", category: "vegetable" },
4631+
],
46324632
},
46334633
// Sort with positional arguments
46344634
SORT_POSITIONAL_REVERSE: {},
46354635
SORT_POSITIONAL_REVERSE_CASE: {},
46364636
SORT_POSITIONAL_ALL: {
46374637
users: [
4638-
{ name: 'Charlie', age: 30 },
4639-
{ name: 'Alice', age: 25 },
4640-
{ name: 'Bob', age: 35 }
4641-
]
4638+
{ name: "Charlie", age: 30 },
4639+
{ name: "Alice", age: 25 },
4640+
{ name: "Bob", age: 35 },
4641+
],
46424642
},
46434643
SORT_POSITIONAL_MIXED: {
46444644
users: [
4645-
{ name: 'Charlie', age: 30 },
4646-
{ name: 'Alice', age: 25 },
4647-
{ name: 'Bob', age: 35 }
4648-
]
4645+
{ name: "Charlie", age: 30 },
4646+
{ name: "Alice", age: 25 },
4647+
{ name: "Bob", age: 35 },
4648+
],
46494649
},
46504650
// Edge cases for sort
46514651
SORT_NULL_VALUES: {},

0 commit comments

Comments
 (0)