modules.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ImportSpecifier = ImportSpecifier;
  6. exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
  7. exports.ExportDefaultSpecifier = ExportDefaultSpecifier;
  8. exports.ExportSpecifier = ExportSpecifier;
  9. exports.ExportNamespaceSpecifier = ExportNamespaceSpecifier;
  10. exports.ExportAllDeclaration = ExportAllDeclaration;
  11. exports.ExportNamedDeclaration = ExportNamedDeclaration;
  12. exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
  13. exports.ImportDeclaration = ImportDeclaration;
  14. exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
  15. function t() {
  16. const data = _interopRequireWildcard(require("@babel/types"));
  17. t = function () {
  18. return data;
  19. };
  20. return data;
  21. }
  22. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  23. function ImportSpecifier(node) {
  24. if (node.importKind === "type" || node.importKind === "typeof") {
  25. this.word(node.importKind);
  26. this.space();
  27. }
  28. this.print(node.imported, node);
  29. if (node.local && node.local.name !== node.imported.name) {
  30. this.space();
  31. this.word("as");
  32. this.space();
  33. this.print(node.local, node);
  34. }
  35. }
  36. function ImportDefaultSpecifier(node) {
  37. this.print(node.local, node);
  38. }
  39. function ExportDefaultSpecifier(node) {
  40. this.print(node.exported, node);
  41. }
  42. function ExportSpecifier(node) {
  43. this.print(node.local, node);
  44. if (node.exported && node.local.name !== node.exported.name) {
  45. this.space();
  46. this.word("as");
  47. this.space();
  48. this.print(node.exported, node);
  49. }
  50. }
  51. function ExportNamespaceSpecifier(node) {
  52. this.token("*");
  53. this.space();
  54. this.word("as");
  55. this.space();
  56. this.print(node.exported, node);
  57. }
  58. function ExportAllDeclaration(node) {
  59. this.word("export");
  60. this.space();
  61. if (node.exportKind === "type") {
  62. this.word("type");
  63. this.space();
  64. }
  65. this.token("*");
  66. this.space();
  67. this.word("from");
  68. this.space();
  69. this.print(node.source, node);
  70. this.semicolon();
  71. }
  72. function ExportNamedDeclaration(node) {
  73. if (this.format.decoratorsBeforeExport && t().isClassDeclaration(node.declaration)) {
  74. this.printJoin(node.declaration.decorators, node);
  75. }
  76. this.word("export");
  77. this.space();
  78. ExportDeclaration.apply(this, arguments);
  79. }
  80. function ExportDefaultDeclaration(node) {
  81. if (this.format.decoratorsBeforeExport && t().isClassDeclaration(node.declaration)) {
  82. this.printJoin(node.declaration.decorators, node);
  83. }
  84. this.word("export");
  85. this.space();
  86. this.word("default");
  87. this.space();
  88. ExportDeclaration.apply(this, arguments);
  89. }
  90. function ExportDeclaration(node) {
  91. if (node.declaration) {
  92. const declar = node.declaration;
  93. this.print(declar, node);
  94. if (!t().isStatement(declar)) this.semicolon();
  95. } else {
  96. if (node.exportKind === "type") {
  97. this.word("type");
  98. this.space();
  99. }
  100. const specifiers = node.specifiers.slice(0);
  101. let hasSpecial = false;
  102. while (true) {
  103. const first = specifiers[0];
  104. if (t().isExportDefaultSpecifier(first) || t().isExportNamespaceSpecifier(first)) {
  105. hasSpecial = true;
  106. this.print(specifiers.shift(), node);
  107. if (specifiers.length) {
  108. this.token(",");
  109. this.space();
  110. }
  111. } else {
  112. break;
  113. }
  114. }
  115. if (specifiers.length || !specifiers.length && !hasSpecial) {
  116. this.token("{");
  117. if (specifiers.length) {
  118. this.space();
  119. this.printList(specifiers, node);
  120. this.space();
  121. }
  122. this.token("}");
  123. }
  124. if (node.source) {
  125. this.space();
  126. this.word("from");
  127. this.space();
  128. this.print(node.source, node);
  129. }
  130. this.semicolon();
  131. }
  132. }
  133. function ImportDeclaration(node) {
  134. this.word("import");
  135. this.space();
  136. if (node.importKind === "type" || node.importKind === "typeof") {
  137. this.word(node.importKind);
  138. this.space();
  139. }
  140. const specifiers = node.specifiers.slice(0);
  141. if (specifiers && specifiers.length) {
  142. while (true) {
  143. const first = specifiers[0];
  144. if (t().isImportDefaultSpecifier(first) || t().isImportNamespaceSpecifier(first)) {
  145. this.print(specifiers.shift(), node);
  146. if (specifiers.length) {
  147. this.token(",");
  148. this.space();
  149. }
  150. } else {
  151. break;
  152. }
  153. }
  154. if (specifiers.length) {
  155. this.token("{");
  156. this.space();
  157. this.printList(specifiers, node);
  158. this.space();
  159. this.token("}");
  160. }
  161. this.space();
  162. this.word("from");
  163. this.space();
  164. }
  165. this.print(node.source, node);
  166. this.semicolon();
  167. }
  168. function ImportNamespaceSpecifier(node) {
  169. this.token("*");
  170. this.space();
  171. this.word("as");
  172. this.space();
  173. this.print(node.local, node);
  174. }