UNPKG

2.43 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 helpers;
21 constructor(nameManager: NameManager, tokens: TokenProcessor, enableLegacyTypeScriptModuleInterop: boolean, options: Options);
22 getPrefixCode(): string;
23 preprocessTokens(): void;
24 /**
25 * In TypeScript, import statements that only import types should be removed. This does not count
26 * bare imports.
27 */
28 pruneTypeOnlyImports(): void;
29 private generateImportReplacements;
30 private getFreeIdentifierForPath;
31 private preprocessImportAtIndex;
32 private preprocessExportAtIndex;
33 private preprocessVarExportAtIndex;
34 /**
35 * Walk this export statement just in case it's an export...from statement.
36 * If it is, combine it into the import info for that path. Otherwise, just
37 * bail out; it'll be handled later.
38 */
39 private preprocessNamedExportAtIndex;
40 private preprocessExportStarAtIndex;
41 private getNamedImports;
42 /**
43 * Get a mutable import info object for this path, creating one if it doesn't
44 * exist yet.
45 */
46 private getImportInfo;
47 private addExportBinding;
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 /**
55 * Return a string like `exports.foo = exports.bar`.
56 */
57 resolveExportBinding(assignedName: string): string | null;
58 /**
59 * Return all imported/exported names where we might be interested in whether usages of those
60 * names are shadowed.
61 */
62 getGlobalNames(): Set<string>;
63}