forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SyntheticNamedExportVariable.ts
55 lines (47 loc) · 1.66 KB
/
SyntheticNamedExportVariable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type Module from '../../Module';
import type { AstContext } from '../../Module';
import ExportDefaultVariable from './ExportDefaultVariable';
import Variable from './Variable';
export default class SyntheticNamedExportVariable extends Variable {
readonly context: AstContext;
readonly module: Module;
readonly syntheticNamespace: Variable;
private baseVariable: Variable | null = null;
constructor(context: AstContext, name: string, syntheticNamespace: Variable) {
super(name);
this.context = context;
this.module = context.module;
this.syntheticNamespace = syntheticNamespace;
}
getBaseVariable(): Variable {
if (this.baseVariable) return this.baseVariable;
let baseVariable = this.syntheticNamespace;
while (
baseVariable instanceof ExportDefaultVariable ||
baseVariable instanceof SyntheticNamedExportVariable
) {
if (baseVariable instanceof ExportDefaultVariable) {
const original = baseVariable.getOriginalVariable();
if (original === baseVariable) break;
baseVariable = original;
}
if (baseVariable instanceof SyntheticNamedExportVariable) {
baseVariable = baseVariable.syntheticNamespace;
}
}
return (this.baseVariable = baseVariable);
}
getBaseVariableName(): string {
return this.syntheticNamespace.getBaseVariableName();
}
getName(getPropertyAccess: (name: string) => string): string {
return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
}
include(): void {
this.included = true;
this.context.includeVariableInModule(this.syntheticNamespace);
}
setRenderNames(baseName: string | null, name: string | null): void {
super.setRenderNames(baseName, name);
}
}