File size: 1,940 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Object.defineProperty(exports, "__esModule", {
  value: true,
});

var _spacer = require("./spacer");

var _spacer2 = _interopRequireDefault(_spacer);

var _formatPropValue = require("./formatPropValue");

var _formatPropValue2 = _interopRequireDefault(_formatPropValue);

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

exports.default = function(
  name,
  hasValue,
  value,
  hasDefaultValue,
  defaultValue,
  inline,
  lvl,
  options
) {
  if (!hasValue && !hasDefaultValue) {
    throw new Error(
      'The prop "' +
        name +
        '" has no value and no default: could not be formatted'
    );
  }

  var usedValue = hasValue ? value : defaultValue;

  var useBooleanShorthandSyntax = options.useBooleanShorthandSyntax,
    tabStop = options.tabStop;

  var formattedPropValue = (0, _formatPropValue2.default)(
    usedValue,
    inline,
    lvl,
    options
  );

  var attributeFormattedInline = " ";
  var attributeFormattedMultiline =
    "\n" + (0, _spacer2.default)(lvl + 1, tabStop);
  var isMultilineAttribute = formattedPropValue.includes("\n");

  if (
    useBooleanShorthandSyntax &&
    formattedPropValue === "{false}" &&
    !hasDefaultValue
  ) {
    // If a boolean is false and not different from it's default, we do not render the attribute
    attributeFormattedInline = "";
    attributeFormattedMultiline = "";
  } else if (useBooleanShorthandSyntax && formattedPropValue === "{true}") {
    attributeFormattedInline += "" + name;
    attributeFormattedMultiline += "" + name;
  } else {
    attributeFormattedInline += name + "=" + formattedPropValue;
    attributeFormattedMultiline += name + "=" + formattedPropValue;
  }

  return {
    attributeFormattedInline: attributeFormattedInline,
    attributeFormattedMultiline: attributeFormattedMultiline,
    isMultilineAttribute: isMultilineAttribute,
  };
};
//# sourceMappingURL=formatProp.js.map