UNPKG

2.68 kBTypeScriptView Raw
1import type { HelperManager } from "./HelperManager";
2import type { Options } from "./index";
3import type NameManager from "./NameManager";
4import type TokenProcessor from "./TokenProcessor";
5/**
6 * Class responsible for preprocessing and bookkeeping import and export declarations within the
7 * file.
8 *
9 * TypeScript uses a simpler mechanism that does not use functions like interopRequireDefault and
10 * interopRequireWildcard, so we also allow that mode for compatibility.
11 */
12export default class CJSImportProcessor {
13 readonly nameManager: NameManager;
14 readonly tokens: TokenProcessor;
15 readonly enableLegacyTypeScriptModuleInterop: boolean;
16 readonly options: Options;
17 readonly isTypeScriptTransformEnabled: boolean;
18 readonly helperManager: HelperManager;
19 private nonTypeIdentifiers;
20 private importInfoByPath;
21 private importsToReplace;
22 private identifierReplacements;
23 private exportBindingsByLocalName;
24 constructor(nameManager: NameManager, tokens: TokenProcessor, enableLegacyTypeScriptModuleInterop: boolean, options: Options, isTypeScriptTransformEnabled: boolean, helperManager: HelperManager);
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}