You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
5.4 KiB

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