Skip to content

Commit f39a51b

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

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-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

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export function parseExpression(exp: string, values: Record<string, any>): any {
2+
console.log('parsing values', exp, values);
23
if (values) {
34
exp = exp.trim();
45
if (exp in values) {
@@ -8,7 +9,21 @@ export function parseExpression(exp: string, values: Record<string, any>): any {
89
const opMatch = parseOp(exp);
910
if (opMatch) {
1011
const { op, a, b } = opMatch;
12+
13+
if (op === 'ASUM') {
14+
// aggregated sum
15+
return (
16+
(values[a] as unknown[])?.reduce(
17+
(acc, item) => acc + parseExpression(b!, item as typeof values),
18+
0
19+
) ?? 0
20+
);
21+
}
22+
1123
const valueA = parseExpression(a, values);
24+
if (!valueA) {
25+
return '';
26+
}
1227

1328
// unary operators
1429
if (b === null) {
@@ -85,14 +100,6 @@ export function parseExpression(exp: string, values: Record<string, any>): any {
85100
}
86101
return 0;
87102
}
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-
);
96103
} else {
97104
// binary operators
98105
const valueB = parseExpression(b, values);

0 commit comments

Comments
 (0)