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