/
ExportNamedDeclaration.ts
43 lines (37 loc) · 1.5 KB
/
ExportNamedDeclaration.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
import MagicString from 'magic-string';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import { HasEffectsContext } from '../ExecutionContext';
import ClassDeclaration from './ClassDeclaration';
import ExportSpecifier from './ExportSpecifier';
import FunctionDeclaration from './FunctionDeclaration';
import Literal from './Literal';
import * as NodeType from './NodeType';
import VariableDeclaration from './VariableDeclaration';
import { Node, NodeBase } from './shared/Node';
export default class ExportNamedDeclaration extends NodeBase {
declaration!: FunctionDeclaration | ClassDeclaration | VariableDeclaration | null;
needsBoundaries!: true;
source!: Literal<string> | null;
specifiers!: ExportSpecifier[];
declare type: NodeType.tExportNamedDeclaration;
bind(): void {
// Do not bind specifiers
if (this.declaration !== null) this.declaration.bind();
}
hasEffects(context: HasEffectsContext): boolean {
return this.declaration !== null && this.declaration.hasEffects(context);
}
initialise(): void {
this.context.addExport(this);
}
render(code: MagicString, options: RenderOptions, nodeRenderOptions?: NodeRenderOptions): void {
const { start, end } = nodeRenderOptions as { end: number; start: number };
if (this.declaration === null) {
code.remove(start, end);
} else {
code.remove(this.start, this.declaration.start);
(this.declaration as Node).render(code, options, { end, start });
}
}
}
ExportNamedDeclaration.prototype.needsBoundaries = true;