|
|
@ -1496,16 +1496,38 @@ export function validateFormulaAndExtractTreeWithType({ |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
res.dataType = FormulaDataTypes.STRING; |
|
|
|
res.dataType = FormulaDataTypes.STRING; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if ( |
|
|
|
} else if (parsedTree.type === JSEPNode.UNARY_EXP) { |
|
|
|
parsedTree.type === JSEPNode.BINARY_EXP || |
|
|
|
throw new FormulaError( |
|
|
|
parsedTree.type === JSEPNode.UNARY_EXP |
|
|
|
FormulaErrorType.NOT_SUPPORTED, |
|
|
|
) { |
|
|
|
{}, |
|
|
|
|
|
|
|
'Unary expression is not supported' |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else if (parsedTree.type === JSEPNode.BINARY_EXP) { |
|
|
|
res.left = validateAndExtract(parsedTree.left); |
|
|
|
res.left = validateAndExtract(parsedTree.left); |
|
|
|
res.right = validateAndExtract(parsedTree.right); |
|
|
|
res.right = validateAndExtract(parsedTree.right); |
|
|
|
|
|
|
|
|
|
|
|
if (['==', '<', '>', '<=', '>=', '!='].includes(parsedTree.operator)) { |
|
|
|
if (['==', '<', '>', '<=', '>=', '!='].includes(parsedTree.operator)) { |
|
|
|
res.dataType = FormulaDataTypes.COND_EXP; |
|
|
|
res.dataType = FormulaDataTypes.COND_EXP; |
|
|
|
} else res.dataType = FormulaDataTypes.NUMERIC; |
|
|
|
} |
|
|
|
|
|
|
|
else if (parsedTree.operator === '+') { |
|
|
|
|
|
|
|
res.dataType = FormulaDataTypes.NUMERIC; |
|
|
|
|
|
|
|
// if any side is string/date/other type, then the result will be concatenated string
|
|
|
|
|
|
|
|
// e.g. 1 + '2' = '12'
|
|
|
|
|
|
|
|
[res.left, res.right].some( |
|
|
|
|
|
|
|
(r) => |
|
|
|
|
|
|
|
![ |
|
|
|
|
|
|
|
FormulaDataTypes.NUMERIC, |
|
|
|
|
|
|
|
FormulaDataTypes.BOOLEAN, |
|
|
|
|
|
|
|
FormulaDataTypes.NULL, |
|
|
|
|
|
|
|
FormulaDataTypes.UNKNOWN, |
|
|
|
|
|
|
|
].includes(r.dataType) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
res.dataType = FormulaDataTypes.STRING; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
res.dataType = FormulaDataTypes.NUMERIC; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|