UNPKG

2.59 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 readonly isTypeScriptTransformEnabled: boolean;
17 private nonTypeIdentifiers;
18 private importInfoByPath;
19 private importsToReplace;
20 private identifierReplacements;
21 private exportBindingsByLocalName;
22 private helpers;
23 constructor(nameManager: NameManager, tokens: TokenProcessor, enableLegacyTypeScriptModuleInterop: boolean, options: Options, isTypeScriptTransformEnabled: boolean);
24 getPrefixCode(): string;
25 preprocessTokens(): void;
26 /**
27 * In TypeScript, import statements that only import types should be removed. This does not count
28 * bare imports.
29 */
30 pruneTypeOnlyImports(): void;
31 isTypeName(name: string): boolean;
32 private generateImportReplacements;
33 private getFreeIdentifierForPath;
34 private preprocessImportAtIndex;
35 private preprocessExportAtIndex;
36 private preprocessVarExportAtIndex;
37 /**
38 * Walk this export statement just in case it's an export...from statement.
39 * If it is, combine it into the import info for that path. Otherwise, just
40 * bail out; it'll be handled later.
41 */
42 private preprocessNamedExportAtIndex;
43 private preprocessExportStarAtIndex;
44 private getNamedImports;
45 /**
46 * Get a mutable import info object for this path, creating one if it doesn't
47 * exist yet.
48 */
49 private getImportInfo;
50 private addExportBinding;
51 /**
52 * Return the code to use for the import for this path, or the empty string if
53 * the code has already been "claimed" by a previous import.
54 */
55 claimImportCode(importPath: string): string;
56 getIdentifierReplacement(identifierName: string): string | null;
57 /**
58 * Return a string like `exports.foo = exports.bar`.
59 */
60 resolveExportBinding(assignedName: string): string | null;
61 /**
62 * Return all imported/exported names where we might be interested in whether usages of those
63 * names are shadowed.
64 */
65 getGlobalNames(): Set<string>;
66}