How to use the expression-eval.parse function in expression-eval

To help you get started, we’ve selected a few expression-eval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uber / deck.gl / modules / json / src / helpers / parse-expression-string.js View on Github external
export default function parseExpressionString(propValue, configuration) {
  // NOTE: Can be null which represents invalid function. Return null so that prop can be omitted
  if (propValue in cachedExpressionMap) {
    return cachedExpressionMap[propValue];
  }

  let func;
  // Compile with expression-eval
  const ast = expressionEval.parse(propValue);
  if (!ast.right && !ast.left && ast.type === 'Identifier') {
    func = row => {
      return get(row, propValue);
    };
  } else {
    // NOTE: To avoid security risks, the arguments passed to the
    // compiled expression must only give access to pure data (no globals etc)
    // We disable function call syntax
    traverse(ast, node => {
      if (node.type === 'CallExpression') {
        throw new Error('Function calls not allowed in JSON expressions');
      }
    });
    // TODO Something like `expressionEval.eval(ast, {row});` would be useful for unpacking arrays
    func = row => {
      return expressionEval.eval(ast, row);

expression-eval

JavaScript expression parsing and evaluation.

MIT
Latest version published 1 year ago

Package Health Score

56 / 100
Full package analysis