All files / src/nodes ContractDefinition.js

100% Statements 12/12
100% Branches 8/8
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 36 37 38 39 40 41 42 43 44 45 46 47 48        55x   55x 55x 55x 55x   55x 804x                 55x 804x                   55x 804x                         55x  
const {
  doc: {
    builders: { group, line, hardline }
  }
} = require('prettier');
 
const printSeparatedItem = require('./print-separated-item');
const printSeparatedList = require('./print-separated-list');
const printPreservingEmptyLines = require('./print-preserving-empty-lines');
const printComments = require('./print-comments');
 
const inheritance = (node, path, print) =>
  node.baseContracts.length > 0
    ? [
        ' is',
        printSeparatedList(path.map(print, 'baseContracts'), {
          firstSeparator: line
        })
      ]
    : line;
 
const body = (node, path, options, print) =>
  node.subNodes.length > 0 || node.comments
    ? printSeparatedItem(
        [
          printPreservingEmptyLines(path, 'subNodes', options, print),
          printComments(node, path, options)
        ],
        { firstSeparator: hardline, grouped: false }
      )
    : '';
 
const ContractDefinition = {
  print: ({ node, options, path, print }) => [
    group([
      node.kind === 'abstract' ? 'abstract contract' : node.kind,
      ' ',
      node.name,
      inheritance(node, path, print),
      '{'
    ]),
    body(node, path, options, print),
    '}'
  ]
};
 
module.exports = ContractDefinition;