| 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 | var _expressions = require("./expressions.js");
|
|---|
| 22 | const {
|
|---|
| 23 | isClassDeclaration,
|
|---|
| 24 | isExportDefaultSpecifier,
|
|---|
| 25 | isExportNamespaceSpecifier,
|
|---|
| 26 | isImportDefaultSpecifier,
|
|---|
| 27 | isImportNamespaceSpecifier,
|
|---|
| 28 | isStatement
|
|---|
| 29 | } = _t;
|
|---|
| 30 | function ImportSpecifier(node) {
|
|---|
| 31 | if (node.importKind === "type" || node.importKind === "typeof") {
|
|---|
| 32 | this.word(node.importKind);
|
|---|
| 33 | this.space();
|
|---|
| 34 | }
|
|---|
| 35 | this.print(node.imported);
|
|---|
| 36 | if (node.local && node.local.name !== node.imported.name) {
|
|---|
| 37 | this.space();
|
|---|
| 38 | this.word("as");
|
|---|
| 39 | this.space();
|
|---|
| 40 | this.print(node.local);
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
| 43 | function ImportDefaultSpecifier(node) {
|
|---|
| 44 | this.print(node.local);
|
|---|
| 45 | }
|
|---|
| 46 | function ExportDefaultSpecifier(node) {
|
|---|
| 47 | this.print(node.exported);
|
|---|
| 48 | }
|
|---|
| 49 | function ExportSpecifier(node) {
|
|---|
| 50 | if (node.exportKind === "type") {
|
|---|
| 51 | this.word("type");
|
|---|
| 52 | this.space();
|
|---|
| 53 | }
|
|---|
| 54 | this.print(node.local);
|
|---|
| 55 | if (node.exported && node.local.name !== node.exported.name) {
|
|---|
| 56 | this.space();
|
|---|
| 57 | this.word("as");
|
|---|
| 58 | this.space();
|
|---|
| 59 | this.print(node.exported);
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 | function ExportNamespaceSpecifier(node) {
|
|---|
| 63 | this.tokenChar(42);
|
|---|
| 64 | this.space();
|
|---|
| 65 | this.word("as");
|
|---|
| 66 | this.space();
|
|---|
| 67 | this.print(node.exported);
|
|---|
| 68 | }
|
|---|
| 69 | let warningShown = false;
|
|---|
| 70 | function _printAttributes(node, hasPreviousBrace) {
|
|---|
| 71 | var _node$extra;
|
|---|
| 72 | const {
|
|---|
| 73 | attributes
|
|---|
| 74 | } = node;
|
|---|
| 75 | var {
|
|---|
| 76 | assertions
|
|---|
| 77 | } = node;
|
|---|
| 78 | const {
|
|---|
| 79 | importAttributesKeyword
|
|---|
| 80 | } = this.format;
|
|---|
| 81 | if (attributes && !importAttributesKeyword && node.extra && (node.extra.deprecatedAssertSyntax || node.extra.deprecatedWithLegacySyntax) && !warningShown) {
|
|---|
| 82 | warningShown = true;
|
|---|
| 83 | console.warn(`\
|
|---|
| 84 | You are using import attributes, without specifying the desired output syntax.
|
|---|
| 85 | Please specify the "importAttributesKeyword" generator option, whose value can be one of:
|
|---|
| 86 | - "with" : \`import { a } from "b" with { type: "json" };\`
|
|---|
| 87 | - "assert" : \`import { a } from "b" assert { type: "json" };\`
|
|---|
| 88 | - "with-legacy" : \`import { a } from "b" with type: "json";\`
|
|---|
| 89 | `);
|
|---|
| 90 | }
|
|---|
| 91 | const useAssertKeyword = importAttributesKeyword === "assert" || !importAttributesKeyword && assertions;
|
|---|
| 92 | this.word(useAssertKeyword ? "assert" : "with");
|
|---|
| 93 | this.space();
|
|---|
| 94 | if (!useAssertKeyword && (importAttributesKeyword === "with-legacy" || !importAttributesKeyword && (_node$extra = node.extra) != null && _node$extra.deprecatedWithLegacySyntax)) {
|
|---|
| 95 | this.printList(attributes || assertions);
|
|---|
| 96 | return;
|
|---|
| 97 | }
|
|---|
| 98 | const occurrenceCount = hasPreviousBrace ? 1 : 0;
|
|---|
| 99 | this.token("{", undefined, occurrenceCount);
|
|---|
| 100 | this.space();
|
|---|
| 101 | this.printList(attributes || assertions, this.shouldPrintTrailingComma("}"));
|
|---|
| 102 | this.space();
|
|---|
| 103 | this.token("}", undefined, occurrenceCount);
|
|---|
| 104 | }
|
|---|
| 105 | function ExportAllDeclaration(node) {
|
|---|
| 106 | var _node$attributes, _node$assertions;
|
|---|
| 107 | this.word("export");
|
|---|
| 108 | this.space();
|
|---|
| 109 | if (node.exportKind === "type") {
|
|---|
| 110 | this.word("type");
|
|---|
| 111 | this.space();
|
|---|
| 112 | }
|
|---|
| 113 | this.tokenChar(42);
|
|---|
| 114 | this.space();
|
|---|
| 115 | this.word("from");
|
|---|
| 116 | this.space();
|
|---|
| 117 | if ((_node$attributes = node.attributes) != null && _node$attributes.length || (_node$assertions = node.assertions) != null && _node$assertions.length) {
|
|---|
| 118 | this.print(node.source, true);
|
|---|
| 119 | this.space();
|
|---|
| 120 | _printAttributes.call(this, node, false);
|
|---|
| 121 | } else {
|
|---|
| 122 | this.print(node.source);
|
|---|
| 123 | }
|
|---|
| 124 | this.semicolon();
|
|---|
| 125 | }
|
|---|
| 126 | function maybePrintDecoratorsBeforeExport(printer, node) {
|
|---|
| 127 | if (isClassDeclaration(node.declaration) && _expressions._shouldPrintDecoratorsBeforeExport.call(printer, node)) {
|
|---|
| 128 | printer.printJoin(node.declaration.decorators);
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 | function ExportNamedDeclaration(node) {
|
|---|
| 132 | maybePrintDecoratorsBeforeExport(this, node);
|
|---|
| 133 | this.word("export");
|
|---|
| 134 | this.space();
|
|---|
| 135 | if (node.declaration) {
|
|---|
| 136 | const declar = node.declaration;
|
|---|
| 137 | this.print(declar);
|
|---|
| 138 | if (!isStatement(declar)) this.semicolon();
|
|---|
| 139 | } else {
|
|---|
| 140 | if (node.exportKind === "type") {
|
|---|
| 141 | this.word("type");
|
|---|
| 142 | this.space();
|
|---|
| 143 | }
|
|---|
| 144 | const specifiers = node.specifiers.slice(0);
|
|---|
| 145 | let hasSpecial = false;
|
|---|
| 146 | for (;;) {
|
|---|
| 147 | const first = specifiers[0];
|
|---|
| 148 | if (isExportDefaultSpecifier(first) || isExportNamespaceSpecifier(first)) {
|
|---|
| 149 | hasSpecial = true;
|
|---|
| 150 | this.print(specifiers.shift());
|
|---|
| 151 | if (specifiers.length) {
|
|---|
| 152 | this.tokenChar(44);
|
|---|
| 153 | this.space();
|
|---|
| 154 | }
|
|---|
| 155 | } else {
|
|---|
| 156 | break;
|
|---|
| 157 | }
|
|---|
| 158 | }
|
|---|
| 159 | let hasBrace = false;
|
|---|
| 160 | if (specifiers.length || !specifiers.length && !hasSpecial) {
|
|---|
| 161 | hasBrace = true;
|
|---|
| 162 | this.tokenChar(123);
|
|---|
| 163 | if (specifiers.length) {
|
|---|
| 164 | this.space();
|
|---|
| 165 | this.printList(specifiers, this.shouldPrintTrailingComma("}"));
|
|---|
| 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 | _printAttributes.call(this, 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, this.shouldPrintTrailingComma("}"));
|
|---|
| 236 | this.space();
|
|---|
| 237 | this.tokenChar(125);
|
|---|
| 238 | } else if (isTypeKind && !hasSpecifiers) {
|
|---|
| 239 | hasBrace = true;
|
|---|
| 240 | this.tokenChar(123);
|
|---|
| 241 | this.tokenChar(125);
|
|---|
| 242 | }
|
|---|
| 243 | if (hasSpecifiers || isTypeKind) {
|
|---|
| 244 | this.space();
|
|---|
| 245 | this.word("from");
|
|---|
| 246 | this.space();
|
|---|
| 247 | }
|
|---|
| 248 | if ((_node$attributes3 = node.attributes) != null && _node$attributes3.length || (_node$assertions3 = node.assertions) != null && _node$assertions3.length) {
|
|---|
| 249 | this.print(node.source, true);
|
|---|
| 250 | this.space();
|
|---|
| 251 | _printAttributes.call(this, node, hasBrace);
|
|---|
| 252 | } else {
|
|---|
| 253 | this.print(node.source);
|
|---|
| 254 | }
|
|---|
| 255 | this.semicolon();
|
|---|
| 256 | }
|
|---|
| 257 | function ImportAttribute(node) {
|
|---|
| 258 | this.print(node.key);
|
|---|
| 259 | this.tokenChar(58);
|
|---|
| 260 | this.space();
|
|---|
| 261 | this.print(node.value);
|
|---|
| 262 | }
|
|---|
| 263 | function ImportNamespaceSpecifier(node) {
|
|---|
| 264 | this.tokenChar(42);
|
|---|
| 265 | this.space();
|
|---|
| 266 | this.word("as");
|
|---|
| 267 | this.space();
|
|---|
| 268 | this.print(node.local);
|
|---|
| 269 | }
|
|---|
| 270 | function ImportExpression(node) {
|
|---|
| 271 | this.word("import");
|
|---|
| 272 | if (node.phase) {
|
|---|
| 273 | this.tokenChar(46);
|
|---|
| 274 | this.word(node.phase);
|
|---|
| 275 | }
|
|---|
| 276 | this.tokenChar(40);
|
|---|
| 277 | const shouldPrintTrailingComma = this.shouldPrintTrailingComma(")");
|
|---|
| 278 | this.print(node.source);
|
|---|
| 279 | if (node.options != null) {
|
|---|
| 280 | this.tokenChar(44);
|
|---|
| 281 | this.space();
|
|---|
| 282 | this.print(node.options);
|
|---|
| 283 | }
|
|---|
| 284 | if (shouldPrintTrailingComma) {
|
|---|
| 285 | this.tokenChar(44);
|
|---|
| 286 | }
|
|---|
| 287 | this.rightParens(node);
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | //# sourceMappingURL=modules.js.map
|
|---|