UNPKG

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