All files / src printer.js

100% Statements 22/22
100% Branches 10/10
100% Functions 2/2
100% Lines 21/21

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 35 36 37 38 39 40 41 42 43 4455x 55x 55x 55x 55x   55x     65537x 54x 1x       53x       65537x   65536x 65536x 50x     65486x 1x     65485x 10x   10x           65475x     55x  
const prettier = require('prettier');
const semver = require('semver');
const nodes = require('./nodes');
const { hasNodeIgnoreComment } = require('./prettier-comments/common/util');
const ignoreComments = require('./comments/ignore');
 
let checked = false;
 
function prettierVersionCheck() {
  if (checked) return;
  if (!semver.satisfies(prettier.version, '>=2.3.0')) {
    throw new Error(
      'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
    );
  }
  checked = true;
}
 
function genericPrint(path, options, print) {
  prettierVersionCheck();
 
  const node = path.getValue();
  if (node === null) {
    return '';
  }
 
  if (!(node.type in nodes)) {
    throw new Error(`Unknown type: ${JSON.stringify(node.type)}`);
  }
 
  if (hasNodeIgnoreComment(node)) {
    ignoreComments(path);
 
    return options.originalText.slice(
      options.locStart(node),
      options.locEnd(node) + 1
    );
  }
 
  return nodes[node.type].print({ node, options, path, print });
}
 
module.exports = genericPrint;