Skip to content

Commit c916d93

Browse files
author
Guilherme de Oliveira
committed
fix: handle null emits
1 parent 0fff989 commit c916d93

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/interface.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ export default defineComponent({
7070
};
7171
7272
function compute() {
73-
return props.template.replace(/{{.*?}}/g, (match) => {
73+
const computedValue = props.template.replace(/{{.*?}}/g, (match) => {
7474
const expression = match.slice(2, -2).trim();
7575
return parseExpression(expression, values.value);
7676
});
77+
78+
if (!computedValue) {
79+
return null;
80+
}
81+
82+
return computedValue;
7783
}
7884
},
7985
});

src/operations.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@ export function parseExpression(exp: string, values: Record<string, any>): any {
88
const opMatch = parseOp(exp);
99
if (opMatch) {
1010
const { op, a, b } = opMatch;
11+
12+
if (op === 'ASUM') {
13+
// aggregated sum
14+
return (
15+
(values[a] as unknown[])?.reduce(
16+
(acc, item) => acc + parseExpression(b!, item as typeof values),
17+
0
18+
) ?? 0
19+
);
20+
}
21+
1122
const valueA = parseExpression(a, values);
23+
if (!valueA) {
24+
return '';
25+
}
1226

1327
// unary operators
1428
if (b === null) {
@@ -85,14 +99,6 @@ export function parseExpression(exp: string, values: Record<string, any>): any {
8599
}
86100
return 0;
87101
}
88-
} else if (op === 'ASUM') {
89-
// aggregated sum
90-
return (
91-
(values[a] as unknown[])?.reduce(
92-
(acc, item) => acc + parseExpression(b, item as typeof values),
93-
0
94-
) ?? 0
95-
);
96102
} else {
97103
// binary operators
98104
const valueB = parseExpression(b, values);

0 commit comments

Comments
 (0)