forked from dsherret/ts-morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportAssignment.ts
77 lines (67 loc) · 2.68 KB
/
ExportAssignment.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { ts, SyntaxKind } from "../../../typescript";
import { Expression } from "../expression";
import { Statement } from "../statement";
import { ExportAssignmentStructure, ExportAssignmentSpecificStructure, StructureKind } from "../../../structures";
import { WriterFunction } from "../../../types";
import { callBaseGetStructure } from "../callBaseGetStructure";
import { callBaseSet } from "../callBaseSet";
export const ExportAssignmentBase = Statement;
export class ExportAssignment extends ExportAssignmentBase<ts.ExportAssignment> {
/**
* Gets if this is an export equals assignment.
*
* If this is false, then it's `export default`.
*/
isExportEquals() {
return this.compilerNode.isExportEquals || false;
}
/**
* Sets if this is an export equals assignment or export default.
* @param value - Whether it should be an export equals assignment.
*/
setIsExportEquals(value: boolean) {
if (this.isExportEquals() === value)
return this;
if (value)
this.getFirstChildByKindOrThrow(SyntaxKind.DefaultKeyword).replaceWithText("=");
else
this.getFirstChildByKindOrThrow(SyntaxKind.EqualsToken).replaceWithText("default");
return this;
}
/**
* Gets the export assignment expression.
*/
getExpression(): Expression {
return this._getNodeFromCompilerNode(this.compilerNode.expression);
}
/**
* Sets the expression of the export assignment.
* @param textOrWriterFunction - Text or writer function to set as the export assignment expression.
*/
setExpression(textOrWriterFunction: string | WriterFunction) {
this.getExpression().replaceWithText(textOrWriterFunction, this._getWriterWithQueuedChildIndentation());
return this;
}
/**
* Sets the node from a structure.
* @param structure - Structure to set the node with.
*/
set(structure: Partial<ExportAssignmentStructure>) {
callBaseSet(ExportAssignmentBase.prototype, this, structure);
if (structure.expression != null)
this.setExpression(structure.expression);
if (structure.isExportEquals != null)
this.setIsExportEquals(structure.isExportEquals);
return this;
}
/**
* Gets the structure equivalent to this node.
*/
getStructure(): ExportAssignmentStructure {
return callBaseGetStructure<ExportAssignmentSpecificStructure>(Statement.prototype, this, {
kind: StructureKind.ExportAssignment,
expression: this.getExpression().getText(),
isExportEquals: this.isExportEquals()
}) as any as ExportAssignmentStructure;
}
}