1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.ExportAllDeclaration = ExportAllDeclaration;
|
7 | exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
|
8 | exports.ExportDefaultSpecifier = ExportDefaultSpecifier;
|
9 | exports.ExportNamedDeclaration = ExportNamedDeclaration;
|
10 | exports.ExportNamespaceSpecifier = ExportNamespaceSpecifier;
|
11 | exports.ExportSpecifier = ExportSpecifier;
|
12 | exports.ImportAttribute = ImportAttribute;
|
13 | exports.ImportDeclaration = ImportDeclaration;
|
14 | exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
|
15 | exports.ImportExpression = ImportExpression;
|
16 | exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
|
17 | exports.ImportSpecifier = ImportSpecifier;
|
18 | exports._printAttributes = _printAttributes;
|
19 | var _t = require("@babel/types");
|
20 | const {
|
21 | isClassDeclaration,
|
22 | isExportDefaultSpecifier,
|
23 | isExportNamespaceSpecifier,
|
24 | isImportDefaultSpecifier,
|
25 | isImportNamespaceSpecifier,
|
26 | isStatement
|
27 | } = _t;
|
28 | function ImportSpecifier(node) {
|
29 | if (node.importKind === "type" || node.importKind === "typeof") {
|
30 | this.word(node.importKind);
|
31 | this.space();
|
32 | }
|
33 | this.print(node.imported, node);
|
34 | if (node.local && node.local.name !== node.imported.name) {
|
35 | this.space();
|
36 | this.word("as");
|
37 | this.space();
|
38 | this.print(node.local, node);
|
39 | }
|
40 | }
|
41 | function ImportDefaultSpecifier(node) {
|
42 | this.print(node.local, node);
|
43 | }
|
44 | function ExportDefaultSpecifier(node) {
|
45 | this.print(node.exported, node);
|
46 | }
|
47 | function ExportSpecifier(node) {
|
48 | if (node.exportKind === "type") {
|
49 | this.word("type");
|
50 | this.space();
|
51 | }
|
52 | this.print(node.local, node);
|
53 | if (node.exported && node.local.name !== node.exported.name) {
|
54 | this.space();
|
55 | this.word("as");
|
56 | this.space();
|
57 | this.print(node.exported, node);
|
58 | }
|
59 | }
|
60 | function ExportNamespaceSpecifier(node) {
|
61 | this.tokenChar(42);
|
62 | this.space();
|
63 | this.word("as");
|
64 | this.space();
|
65 | this.print(node.exported, node);
|
66 | }
|
67 | let warningShown = false;
|
68 | function _printAttributes(node) {
|
69 | const {
|
70 | importAttributesKeyword
|
71 | } = this.format;
|
72 | const {
|
73 | attributes,
|
74 | assertions
|
75 | } = node;
|
76 | if (attributes && !importAttributesKeyword && !warningShown) {
|
77 | warningShown = true;
|
78 | console.warn(`\
|
79 | You are using import attributes, without specifying the desired output syntax.
|
80 | Please specify the "importAttributesKeyword" generator option, whose value can be one of:
|
81 | - "with" : \`import { a } from "b" with { type: "json" };\`
|
82 | - "assert" : \`import { a } from "b" assert { type: "json" };\`
|
83 | - "with-legacy" : \`import { a } from "b" with type: "json";\`
|
84 | `);
|
85 | }
|
86 | const useAssertKeyword = importAttributesKeyword === "assert" || !importAttributesKeyword && assertions;
|
87 | this.word(useAssertKeyword ? "assert" : "with");
|
88 | this.space();
|
89 | if (!useAssertKeyword && importAttributesKeyword !== "with") {
|
90 | this.printList(attributes || assertions, node);
|
91 | return;
|
92 | }
|
93 | this.tokenChar(123);
|
94 | this.space();
|
95 | this.printList(attributes || assertions, node);
|
96 | this.space();
|
97 | this.tokenChar(125);
|
98 | }
|
99 | function ExportAllDeclaration(node) {
|
100 | var _node$attributes, _node$assertions;
|
101 | this.word("export");
|
102 | this.space();
|
103 | if (node.exportKind === "type") {
|
104 | this.word("type");
|
105 | this.space();
|
106 | }
|
107 | this.tokenChar(42);
|
108 | this.space();
|
109 | this.word("from");
|
110 | this.space();
|
111 | if ((_node$attributes = node.attributes) != null && _node$attributes.length || (_node$assertions = node.assertions) != null && _node$assertions.length) {
|
112 | this.print(node.source, node, true);
|
113 | this.space();
|
114 | this._printAttributes(node);
|
115 | } else {
|
116 | this.print(node.source, node);
|
117 | }
|
118 | this.semicolon();
|
119 | }
|
120 | function maybePrintDecoratorsBeforeExport(printer, node) {
|
121 | if (isClassDeclaration(node.declaration) && printer._shouldPrintDecoratorsBeforeExport(node)) {
|
122 | printer.printJoin(node.declaration.decorators, node);
|
123 | }
|
124 | }
|
125 | function ExportNamedDeclaration(node) {
|
126 | maybePrintDecoratorsBeforeExport(this, node);
|
127 | this.word("export");
|
128 | this.space();
|
129 | if (node.declaration) {
|
130 | const declar = node.declaration;
|
131 | this.print(declar, node);
|
132 | if (!isStatement(declar)) this.semicolon();
|
133 | } else {
|
134 | if (node.exportKind === "type") {
|
135 | this.word("type");
|
136 | this.space();
|
137 | }
|
138 | const specifiers = node.specifiers.slice(0);
|
139 | let hasSpecial = false;
|
140 | for (;;) {
|
141 | const first = specifiers[0];
|
142 | if (isExportDefaultSpecifier(first) || isExportNamespaceSpecifier(first)) {
|
143 | hasSpecial = true;
|
144 | this.print(specifiers.shift(), node);
|
145 | if (specifiers.length) {
|
146 | this.tokenChar(44);
|
147 | this.space();
|
148 | }
|
149 | } else {
|
150 | break;
|
151 | }
|
152 | }
|
153 | if (specifiers.length || !specifiers.length && !hasSpecial) {
|
154 | this.tokenChar(123);
|
155 | if (specifiers.length) {
|
156 | this.space();
|
157 | this.printList(specifiers, node);
|
158 | this.space();
|
159 | }
|
160 | this.tokenChar(125);
|
161 | }
|
162 | if (node.source) {
|
163 | var _node$attributes2, _node$assertions2;
|
164 | this.space();
|
165 | this.word("from");
|
166 | this.space();
|
167 | if ((_node$attributes2 = node.attributes) != null && _node$attributes2.length || (_node$assertions2 = node.assertions) != null && _node$assertions2.length) {
|
168 | this.print(node.source, node, true);
|
169 | this.space();
|
170 | this._printAttributes(node);
|
171 | } else {
|
172 | this.print(node.source, node);
|
173 | }
|
174 | }
|
175 | this.semicolon();
|
176 | }
|
177 | }
|
178 | function ExportDefaultDeclaration(node) {
|
179 | maybePrintDecoratorsBeforeExport(this, node);
|
180 | this.word("export");
|
181 | this.noIndentInnerCommentsHere();
|
182 | this.space();
|
183 | this.word("default");
|
184 | this.space();
|
185 | const declar = node.declaration;
|
186 | this.print(declar, node);
|
187 | if (!isStatement(declar)) this.semicolon();
|
188 | }
|
189 | function ImportDeclaration(node) {
|
190 | var _node$attributes3, _node$assertions3;
|
191 | this.word("import");
|
192 | this.space();
|
193 | const isTypeKind = node.importKind === "type" || node.importKind === "typeof";
|
194 | if (isTypeKind) {
|
195 | this.noIndentInnerCommentsHere();
|
196 | this.word(node.importKind);
|
197 | this.space();
|
198 | } else if (node.module) {
|
199 | this.noIndentInnerCommentsHere();
|
200 | this.word("module");
|
201 | this.space();
|
202 | } else if (node.phase) {
|
203 | this.noIndentInnerCommentsHere();
|
204 | this.word(node.phase);
|
205 | this.space();
|
206 | }
|
207 | const specifiers = node.specifiers.slice(0);
|
208 | const hasSpecifiers = !!specifiers.length;
|
209 | while (hasSpecifiers) {
|
210 | const first = specifiers[0];
|
211 | if (isImportDefaultSpecifier(first) || isImportNamespaceSpecifier(first)) {
|
212 | this.print(specifiers.shift(), node);
|
213 | if (specifiers.length) {
|
214 | this.tokenChar(44);
|
215 | this.space();
|
216 | }
|
217 | } else {
|
218 | break;
|
219 | }
|
220 | }
|
221 | if (specifiers.length) {
|
222 | this.tokenChar(123);
|
223 | this.space();
|
224 | this.printList(specifiers, node);
|
225 | this.space();
|
226 | this.tokenChar(125);
|
227 | } else if (isTypeKind && !hasSpecifiers) {
|
228 | this.tokenChar(123);
|
229 | this.tokenChar(125);
|
230 | }
|
231 | if (hasSpecifiers || isTypeKind) {
|
232 | this.space();
|
233 | this.word("from");
|
234 | this.space();
|
235 | }
|
236 | if ((_node$attributes3 = node.attributes) != null && _node$attributes3.length || (_node$assertions3 = node.assertions) != null && _node$assertions3.length) {
|
237 | this.print(node.source, node, true);
|
238 | this.space();
|
239 | this._printAttributes(node);
|
240 | } else {
|
241 | this.print(node.source, node);
|
242 | }
|
243 | this.semicolon();
|
244 | }
|
245 | function ImportAttribute(node) {
|
246 | this.print(node.key);
|
247 | this.tokenChar(58);
|
248 | this.space();
|
249 | this.print(node.value);
|
250 | }
|
251 | function ImportNamespaceSpecifier(node) {
|
252 | this.tokenChar(42);
|
253 | this.space();
|
254 | this.word("as");
|
255 | this.space();
|
256 | this.print(node.local, node);
|
257 | }
|
258 | function ImportExpression(node) {
|
259 | this.word("import");
|
260 | if (node.phase) {
|
261 | this.tokenChar(46);
|
262 | this.word(node.phase);
|
263 | }
|
264 | this.tokenChar(40);
|
265 | this.print(node.source, node);
|
266 | if (node.options != null) {
|
267 | this.tokenChar(44);
|
268 | this.space();
|
269 | this.print(node.options, node);
|
270 | }
|
271 | this.tokenChar(41);
|
272 | }
|
273 |
|
274 |
|