All files / src/comments ignore.js

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

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 26 27 28 29 30 31 32 33 34  265x   265x   155x 155x 850x       310x     30x 40x 40x   30x     510x 205x 55x 55x   150x           55x  
function ignoreComments(path) {
  const node = path.getValue();
  // We ignore anything that is not an object
  if (node === null || typeof node !== 'object') return;
 
  const keys = Object.keys(node);
  keys.forEach((key) => {
    switch (key) {
      // We ignore `loc` and `range` since these are added by the parser
      case 'loc':
      case 'range':
        break;
      // The key `comments` will contain every comment for this node
      case 'comments':
        path.each((commentPath) => {
          const comment = commentPath.getValue();
          comment.printed = true;
        }, 'comments');
        break;
      default:
        // If the value for that key is an Array or an Object we go deeper.
        if (typeof node[key] === 'object') {
          if (Array.isArray(node[key])) {
            path.each(ignoreComments, key);
            return;
          }
          path.call(ignoreComments, key);
        }
    }
  });
}
 
module.exports = ignoreComments;