UNPKG

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