UNPKG

1.81 kBTypeScriptView Raw
1import type { Options } from "../index";
2import type NameManager from "../NameManager";
3import type TokenProcessor from "../TokenProcessor";
4import type ReactHotLoaderTransformer from "./ReactHotLoaderTransformer";
5import Transformer from "./Transformer";
6/**
7 * Class for editing import statements when we are keeping the code as ESM. We still need to remove
8 * type-only imports in TypeScript and Flow.
9 */
10export default class ESMImportTransformer extends Transformer {
11 readonly tokens: TokenProcessor;
12 readonly nameManager: NameManager;
13 readonly reactHotLoaderTransformer: ReactHotLoaderTransformer | null;
14 readonly isTypeScriptTransformEnabled: boolean;
15 private nonTypeIdentifiers;
16 private declarationInfo;
17 constructor(tokens: TokenProcessor, nameManager: NameManager, reactHotLoaderTransformer: ReactHotLoaderTransformer | null, isTypeScriptTransformEnabled: boolean, options: Options);
18 process(): boolean;
19 private processImportEquals;
20 private processImport;
21 /**
22 * Remove type bindings from this import, leaving the rest of the import intact.
23 *
24 * Return true if this import was ONLY types, and thus is eligible for removal. This will bail out
25 * of the replacement operation, so we can return early here.
26 */
27 private removeImportTypeBindings;
28 private isTypeName;
29 private processExportDefault;
30 /**
31 * In TypeScript, we need to remove named exports that were never declared or only declared as a
32 * type.
33 */
34 private processNamedExports;
35 /**
36 * ESM elides all imports with the rule that we only elide if we see that it's
37 * a type and never see it as a value. This is in contract to CJS, which
38 * elides imports that are completely unknown.
39 */
40 private shouldElideExportedName;
41}