|
|
@ -19,10 +19,7 @@ export const jsepCurlyHook = { |
|
|
|
context.index += 1; |
|
|
|
context.index += 1; |
|
|
|
env.node = { |
|
|
|
env.node = { |
|
|
|
type: jsep.IDENTIFIER, |
|
|
|
type: jsep.IDENTIFIER, |
|
|
|
// column name with space would break it down to jsep.IDENTIFIER + jsep.LITERAL
|
|
|
|
name: nodes.map((node) => parseIdentifierName(node)).join(''), |
|
|
|
// either take node.name for jsep.IDENTIFIER
|
|
|
|
|
|
|
|
// or take node.value for jsep.LITERAL
|
|
|
|
|
|
|
|
name: nodes.map((node) => node.name || node.value).join(' '), |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
return env.node; |
|
|
|
return env.node; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -33,6 +30,23 @@ export const jsepCurlyHook = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
} as jsep.IPlugin; |
|
|
|
} 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( |
|
|
|
export async function substituteColumnAliasWithIdInFormula( |
|
|
|
formula, |
|
|
|
formula, |
|
|
|
columns: ColumnType[] |
|
|
|
columns: ColumnType[] |
|
|
|