UNPKG

2.3 kBTypeScriptView Raw
1import NameManager from "./NameManager";
2import TokenProcessor from "./TokenProcessor";
3/**
4 * Class responsible for preprocessing and bookkeeping import and export declarations within the
5 * file.
6 *
7 * TypeScript uses a simpler mechanism that does not use functions like interopRequireDefault and
8 * interopRequireWildcard, so we also allow that mode for compatibility.
9 */
10export default class CJSImportProcessor {
11 readonly nameManager: NameManager;
12 readonly tokens: TokenProcessor;
13 readonly enableLegacyTypeScriptModuleInterop: boolean;
14 private importInfoByPath;
15 private importsToReplace;
16 private identifierReplacements;
17 private exportBindingsByLocalName;
18 private interopRequireWildcardName;
19 private interopRequireDefaultName;
20 constructor(nameManager: NameManager, tokens: TokenProcessor, enableLegacyTypeScriptModuleInterop: boolean);
21 getPrefixCode(): string;
22 preprocessTokens(): void;
23 /**
24 * In TypeScript, import statements that only import types should be removed. This does not count
25 * bare imports.
26 */
27 pruneTypeOnlyImports(): void;
28 private generateImportReplacements;
29 private getFreeIdentifierForPath;
30 private preprocessImportAtIndex;
31 private preprocessExportAtIndex;
32 private preprocessVarExportAtIndex;
33 /**
34 * Walk this export statement just in case it's an export...from statement.
35 * If it is, combine it into the import info for that path. Otherwise, just
36 * bail out; it'll be handled later.
37 */
38 private preprocessNamedExportAtIndex;
39 private preprocessExportStarAtIndex;
40 private getNamedImports;
41 /**
42 * Get a mutable import info object for this path, creating one if it doesn't
43 * exist yet.
44 */
45 private getImportInfo;
46 /**
47 * Return the code to use for the import for this path, or the empty string if
48 * the code has already been "claimed" by a previous import.
49 */
50 claimImportCode(importPath: string): string;
51 getIdentifierReplacement(identifierName: string): string | null;
52 resolveExportBinding(assignedName: string): string | null;
53 /**
54 * Return all imported/exported names where we might be interested in whether usages of those
55 * names are shadowed.
56 */
57 getGlobalNames(): Set<string>;
58}