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