diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.ts index ffa7964488..7103bac4d1 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.ts @@ -19,10 +19,7 @@ export const jsepCurlyHook = { context.index += 1; env.node = { type: jsep.IDENTIFIER, - // column name with space would break it down to jsep.IDENTIFIER + jsep.LITERAL - // either take node.name for jsep.IDENTIFIER - // or take node.value for jsep.LITERAL - name: nodes.map((node) => node.name || node.value).join(' '), + name: nodes.map((node) => parseIdentifierName(node)).join(''), }; return env.node; } else { @@ -33,6 +30,23 @@ export const jsepCurlyHook = { }, } as jsep.IPlugin; +function parseIdentifierName(node) { + if (node.type === 'Identifier') { + // e.g. col + return node.name; + } else if (node.type === 'BinaryExpression') { + // e.g. col-1 would be considered as col (left), - (operator), 1 (right) + return ( + parseIdentifierName(node.left) + + node.operator + + parseIdentifierName(node.right) + ); + } else if (node.type === 'Literal') { + // e.g col (identifier) + 123 (literal) + return node.value; + } +} + export async function substituteColumnAliasWithIdInFormula( formula, columns: ColumnType[]