source: frontend/node_modules/sucrase/dist/esm/util/shouldElideDefaultExport.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import {TokenType as tt} from "../parser/tokenizer/types";
2
3
4
5/**
6 * Common method sharing code between CJS and ESM cases, since they're the same here.
7 */
8export default function shouldElideDefaultExport(
9 isTypeScriptTransformEnabled,
10 keepUnusedImports,
11 tokens,
12 declarationInfo,
13) {
14 if (!isTypeScriptTransformEnabled || keepUnusedImports) {
15 return false;
16 }
17 const exportToken = tokens.currentToken();
18 if (exportToken.rhsEndIndex == null) {
19 throw new Error("Expected non-null rhsEndIndex on export token.");
20 }
21 // The export must be of the form `export default a` or `export default a;`.
22 const numTokens = exportToken.rhsEndIndex - tokens.currentIndex();
23 if (
24 numTokens !== 3 &&
25 !(numTokens === 4 && tokens.matches1AtIndex(exportToken.rhsEndIndex - 1, tt.semi))
26 ) {
27 return false;
28 }
29 const identifierToken = tokens.tokenAtRelativeIndex(2);
30 if (identifierToken.type !== tt.name) {
31 return false;
32 }
33 const exportedName = tokens.identifierNameForToken(identifierToken);
34 return (
35 declarationInfo.typeDeclarations.has(exportedName) &&
36 !declarationInfo.valueDeclarations.has(exportedName)
37 );
38}
Note: See TracBrowser for help on using the repository browser.