Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

uber / deck.gl / 14011

20 Sep 2019 - 23:54 coverage increased (+2.7%) to 82.999%
14011

Pull #3672

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
bump loaders.gl version
Pull Request #3672: Fix bugs in pre-bundled version

3393 of 4577 branches covered (74.13%)

Branch coverage included in aggregate %.

7157 of 8134 relevant lines covered (87.99%)

4305.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.68
/modules/json/src/helpers/parse-expression-string.js
1
import {get} from '../utils/get';
2

3
// expression-eval: Small jsep based expression parser that supports array and object indexing
4
import expressionEval from 'expression-eval';
5

6
const cachedExpressionMap = {
1×
7
  '-': object => object
12×
8
};
9

10
// Calculates an accessor function from a JSON string
11
// '-' : x => x
12
// 'a.b.c': x => x.a.b.c
13
export default function parseExpressionString(propValue, configuration, isAccessor) {
14
  // NOTE: Can be null which represents invalid function. Return null so that prop can be ommitted
15
  if (propValue in cachedExpressionMap) {
1×
16
    return cachedExpressionMap[propValue];
2×
17
  }
18

19
  let func;
20
  // Compile with expression-eval
21
  const ast = expressionEval.parse(propValue);
1×
22
  if (!ast.right && !ast.left && ast.type === 'Identifier') {
2×
23
    func = row => get(row, propValue);
1×
24
  } else {
25
    // NOTE: To avoid security risks, the arguments passed to the
26
    // compiled expresion must only give access to pure data (no globals etc)
27
    // We disable function call syntax?
28
    traverse(ast, node => {
92×
29
      if (node.type === 'CallExpression') {
34×
30
        throw new Error('Function calls not allowed in JSON expressions');
58×
31
      }
32
    });
33
    func = isAccessor
Branches [[4, 1]] missed. 58×
34
      ? row => expressionEval.eval(ast, row)
4×
35
      : // TBD - how do we pass args to general (non-accessor) functions?
36
        args => expressionEval.eval(ast, {args});
4×
37
  }
38

39
  // Cache the compiled function
40
  cachedExpressionMap[propValue] = func;
54×
41
  return func;
167×
42
}
43

44
// Helper function to search all nodes in AST returned by expressionEval
45
// eslint-disable-next-line complexity
46
function traverse(node, visitor) {
47
  if (Array.isArray(node)) {
7×
48
    node.forEach(element => traverse(element, visitor));
48×
UNCOV
49
  } else if (node && typeof node === 'object') {
!
50
    if (node.type) {
Branches [[8, 1]] missed. 51×
51
      visitor(node);
51×
52
    }
53
    for (const key in node) {
573×
54
      traverse(node[key], visitor);
6×
55
    }
56
  }
57
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC