All files / src/nodes ModifierInvocation.js

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

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 3655x 55x   55x 925x     110x         815x     35x           5x     810x     55x 925x           55x  
const printSeparatedList = require('./print-separated-list');
const printComments = require('./print-comments');
 
const modifierArguments = (node, path, print, options) => {
  if (node.arguments) {
    // We always print parentheses at this stage because the parser already
    // stripped them in FunctionDefinitions that are not a constructor.
    return node.arguments.length > 0
      ? ['(', printSeparatedList(path.map(print, 'arguments')), ')']
      : '()';
  }
 
  if (
    node.comments &&
    node.comments.some(
      (comment) => !comment.leading && !comment.trailing && !comment.printed
    )
  ) {
    // We print parentheses here because the comment is supposed to be a block
    // comment inside empty parentheses.
    //    modifier(/* comment */)
    return ['(', printComments(node, path, options), ')'];
  }
 
  return '';
};
 
const ModifierInvocation = {
  print: ({ node, path, print, options }) => [
    node.name,
    modifierArguments(node, path, print, options)
  ]
};
 
module.exports = ModifierInvocation;