Browse Source

fix(nocodb-sdk): revise parsing identifier name logic

pull/4776/head
Wing-Kam Wong 2 years ago
parent
commit
6c71afe28d
  1. 22
      packages/nocodb-sdk/src/lib/formulaHelpers.ts

22
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[]

Loading…
Cancel
Save