1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.JSXAttribute = JSXAttribute;
|
7 | exports.JSXIdentifier = JSXIdentifier;
|
8 | exports.JSXNamespacedName = JSXNamespacedName;
|
9 | exports.JSXMemberExpression = JSXMemberExpression;
|
10 | exports.JSXSpreadAttribute = JSXSpreadAttribute;
|
11 | exports.JSXExpressionContainer = JSXExpressionContainer;
|
12 | exports.JSXSpreadChild = JSXSpreadChild;
|
13 | exports.JSXText = JSXText;
|
14 | exports.JSXElement = JSXElement;
|
15 | exports.JSXOpeningElement = JSXOpeningElement;
|
16 | exports.JSXClosingElement = JSXClosingElement;
|
17 | exports.JSXEmptyExpression = JSXEmptyExpression;
|
18 | exports.JSXFragment = JSXFragment;
|
19 | exports.JSXOpeningFragment = JSXOpeningFragment;
|
20 | exports.JSXClosingFragment = JSXClosingFragment;
|
21 |
|
22 | var t = require("@babel/types");
|
23 |
|
24 | function JSXAttribute(node) {
|
25 | this.print(node.name, node);
|
26 |
|
27 | if (node.value) {
|
28 | this.token("=");
|
29 | this.print(node.value, node);
|
30 | }
|
31 | }
|
32 |
|
33 | function JSXIdentifier(node) {
|
34 | this.word(node.name);
|
35 | }
|
36 |
|
37 | function JSXNamespacedName(node) {
|
38 | this.print(node.namespace, node);
|
39 | this.token(":");
|
40 | this.print(node.name, node);
|
41 | }
|
42 |
|
43 | function JSXMemberExpression(node) {
|
44 | this.print(node.object, node);
|
45 | this.token(".");
|
46 | this.print(node.property, node);
|
47 | }
|
48 |
|
49 | function JSXSpreadAttribute(node) {
|
50 | this.token("{");
|
51 | this.token("...");
|
52 | this.print(node.argument, node);
|
53 | this.token("}");
|
54 | }
|
55 |
|
56 | function JSXExpressionContainer(node) {
|
57 | this.token("{");
|
58 | this.print(node.expression, node);
|
59 | this.token("}");
|
60 | }
|
61 |
|
62 | function JSXSpreadChild(node) {
|
63 | this.token("{");
|
64 | this.token("...");
|
65 | this.print(node.expression, node);
|
66 | this.token("}");
|
67 | }
|
68 |
|
69 | function JSXText(node) {
|
70 | const raw = this.getPossibleRaw(node);
|
71 |
|
72 | if (raw != null) {
|
73 | this.token(raw);
|
74 | } else {
|
75 | this.token(node.value);
|
76 | }
|
77 | }
|
78 |
|
79 | function JSXElement(node) {
|
80 | const open = node.openingElement;
|
81 | this.print(open, node);
|
82 | if (open.selfClosing) return;
|
83 | this.indent();
|
84 |
|
85 | for (const child of node.children) {
|
86 | this.print(child, node);
|
87 | }
|
88 |
|
89 | this.dedent();
|
90 | this.print(node.closingElement, node);
|
91 | }
|
92 |
|
93 | function spaceSeparator() {
|
94 | this.space();
|
95 | }
|
96 |
|
97 | function JSXOpeningElement(node) {
|
98 | this.token("<");
|
99 | this.print(node.name, node);
|
100 | this.print(node.typeParameters, node);
|
101 |
|
102 | if (node.attributes.length > 0) {
|
103 | this.space();
|
104 | this.printJoin(node.attributes, node, {
|
105 | separator: spaceSeparator
|
106 | });
|
107 | }
|
108 |
|
109 | if (node.selfClosing) {
|
110 | this.space();
|
111 | this.token("/>");
|
112 | } else {
|
113 | this.token(">");
|
114 | }
|
115 | }
|
116 |
|
117 | function JSXClosingElement(node) {
|
118 | this.token("</");
|
119 | this.print(node.name, node);
|
120 | this.token(">");
|
121 | }
|
122 |
|
123 | function JSXEmptyExpression(node) {
|
124 | this.printInnerComments(node);
|
125 | }
|
126 |
|
127 | function JSXFragment(node) {
|
128 | this.print(node.openingFragment, node);
|
129 | this.indent();
|
130 |
|
131 | for (const child of node.children) {
|
132 | this.print(child, node);
|
133 | }
|
134 |
|
135 | this.dedent();
|
136 | this.print(node.closingFragment, node);
|
137 | }
|
138 |
|
139 | function JSXOpeningFragment() {
|
140 | this.token("<");
|
141 | this.token(">");
|
142 | }
|
143 |
|
144 | function JSXClosingFragment() {
|
145 | this.token("</");
|
146 | this.token(">");
|
147 | } |
\ | No newline at end of file |