Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function(expr, scope, preamble) {
var params = {}, ast, gen;
// parse the expression to an abstract syntax tree (ast)
try {
expr = isString(expr) ? expr : (stringValue(expr) + '');
ast = parse(expr);
} catch (err) {
error('Expression parse error: ' + expr);
}
// analyze ast function calls for dependencies
ast.visit(function visitor(node) {
if (node.type !== CallExpression) return;
var name = node.callee.name,
visit = codegenParams.visitors[name];
if (visit) visit(name, node.arguments, scope, params);
});
// perform code generation
gen = codeGenerator(ast);
// collect signal dependencies
export function toPredicateFunction(filters: ShelfFilter[]) {
const expr = '(' +
filters.map(f => {
return fieldFilterExpression(f, false); // Do not use inrange as it is not included in the main Vega Expression
}).join(')&&(') +
')';
const ast = vegaExpression.parse(expr);
const codegen = vegaExpression.codegen({
whitelist: ['datum'],
globalvar: 'global'
});
const value = codegen(ast);
return new Function('datum', `return ${value.code};`) as (d: object) => boolean;
}
export function getDependentFields(expression: string) {
const ast = parse(expression);
const dependents = new Set();
ast.visit((node: any) => {
if (node.type === 'MemberExpression' && startsWithDatum(node)) {
dependents.add(
getName(node)
.slice(1)
.join('.')
);
}
});
return dependents;
}
export function getDependentFields(expression) {
const ast = parse(expression);
const dependents = new Set();
ast.visit((node) => {
if (node.type === 'MemberExpression' && startsWithDatum(node)) {
dependents.add(getName(node)
.slice(1)
.join('.'));
}
});
return dependents;
}
//# sourceMappingURL=expressions.js.map