File size: 1,868 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
76
77
Object.defineProperty(exports, "__esModule", {
  value: true,
});

var _formatReactElementNode = require("./formatReactElementNode");

var _formatReactElementNode2 = _interopRequireDefault(_formatReactElementNode);

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

var REACT_FRAGMENT_TAG_NAME_SHORT_SYNTAX = "";
var REACT_FRAGMENT_TAG_NAME_EXPLICIT_SYNTAX = "React.Fragment";

var toReactElementTreeNode = function toReactElementTreeNode(
  displayName,
  key,
  childrens
) {
  var props = {};
  if (key) {
    props = { key: key };
  }

  return {
    type: "ReactElement",
    displayName: displayName,
    props: props,
    defaultProps: {},
    childrens: childrens,
  };
};

var isKeyedFragment = function isKeyedFragment(_ref) {
  var key = _ref.key;
  return Boolean(key);
};
var hasNoChildren = function hasNoChildren(_ref2) {
  var childrens = _ref2.childrens;
  return childrens.length === 0;
};

exports.default = function(node, inline, lvl, options) {
  var type = node.type,
    key = node.key,
    childrens = node.childrens;

  if (type !== "ReactFragment") {
    throw new Error(
      'The "formatReactFragmentNode" function could only format node of type "ReactFragment". Given: ' +
        type
    );
  }

  var useFragmentShortSyntax = options.useFragmentShortSyntax;

  var displayName = void 0;
  if (useFragmentShortSyntax) {
    if (hasNoChildren(node) || isKeyedFragment(node)) {
      displayName = REACT_FRAGMENT_TAG_NAME_EXPLICIT_SYNTAX;
    } else {
      displayName = REACT_FRAGMENT_TAG_NAME_SHORT_SYNTAX;
    }
  } else {
    displayName = REACT_FRAGMENT_TAG_NAME_EXPLICIT_SYNTAX;
  }

  return (0, _formatReactElementNode2.default)(
    toReactElementTreeNode(displayName, key, childrens),
    inline,
    lvl,
    options
  );
};
//# sourceMappingURL=formatReactFragmentNode.js.map