modules.js 6.3 KB

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