1 | import type CJSImportProcessor from "../CJSImportProcessor";
|
2 | import type NameManager from "../NameManager";
|
3 | import type TokenProcessor from "../TokenProcessor";
|
4 | import type ReactHotLoaderTransformer from "./ReactHotLoaderTransformer";
|
5 | import type RootTransformer from "./RootTransformer";
|
6 | import Transformer from "./Transformer";
|
7 | /**
|
8 | * Class for editing import statements when we are transforming to commonjs.
|
9 | */
|
10 | export default class CJSImportTransformer extends Transformer {
|
11 | readonly rootTransformer: RootTransformer;
|
12 | readonly tokens: TokenProcessor;
|
13 | readonly importProcessor: CJSImportProcessor;
|
14 | readonly nameManager: NameManager;
|
15 | readonly reactHotLoaderTransformer: ReactHotLoaderTransformer | null;
|
16 | readonly enableLegacyBabel5ModuleInterop: boolean;
|
17 | readonly isTypeScriptTransformEnabled: boolean;
|
18 | private hadExport;
|
19 | private hadNamedExport;
|
20 | private hadDefaultExport;
|
21 | private declarationInfo;
|
22 | constructor(rootTransformer: RootTransformer, tokens: TokenProcessor, importProcessor: CJSImportProcessor, nameManager: NameManager, reactHotLoaderTransformer: ReactHotLoaderTransformer | null, enableLegacyBabel5ModuleInterop: boolean, isTypeScriptTransformEnabled: boolean);
|
23 | getPrefixCode(): string;
|
24 | getSuffixCode(): string;
|
25 | process(): boolean;
|
26 | private processImportEquals;
|
27 | /**
|
28 | * Transform this:
|
29 | * import foo, {bar} from 'baz';
|
30 | * into
|
31 | * var _baz = require('baz'); var _baz2 = _interopRequireDefault(_baz);
|
32 | *
|
33 | * The import code was already generated in the import preprocessing step, so
|
34 | * we just need to look it up.
|
35 | */
|
36 | private processImport;
|
37 | /**
|
38 | * Erase this import, and return true if it was either of the form "import type" or contained only
|
39 | * "type" named imports. Such imports should not even do a side-effect import.
|
40 | *
|
41 | * The position should end at the import string.
|
42 | */
|
43 | private removeImportAndDetectIfType;
|
44 | private removeRemainingImport;
|
45 | private processIdentifier;
|
46 | processObjectShorthand(): boolean;
|
47 | processExport(): boolean;
|
48 | private processAssignment;
|
49 | /**
|
50 | * Process something like `a += 3`, where `a` might be an exported value.
|
51 | */
|
52 | private processComplexAssignment;
|
53 | /**
|
54 | * Process something like `++a`, where `a` might be an exported value.
|
55 | */
|
56 | private processPreIncDec;
|
57 | /**
|
58 | * Process something like `a++`, where `a` might be an exported value.
|
59 | * This starts at the `a`, not at the `++`.
|
60 | */
|
61 | private processPostIncDec;
|
62 | private processExportDefault;
|
63 | /**
|
64 | * Transform a declaration like `export var`, `export let`, or `export const`.
|
65 | */
|
66 | private processExportVar;
|
67 | /**
|
68 | * Determine if the export is of the form:
|
69 | * export var/let/const [varName] = [expr];
|
70 | * In other words, determine if function name inference might apply.
|
71 | */
|
72 | private isSimpleExportVar;
|
73 | /**
|
74 | * Transform an `export var` declaration initializing a single variable.
|
75 | *
|
76 | * For example, this:
|
77 | * export const f = () => {};
|
78 | * becomes this:
|
79 | * const f = () => {}; exports.f = f;
|
80 | *
|
81 | * The variable is unused (e.g. exports.f has the true value of the export).
|
82 | * We need to produce an assignment of this form so that the function will
|
83 | * have an inferred name of "f", which wouldn't happen in the more general
|
84 | * case below.
|
85 | */
|
86 | private processSimpleExportVar;
|
87 | /**
|
88 | * Transform normal declaration exports, including handling destructuring.
|
89 | * For example, this:
|
90 | * export const {x: [a = 2, b], c} = d;
|
91 | * becomes this:
|
92 | * ({x: [exports.a = 2, exports.b], c: exports.c} = d;)
|
93 | */
|
94 | private processComplexExportVar;
|
95 | /**
|
96 | * Transform this:
|
97 | * export function foo() {}
|
98 | * into this:
|
99 | * function foo() {} exports.foo = foo;
|
100 | */
|
101 | private processExportFunction;
|
102 | /**
|
103 | * Skip past a function with a name and return that name.
|
104 | */
|
105 | private processNamedFunction;
|
106 | /**
|
107 | * Transform this:
|
108 | * export class A {}
|
109 | * into this:
|
110 | * class A {} exports.A = A;
|
111 | */
|
112 | private processExportClass;
|
113 | /**
|
114 | * Transform this:
|
115 | * export {a, b as c};
|
116 | * into this:
|
117 | * exports.a = a; exports.c = b;
|
118 | *
|
119 | * OR
|
120 | *
|
121 | * Transform this:
|
122 | * export {a, b as c} from './foo';
|
123 | * into the pre-generated Object.defineProperty code from the ImportProcessor.
|
124 | *
|
125 | * For the first case, if the TypeScript transform is enabled, we need to skip
|
126 | * exports that are only defined as types.
|
127 | */
|
128 | private processExportBindings;
|
129 | private processExportStar;
|
130 | private shouldElideExportedIdentifier;
|
131 | }
|