Keine Beschreibung

shouldElideDefaultExport.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _types = require('../parser/tokenizer/types');
  2. /**
  3. * Common method sharing code between CJS and ESM cases, since they're the same here.
  4. */
  5. function shouldElideDefaultExport(
  6. isTypeScriptTransformEnabled,
  7. tokens,
  8. declarationInfo,
  9. ) {
  10. if (!isTypeScriptTransformEnabled) {
  11. return false;
  12. }
  13. const exportToken = tokens.currentToken();
  14. if (exportToken.rhsEndIndex == null) {
  15. throw new Error("Expected non-null rhsEndIndex on export token.");
  16. }
  17. // The export must be of the form `export default a` or `export default a;`.
  18. const numTokens = exportToken.rhsEndIndex - tokens.currentIndex();
  19. if (
  20. numTokens !== 3 &&
  21. !(numTokens === 4 && tokens.matches1AtIndex(exportToken.rhsEndIndex - 1, _types.TokenType.semi))
  22. ) {
  23. return false;
  24. }
  25. const identifierToken = tokens.tokenAtRelativeIndex(2);
  26. if (identifierToken.type !== _types.TokenType.name) {
  27. return false;
  28. }
  29. const exportedName = tokens.identifierNameForToken(identifierToken);
  30. return (
  31. declarationInfo.typeDeclarations.has(exportedName) &&
  32. !declarationInfo.valueDeclarations.has(exportedName)
  33. );
  34. } exports.default = shouldElideDefaultExport;