All files / src/nodes VariableDeclaration.js

100% Statements 23/23
100% Branches 22/22
100% Functions 8/8
100% Lines 17/17

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 49 50 51 52 53 54 55 56 57        55x   55x   7448x   55x 7448x       7448x   55x 7448x       7448x   55x 7448x 20x 15x               7448x   55x   7513x                               55x  
const {
  doc: {
    builders: { group, indent, line }
  }
} = require('prettier');
 
const printSeparatedList = require('./print-separated-list');
 
const indexed = (node) => (node.isIndexed ? ' indexed' : '');
 
const visibility = (node) =>
  node.visibility && node.visibility !== 'default'
    ? [line, node.visibility]
    : '';
 
const constantKeyword = (node) => (node.isDeclaredConst ? ' constant' : '');
 
const storageLocation = (node) =>
  node.storageLocation && node.visibility !== 'default'
    ? [line, node.storageLocation]
    : '';
 
const immutable = (node) => (node.isImmutable ? ' immutable' : '');
 
const override = (node, path, print) => {
  if (!node.override) return '';
  if (node.override.length === 0) return [line, 'override'];
  return [
    line,
    'override(',
    printSeparatedList(path.map(print, 'override')),
    ')'
  ];
};
 
const name = (node) => (node.name ? [' ', node.name] : '');
 
const VariableDeclaration = {
  print: ({ node, path, print }) =>
    node.typeName
      ? group([
          path.call(print, 'typeName'),
          indent([
            indexed(node),
            visibility(node),
            constantKeyword(node),
            storageLocation(node),
            immutable(node),
            override(node, path, print),
            name(node)
          ])
        ])
      : node.name
};
 
module.exports = VariableDeclaration;