All files / style9/src test-ast-shape.js

100% Statements 16/16
100% Branches 12/12
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  494x 420x 245x       410x 336x       583x 904x 494x   410x       518x     8x  
function getAst(ast, path) {
  if (Array.isArray(ast)) return ast[path];
  if (path === 'parent') return ast.parentPath;
  return ast.get(path);
}
 
function getValue(ast, path) {
  if (Array.isArray(ast)) return ast[path];
  return ast.node[path];
}
 
function testASTShape(ast, shape) {
  for (const key in shape) {
    if (typeof shape[key] === 'object') {
      if (!testASTShape(getAst(ast, key), shape[key])) return false;
    } else {
      if (shape[key] !== getValue(ast, key)) return false;
    }
  }
 
  return true;
}
 
module.exports = testASTShape;